diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index 7f126846a1..1df6b26441 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -2,6 +2,7 @@ ## Unreleased +- Fix watcher does not trigger reload on windows. - Add feed for blog posts. - **HOTFIX for 2.0.0-alpha.32** - Fix build compilation if exists only one code tab. - Add table of contents highlighting on scroll. diff --git a/package.json b/package.json index efa6cdaf88..43308efc90 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "jest": "^24.9.0", "lerna": "^3.18.1", "lint-staged": "^7.2.0", + "picomatch": "^2.1.0", "prettier": "^1.18.2", "react": "^16.8.4", "react-dom": "^16.8.4", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index a044c52325..11bb217a45 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -7,11 +7,13 @@ import path from 'path'; import {validate} from 'webpack'; +import {isMatch} from 'picomatch'; import fs from 'fs-extra'; import pluginContentDocs from '../index'; import {loadContext} from '@docusaurus/core/src/server/index'; import {applyConfigureWebpack} from '@docusaurus/core/src/webpack/utils'; import {RouteConfig} from '@docusaurus/types'; +import {posixPath} from '@docusaurus/utils'; const createFakeActions = (routeConfigs: RouteConfig[], contentDir) => { return { @@ -87,7 +89,26 @@ describe('simple website', () => { test('getPathToWatch', () => { const pathToWatch = plugin.getPathsToWatch(); - expect(pathToWatch).not.toEqual([]); + const matchPattern = pathToWatch.map(filepath => + posixPath(path.relative(siteDir, filepath)), + ); + expect(matchPattern).not.toEqual([]); + expect(matchPattern).toMatchInlineSnapshot(` + Array [ + "docs/**/*.{md,mdx}", + "sidebars.json", + ] + `); + expect(isMatch('docs/hello.md', matchPattern)).toEqual(true); + expect(isMatch('docs/hello.mdx', matchPattern)).toEqual(true); + expect(isMatch('docs/foo/bar.md', matchPattern)).toEqual(true); + expect(isMatch('docs/hello.js', matchPattern)).toEqual(false); + expect(isMatch('docs/super.mdl', matchPattern)).toEqual(false); + expect(isMatch('docs/mdx', matchPattern)).toEqual(false); + expect(isMatch('sidebars.json', matchPattern)).toEqual(true); + expect(isMatch('versioned_docs/hello.md', matchPattern)).toEqual(false); + expect(isMatch('hello.md', matchPattern)).toEqual(false); + expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false); }); test('configureWebpack', async () => { diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index a2e1061c29..afb49ae0bf 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -36,7 +36,7 @@ import {Configuration} from 'webpack'; const DEFAULT_OPTIONS: PluginOptions = { path: 'docs', // Path to data on filesystem, relative to site dir. routeBasePath: 'docs', // URL Route. - include: ['**/*.md', '**/*.mdx'], // Extensions to include. + include: ['**/*.{md,mdx}'], // Extensions to include. sidebarPath: '', // Path to sidebar configuration for showing a list of markdown pages. docLayoutComponent: '@theme/DocPage', docItemComponent: '@theme/DocItem', diff --git a/packages/docusaurus-utils/src/__tests__/index.test.ts b/packages/docusaurus-utils/src/__tests__/index.test.ts index 2c0b770b17..64246be8f4 100644 --- a/packages/docusaurus-utils/src/__tests__/index.test.ts +++ b/packages/docusaurus-utils/src/__tests__/index.test.ts @@ -25,6 +25,8 @@ describe('load utils', () => { '\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb', 'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb', 'foo\\bar': 'foo/bar', + 'foo\\bar/lol': 'foo/bar/lol', + 'website\\docs/**/*.{md,mdx}': 'website/docs/**/*.{md,mdx}', }; Object.keys(asserts).forEach(file => { expect(posixPath(file)).toBe(asserts[file]); diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index 357d433c0d..c77207f0c5 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -21,6 +21,7 @@ import merge from 'webpack-merge'; import HotModuleReplacementPlugin from 'webpack/lib/HotModuleReplacementPlugin'; import {load} from '../server'; import {StartCLIOptions} from '@docusaurus/types'; +import {posixPath} from '@docusaurus/utils'; import {CONFIG_FILE_NAME, STATIC_DIR_NAME, DEFAULT_PORT} from '../constants'; import {createClientConfig} from '../webpack/client'; import {applyConfigureWebpack} from '../webpack/utils'; @@ -54,9 +55,9 @@ export async function start( const normalizeToSiteDir = filepath => { if (filepath && path.isAbsolute(filepath)) { - return path.relative(siteDir, filepath); + return posixPath(path.relative(siteDir, filepath)); } - return filepath; + return posixPath(filepath); }; const pluginPaths: string[] = _.compact( diff --git a/yarn.lock b/yarn.lock index ae46bdb929..71acd42108 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11972,6 +11972,11 @@ picomatch@^2.0.4, picomatch@^2.0.5: resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.0.7.tgz#514169d8c7cd0bdbeecc8a2609e34a7163de69f6" integrity sha512-oLHIdio3tZ0qH76NybpeneBhYVj0QFTfXEFTc/B3zKQspYfYYkWYgFsmzo+4kvId/bQRcNkVeguI3y+CD22BtA== +picomatch@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.1.0.tgz#0fd042f568d08b1ad9ff2d3ec0f0bfb3cb80e177" + integrity sha512-uhnEDzAbrcJ8R3g2fANnSuXZMBtkpSjxTTgn2LeSiQlfmq72enQJWdQllXW24MBLYnA1SBD2vfvx2o0Zw3Ielw== + pify@^2.0.0, pify@^2.2.0, pify@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"