Skip to content

Commit

Permalink
Fix watch for windows directories
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Dec 6, 2021
1 parent c6f0205 commit a4911b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/core-server/src/utils/watch-story-specifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions lib/core-server/src/utils/watch-story-specifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a4911b9

Please sign in to comment.