Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix(watchLocalModules): wait for change to finish (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAdshead committed Aug 25, 2020
1 parent 5503a03 commit a27d4ba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/server/utils/watchLocalModules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('watchLocalModules', () => {

it('should watch the modules directory', () => {
watchLocalModules();
expect(chokidar.watch).toHaveBeenCalledWith(path.resolve(__dirname, '../../../static/modules'));
expect(chokidar.watch).toHaveBeenCalledWith(path.resolve(__dirname, '../../../static/modules'), { awaitWriteFinish: true });
});

it('should update the module registry when a server bundle changes', async () => {
Expand Down
3 changes: 1 addition & 2 deletions src/server/utils/watchLocalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ export default function watchLocalModules() {
const staticsDirectoryPath = path.resolve(__dirname, '../../../static');
const moduleDirectory = path.resolve(staticsDirectoryPath, 'modules');
const moduleMapPath = path.resolve(staticsDirectoryPath, 'module-map.json');
const watcher = chokidar.watch(moduleDirectory);
const watcher = chokidar.watch(moduleDirectory, { awaitWriteFinish: true });

watcher.on('change', async (changedPath) => {
if (!changedPath.endsWith('.node.js')) return;

const match = changedPath.substring(moduleDirectory.length).match(/\/([^/]+)\/([^/]+)/);
if (!match) return;

const [, moduleNameChangeDetectedIn] = match;

const moduleMap = JSON.parse(fs.readFileSync(moduleMapPath, 'utf8'));
Expand Down

0 comments on commit a27d4ba

Please sign in to comment.