From b525e61a72845976692060a7bc82b987653a1380 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 9 Apr 2021 17:51:58 +0200 Subject: [PATCH] make sure that invalid event is only reported once --- lib/Watching.js | 10 ++++++++-- test/MultiCompiler.test.js | 29 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/Watching.js b/lib/Watching.js index d3c513a401f..254c80f6809 100644 --- a/lib/Watching.js +++ b/lib/Watching.js @@ -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; @@ -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) => { @@ -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(); } ); @@ -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(); diff --git a/test/MultiCompiler.test.js b/test/MultiCompiler.test.js index 319e9b4470d..0c785d44058 100644 --- a/test/MultiCompiler.test.js +++ b/test/MultiCompiler.test.js @@ -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`); }); @@ -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(() => { @@ -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", ] @@ -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", ] @@ -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", ]