Merge pull request #8253 from renatoagds/compiler-watch-mode

Adding watchMode flag in compiler
This commit is contained in:
Tobias Koppers 2018-10-24 09:39:33 +02:00 committed by GitHub
commit c74bee9cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -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);

View File

@ -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();
};

View File

@ -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,