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

fix(watchLocalModules): wait for change to finish #285

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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