From a4911b9fa761a80b94b0c72fb9688285335b0294 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Sun, 5 Dec 2021 17:51:11 -0800 Subject: [PATCH] Fix watch for windows directories --- lib/core-server/src/utils/watch-story-specifiers.test.ts | 2 +- lib/core-server/src/utils/watch-story-specifiers.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/core-server/src/utils/watch-story-specifiers.test.ts b/lib/core-server/src/utils/watch-story-specifiers.test.ts index cc03b45a9d94..53eb81dad074 100644 --- a/lib/core-server/src/utils/watch-story-specifiers.test.ts +++ b/lib/core-server/src/utils/watch-story-specifiers.test.ts @@ -79,7 +79,7 @@ describe('watchStorySpecifiers', () => { onInvalidate.mockClear(); await onChange('src/nested', 1234); expect(onInvalidate).toHaveBeenCalledWith(specifier, `./src/nested/Button.stories.ts`, false); - }, 10000); + }); it('watches single file globs', async () => { const specifier = normalizeStoriesEntry('../src/nested/Button.stories.mdx', options); diff --git a/lib/core-server/src/utils/watch-story-specifiers.ts b/lib/core-server/src/utils/watch-story-specifiers.ts index 8b4baf4d1a1f..f42221c512a5 100644 --- a/lib/core-server/src/utils/watch-story-specifiers.ts +++ b/lib/core-server/src/utils/watch-story-specifiers.ts @@ -73,9 +73,14 @@ export function watchStorySpecifiers( // because the directoru could already be within the files part (e.g. './x/foo/bar') path.basename(specifier.files) ); - const files = await glob(dirGlob); + // glob only supports forward slashes + const files = await glob(dirGlob.replace(/\\/g, '/')); + files.forEach((filePath) => { - const fileImportPath = toImportPath(path.relative(options.workingDir, filePath)); + const fileImportPath = toImportPath( + // use posix path separators even on windows + path.relative(options.workingDir, filePath).replace(/\\/g, '/') + ); if (specifier.importPathMatcher.exec(fileImportPath)) { onInvalidate(specifier, fileImportPath, removed);