Merge pull request #8253 from renatoagds/compiler-watch-mode
Adding watchMode flag in compiler
This commit is contained in:
commit
c74bee9cef
|
@ -184,12 +184,16 @@ class Compiler extends Tapable {
|
|||
|
||||
/** @type {boolean} */
|
||||
this.running = false;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.watchMode = false;
|
||||
}
|
||||
|
||||
watch(watchOptions, handler) {
|
||||
if (this.running) return handler(new ConcurrentCompilationError());
|
||||
|
||||
this.running = true;
|
||||
this.watchMode = true;
|
||||
this.fileTimestamps = new Map();
|
||||
this.contextTimestamps = new Map();
|
||||
return new Watching(this, watchOptions, handler);
|
||||
|
|
|
@ -170,6 +170,7 @@ class Watching {
|
|||
const finalCallback = () => {
|
||||
this.compiler.hooks.watchClose.call();
|
||||
this.compiler.running = false;
|
||||
this.compiler.watchMode = false;
|
||||
if (callback !== undefined) callback();
|
||||
};
|
||||
|
||||
|
|
|
@ -448,6 +448,28 @@ describe("Compiler", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
it("should flag watchMode as true in watch", function(done) {
|
||||
const compiler = webpack({
|
||||
context: __dirname,
|
||||
mode: "production",
|
||||
entry: "./c",
|
||||
output: {
|
||||
path: "/",
|
||||
filename: "bundle.js"
|
||||
}
|
||||
});
|
||||
|
||||
compiler.outputFileSystem = new MemoryFs();
|
||||
|
||||
const watch = compiler.watch({}, err => {
|
||||
if (err) return done(err);
|
||||
expect(compiler.watchMode).toBeTruthy();
|
||||
watch.close(() => {
|
||||
expect(compiler.watchMode).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it("should use cache on second run call", function(done) {
|
||||
const compiler = webpack({
|
||||
context: __dirname,
|
||||
|
|
Loading…
Reference in New Issue