From a27d4ba3af68c0bac29650be9220dadf0461227a Mon Sep 17 00:00:00 2001 From: Jonny Adshead Date: Tue, 25 Aug 2020 15:19:58 -0700 Subject: [PATCH] fix(watchLocalModules): wait for change to finish (#285) --- __tests__/server/utils/watchLocalModules.spec.js | 2 +- src/server/utils/watchLocalModules.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/__tests__/server/utils/watchLocalModules.spec.js b/__tests__/server/utils/watchLocalModules.spec.js index dd6755899..f34bcd0de 100644 --- a/__tests__/server/utils/watchLocalModules.spec.js +++ b/__tests__/server/utils/watchLocalModules.spec.js @@ -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 () => { diff --git a/src/server/utils/watchLocalModules.js b/src/server/utils/watchLocalModules.js index f7e63407a..64eb9ce32 100644 --- a/src/server/utils/watchLocalModules.js +++ b/src/server/utils/watchLocalModules.js @@ -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'));