Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not drop aggregated changes with resumed compilation #12881

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/Watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,21 @@ class Watching {
return;
}
if (this.watcher) {
this.compiler.modifiedFiles =
this.watcher.getAggregatedChanges &&
this.watcher.getAggregatedChanges();
this.compiler.removedFiles =
this.watcher.getAggregatedRemovals &&
this.watcher.getAggregatedRemovals();
this.compiler.fileTimestamps = this.watcher.getFileTimeInfoEntries();
this.compiler.contextTimestamps = this.watcher.getContextTimeInfoEntries();
// Following must be either removed or merged
// because it will overwrite existing (and unprocessed):
// - this.compiler.modifiedFiles
// - this.compiler.removedFiles
// Alternatively, we can merge those with values from the
// oldWatcher in NodeWatchFileSystem

// this.compiler.modifiedFiles =
// this.watcher.getAggregatedChanges &&
// this.watcher.getAggregatedChanges();
// this.compiler.removedFiles =
// this.watcher.getAggregatedRemovals &&
// this.watcher.getAggregatedRemovals();
// this.compiler.fileTimestamps = this.watcher.getFileTimeInfoEntries();
// this.compiler.contextTimestamps = this.watcher.getContextTimeInfoEntries();
this.pausedWatcher = this.watcher;
this.watcher.pause();
this.watcher = null;
Expand Down
10 changes: 10 additions & 0 deletions lib/node/NodeWatchFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ class NodeWatchFileSystem {
this.watcher.watch({ files, directories, missing, startTime });

if (oldWatcher) {
// Ideally we need it in watchpack, e.g.:
// oldWatcher.close({ emitAggregated: true })
// (this will emit aggregated values before closing)
// Dirty workaround that does the same:
if (
oldWatcher.aggregatedChanges.size > 0 ||
oldWatcher.aggregatedRemovals.size > 0
) {
oldWatcher._onTimeout();
}
oldWatcher.close();
}
return {
Expand Down
24 changes: 24 additions & 0 deletions test/WatchSuspend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe("WatchSuspend", () => {
}
});
watching = compiler.watch({ aggregateTimeout: 50 }, () => {});

compiler.hooks.done.tap("WatchSuspendTest", () => {
if (onChange) onChange();
});
Expand Down Expand Up @@ -92,5 +93,28 @@ describe("WatchSuspend", () => {
};
watching.resume();
});

it("should not ignore changes during resumed compilation", async () => {
// aggregateTimeout must be long enough for this test
// So set-up new watcher and wait when initial compilation is done
await new Promise(resolve => {
watching.close();
watching = compiler.watch({ aggregateTimeout: 1000 }, resolve);
});
return new Promise(resolve => {
watching.suspend();
fs.writeFileSync(filePath, "'baz'", "utf-8");

// Run resume between "changed" and "aggregated" events
setTimeout(() => {
watching.resume();

setTimeout(() => {
expect(fs.readFileSync(outputPath, "utf-8")).toContain("'baz'");
resolve();
}, 2000);
}, 200);
});
});
});
});