mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
fix(v2): fix chokidar/watcher does not trigger reload on windows (#1943)
* fix(v2): fix chokidar/watcher does not trigger reload on windows * nits * nits * stronger test
This commit is contained in:
parent
ff83e6f8bc
commit
baa884fe2e
7 changed files with 35 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue