Skip to content

Commit 2591ebf

Browse files
authored
Merge pull request webpack#6209 from ooflorent/multicompiler_hooks
Forward run and watchRun calls when using MultiCompiler
2 parents 08eb0ff + fb1c041 commit 2591ebf

3 files changed

Lines changed: 57 additions & 680 deletions

File tree

lib/MultiCompiler.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const Tapable = require("tapable").Tapable;
88
const SyncHook = require("tapable").SyncHook;
9+
const MultiHook = require("tapable").MultiHook;
910
const asyncLib = require("async");
1011
const MultiWatching = require("./MultiWatching");
1112
const MultiStats = require("./MultiStats");
@@ -15,8 +16,10 @@ module.exports = class MultiCompiler extends Tapable {
1516
super();
1617
this.hooks = {
1718
done: new SyncHook(["stats"]),
18-
invalid: new SyncHook([]),
19-
watchClose: new SyncHook([])
19+
invalid: new MultiHook(compilers.map(c => c.hooks.invalid)),
20+
run: new MultiHook(compilers.map(c => c.hooks.run)),
21+
watchClose: new SyncHook([]),
22+
watchRun: new MultiHook(compilers.map(c => c.hooks.watchRun))
2023
};
2124
if(!Array.isArray(compilers)) {
2225
compilers = Object.keys(compilers).map((name) => {
@@ -44,7 +47,6 @@ module.exports = class MultiCompiler extends Tapable {
4447
compilerDone = false;
4548
doneCompilers--;
4649
}
47-
this.hooks.invalid.call();
4850
});
4951
});
5052
}

test/MultiCompiler.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
3+
/* globals describe it */
4+
const path = require("path");
5+
const should = require("should");
6+
const MemoryFs = require("memory-fs");
7+
const webpack = require("../");
8+
9+
const createMultiCompiler = () => {
10+
const compiler = webpack([{
11+
context: path.join(__dirname, "fixtures"),
12+
entry: "./a.js"
13+
}, {
14+
context: path.join(__dirname, "fixtures"),
15+
entry: "./b.js"
16+
}]);
17+
compiler.outputFileSystem = new MemoryFs();
18+
return compiler;
19+
};
20+
21+
describe("MultiCompiler", function() {
22+
it("should trigger 'run' for each child compiler", done => {
23+
const compiler = createMultiCompiler();
24+
let called = 0;
25+
26+
compiler.hooks.run.tap("MultiCompiler test", () => called++);
27+
compiler.run(err => {
28+
if(err) {
29+
throw err;
30+
} else {
31+
should(called).be.equal(2);
32+
done();
33+
}
34+
});
35+
});
36+
37+
it("should trigger 'watchRun' for each child compiler", done => {
38+
const compiler = createMultiCompiler();
39+
let called = 0;
40+
41+
compiler.hooks.watchRun.tap("MultiCompiler test", () => called++);
42+
const watcher = compiler.watch(1000, err => {
43+
if(err) {
44+
throw err;
45+
} else {
46+
watcher.close();
47+
should(called).be.equal(2);
48+
done();
49+
}
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)