close watching when closing compiler

do not shutdown cache when closing only the watching
This commit is contained in:
Tobias Koppers 2021-08-30 15:01:24 +02:00
parent 553d9b62bb
commit 05c1861684
3 changed files with 32 additions and 36 deletions

View File

@ -1130,6 +1130,13 @@ ${other}`);
* @returns {void}
*/
close(callback) {
if (this.watching) {
// When there is still an active watching, close this first
this.watching.close(err => {
this.close(callback);
});
return;
}
this.hooks.shutdown.callAsync(err => {
if (err) return callback(err);
// Get rid of reference to last compilation to avoid leaking memory

View File

@ -419,26 +419,24 @@ class Watching {
this.compiler.fileTimestamps = undefined;
this.compiler.contextTimestamps = undefined;
this.compiler.fsStartTime = undefined;
const shutdown = () => {
this.compiler.cache.shutdown(err => {
this.compiler.hooks.watchClose.call();
const closeCallbacks = this._closeCallbacks;
this._closeCallbacks = undefined;
for (const cb of closeCallbacks) cb(err);
});
const shutdown = err => {
this.compiler.hooks.watchClose.call();
const closeCallbacks = this._closeCallbacks;
this._closeCallbacks = undefined;
for (const cb of closeCallbacks) cb(err);
};
if (compilation) {
const logger = compilation.getLogger("webpack.Watching");
logger.time("storeBuildDependencies");
this.compiler.cache.storeBuildDependencies(
compilation.buildDependencies,
err => {
err2 => {
logger.timeEnd("storeBuildDependencies");
shutdown();
shutdown(err || err2);
}
);
} else {
shutdown();
shutdown(err);
}
};

View File

@ -30,13 +30,6 @@ const createMultiCompiler = options => {
return compiler;
};
const close = (watching, compiler, done) => {
watching.close(err => {
if (err) return done(err);
compiler.close(done);
});
};
describe("MultiCompiler", function () {
jest.setTimeout(20000);
@ -59,12 +52,12 @@ describe("MultiCompiler", function () {
let called = 0;
compiler.hooks.watchRun.tap("MultiCompiler test", () => called++);
const watching = compiler.watch(1000, err => {
compiler.watch(1000, err => {
if (err) {
throw err;
}
expect(called).toBe(2);
close(watching, compiler, done);
compiler.close(done);
});
});
@ -81,12 +74,12 @@ describe("MultiCompiler", function () {
});
it("should not be running twice at a time (watch)", done => {
const compiler = createMultiCompiler();
const watching = compiler.watch({}, (err, stats) => {
compiler.watch({}, (err, stats) => {
if (err) return done(err);
});
compiler.watch({}, (err, stats) => {
if (err) {
close(watching, compiler, done);
compiler.close(done);
}
});
});
@ -103,13 +96,12 @@ describe("MultiCompiler", function () {
});
it("should not be running twice at a time (watch - run)", done => {
const compiler = createMultiCompiler();
let watching;
watching = compiler.watch({}, (err, stats) => {
compiler.watch({}, (err, stats) => {
if (err) return done(err);
});
compiler.run((err, stats) => {
if (err) {
close(watching, compiler, done);
compiler.close(done);
}
});
});
@ -149,10 +141,9 @@ describe("MultiCompiler", function () {
compiler.run((err, stats) => {
if (err) return done(err);
let watching;
watching = compiler.watch({}, (err, stats) => {
compiler.watch({}, (err, stats) => {
if (err) return done(err);
close(watching, compiler, done);
compiler.close(done);
});
});
});
@ -174,9 +165,9 @@ describe("MultiCompiler", function () {
if (err) return done(err);
});
watching.close(() => {
const watching2 = compiler.watch({}, (err, stats) => {
compiler.watch({}, (err, stats) => {
if (err) return done(err);
close(watching2, compiler, done);
compiler.close(done);
});
});
});
@ -274,7 +265,7 @@ describe("MultiCompiler", function () {
});
let update = 0;
const watching = compiler.watch({}, (err, stats) => {
compiler.watch({}, (err, stats) => {
if (err) return done(err);
const info = () => stats.toString({ preset: "summary", version: false });
switch (update++) {
@ -380,7 +371,7 @@ describe("MultiCompiler", function () {
]
`);
events.length = 0;
close(watching, compiler, done);
compiler.close(done);
break;
default:
done(new Error("unexpected"));
@ -458,7 +449,7 @@ describe("MultiCompiler", function () {
events.length = 0;
expect(state).toBe(1);
setTimeout(() => {
close(watching, compiler, done);
compiler.close(done);
}, 1000);
} catch (e) {
console.error(e);
@ -537,7 +528,7 @@ describe("MultiCompiler", function () {
events.length = 0;
expect(state).toBe(1);
setTimeout(() => {
close(watching, compiler, done);
compiler.close(done);
}, 1000);
} catch (e) {
console.error(e);
@ -579,7 +570,7 @@ describe("MultiCompiler", function () {
watching.invalidate(err => {
if (err) return done(err);
close(watching, compiler, done);
compiler.close(done);
});
});
}, 2000);
@ -626,9 +617,9 @@ describe("MultiCompiler", function () {
}
}
};
const watching = compiler.watch({}, (err, stats) => {
compiler.watch({}, (err, stats) => {
if (err) return done(err);
close(watching, compiler, done);
compiler.close(done);
});
});
});