diff --git a/__tests__/server/utils/watchLocalModules.spec.js b/__tests__/server/utils/watchLocalModules.spec.js index dd675589..f34bcd0d 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 f7e63407..64eb9ce3 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'));