mirror of https://github.com/webpack/webpack.git
close watching when closing compiler
do not shutdown cache when closing only the watching
This commit is contained in:
parent
553d9b62bb
commit
05c1861684
|
@ -1130,6 +1130,13 @@ ${other}`);
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
close(callback) {
|
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 => {
|
this.hooks.shutdown.callAsync(err => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
// Get rid of reference to last compilation to avoid leaking memory
|
// Get rid of reference to last compilation to avoid leaking memory
|
||||||
|
|
|
@ -419,26 +419,24 @@ class Watching {
|
||||||
this.compiler.fileTimestamps = undefined;
|
this.compiler.fileTimestamps = undefined;
|
||||||
this.compiler.contextTimestamps = undefined;
|
this.compiler.contextTimestamps = undefined;
|
||||||
this.compiler.fsStartTime = undefined;
|
this.compiler.fsStartTime = undefined;
|
||||||
const shutdown = () => {
|
const shutdown = err => {
|
||||||
this.compiler.cache.shutdown(err => {
|
this.compiler.hooks.watchClose.call();
|
||||||
this.compiler.hooks.watchClose.call();
|
const closeCallbacks = this._closeCallbacks;
|
||||||
const closeCallbacks = this._closeCallbacks;
|
this._closeCallbacks = undefined;
|
||||||
this._closeCallbacks = undefined;
|
for (const cb of closeCallbacks) cb(err);
|
||||||
for (const cb of closeCallbacks) cb(err);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
if (compilation) {
|
if (compilation) {
|
||||||
const logger = compilation.getLogger("webpack.Watching");
|
const logger = compilation.getLogger("webpack.Watching");
|
||||||
logger.time("storeBuildDependencies");
|
logger.time("storeBuildDependencies");
|
||||||
this.compiler.cache.storeBuildDependencies(
|
this.compiler.cache.storeBuildDependencies(
|
||||||
compilation.buildDependencies,
|
compilation.buildDependencies,
|
||||||
err => {
|
err2 => {
|
||||||
logger.timeEnd("storeBuildDependencies");
|
logger.timeEnd("storeBuildDependencies");
|
||||||
shutdown();
|
shutdown(err || err2);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
shutdown();
|
shutdown(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,6 @@ const createMultiCompiler = options => {
|
||||||
return compiler;
|
return compiler;
|
||||||
};
|
};
|
||||||
|
|
||||||
const close = (watching, compiler, done) => {
|
|
||||||
watching.close(err => {
|
|
||||||
if (err) return done(err);
|
|
||||||
compiler.close(done);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("MultiCompiler", function () {
|
describe("MultiCompiler", function () {
|
||||||
jest.setTimeout(20000);
|
jest.setTimeout(20000);
|
||||||
|
|
||||||
|
@ -59,12 +52,12 @@ describe("MultiCompiler", function () {
|
||||||
let called = 0;
|
let called = 0;
|
||||||
|
|
||||||
compiler.hooks.watchRun.tap("MultiCompiler test", () => called++);
|
compiler.hooks.watchRun.tap("MultiCompiler test", () => called++);
|
||||||
const watching = compiler.watch(1000, err => {
|
compiler.watch(1000, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
expect(called).toBe(2);
|
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 => {
|
it("should not be running twice at a time (watch)", done => {
|
||||||
const compiler = createMultiCompiler();
|
const compiler = createMultiCompiler();
|
||||||
const watching = compiler.watch({}, (err, stats) => {
|
compiler.watch({}, (err, stats) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
});
|
});
|
||||||
compiler.watch({}, (err, stats) => {
|
compiler.watch({}, (err, stats) => {
|
||||||
if (err) {
|
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 => {
|
it("should not be running twice at a time (watch - run)", done => {
|
||||||
const compiler = createMultiCompiler();
|
const compiler = createMultiCompiler();
|
||||||
let watching;
|
compiler.watch({}, (err, stats) => {
|
||||||
watching = compiler.watch({}, (err, stats) => {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
});
|
});
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -149,10 +141,9 @@ describe("MultiCompiler", function () {
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
let watching;
|
compiler.watch({}, (err, stats) => {
|
||||||
watching = compiler.watch({}, (err, stats) => {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -174,9 +165,9 @@ describe("MultiCompiler", function () {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
});
|
});
|
||||||
watching.close(() => {
|
watching.close(() => {
|
||||||
const watching2 = compiler.watch({}, (err, stats) => {
|
compiler.watch({}, (err, stats) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
close(watching2, compiler, done);
|
compiler.close(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -274,7 +265,7 @@ describe("MultiCompiler", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
let update = 0;
|
let update = 0;
|
||||||
const watching = compiler.watch({}, (err, stats) => {
|
compiler.watch({}, (err, stats) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
const info = () => stats.toString({ preset: "summary", version: false });
|
const info = () => stats.toString({ preset: "summary", version: false });
|
||||||
switch (update++) {
|
switch (update++) {
|
||||||
|
@ -380,7 +371,7 @@ describe("MultiCompiler", function () {
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
events.length = 0;
|
events.length = 0;
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
done(new Error("unexpected"));
|
done(new Error("unexpected"));
|
||||||
|
@ -458,7 +449,7 @@ describe("MultiCompiler", function () {
|
||||||
events.length = 0;
|
events.length = 0;
|
||||||
expect(state).toBe(1);
|
expect(state).toBe(1);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -537,7 +528,7 @@ describe("MultiCompiler", function () {
|
||||||
events.length = 0;
|
events.length = 0;
|
||||||
expect(state).toBe(1);
|
expect(state).toBe(1);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -579,7 +570,7 @@ describe("MultiCompiler", function () {
|
||||||
|
|
||||||
watching.invalidate(err => {
|
watching.invalidate(err => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
@ -626,9 +617,9 @@ describe("MultiCompiler", function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const watching = compiler.watch({}, (err, stats) => {
|
compiler.watch({}, (err, stats) => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
close(watching, compiler, done);
|
compiler.close(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue