Skip to content

Commit

Permalink
make sure that invalid event is only reported once
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 9, 2021
1 parent 1f48895 commit b525e61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
10 changes: 8 additions & 2 deletions lib/Watching.js
Expand Up @@ -53,6 +53,7 @@ class Watching {
this.compiler = compiler;
this.running = false;
this._initial = true;
this._invalidReported = true;
this._needRecords = true;
this.watcher = undefined;
this.pausedWatcher = undefined;
Expand Down Expand Up @@ -83,6 +84,7 @@ class Watching {
});
}
this.invalid = false;
this._invalidReported = false;
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
if (err) return this._done(err);
const onCompiled = (err, compilation) => {
Expand Down Expand Up @@ -270,7 +272,10 @@ class Watching {
this._onChange();
},
(fileName, changeTime) => {
this.compiler.hooks.invalid.call(fileName, changeTime);
if (!this._invalidReported) {
this._invalidReported = true;
this.compiler.hooks.invalid.call(fileName, changeTime);
}
this._onInvalid();
}
);
Expand All @@ -284,7 +289,8 @@ class Watching {
if (callback) {
this.callbacks.push(callback);
}
if (!this._initial) {
if (!this._invalidReported) {
this._invalidReported = true;
this.compiler.hooks.invalid.call(null, Date.now());
}
this._invalidate();
Expand Down
29 changes: 20 additions & 9 deletions test/MultiCompiler.test.js
Expand Up @@ -246,6 +246,9 @@ describe("MultiCompiler", function () {
};
const events = [];
compiler.compilers.forEach(c => {
c.hooks.invalid.tap("test", () => {
events.push(`${c.name} invalid`);
});
c.hooks.watchRun.tap("test", () => {
events.push(`${c.name} run`);
});
Expand Down Expand Up @@ -273,15 +276,15 @@ describe("MultiCompiler", function () {
expect(compiler.compilers[0].modifiedFiles).toBe(undefined);
expect(compiler.compilers[0].removedFiles).toBe(undefined);
expect(events).toMatchInlineSnapshot(`
Array [
"b run",
"b done",
"c run",
"c done",
"a run",
"a done",
]
`);
Array [
"b run",
"b done",
"c run",
"c done",
"a run",
"a done",
]
`);
events.length = 0;
// wait until watching begins
setTimeout(() => {
Expand All @@ -301,8 +304,10 @@ describe("MultiCompiler", function () {
expect(compiler.compilers[1].removedFiles).toEqual(new Set());
expect(events).toMatchInlineSnapshot(`
Array [
"b invalid",
"b run",
"b done",
"a invalid",
"a run",
"a done",
]
Expand All @@ -317,10 +322,13 @@ describe("MultiCompiler", function () {
`);
expect(events).toMatchInlineSnapshot(`
Array [
"b invalid",
"b run",
"b done",
"a invalid",
"a run",
"a done",
"a invalid",
"a run",
"a done",
]
Expand All @@ -344,10 +352,13 @@ describe("MultiCompiler", function () {
`);
expect(events).toMatchInlineSnapshot(`
Array [
"b invalid",
"c invalid",
"b run",
"b done",
"c run",
"c done",
"a invalid",
"a run",
"a done",
]
Expand Down

0 comments on commit b525e61

Please sign in to comment.