Skip to content

Commit 83ad4b0

Browse files
authored
Merge pull request webpack#4169 from kball/IS4156-multicompiler-watch-options
Update MultiCompiler and lib/webpack to better support multiple watchOptions
2 parents b0e03f4 + ac1a25d commit 83ad4b0

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎lib/MultiCompiler.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ MultiCompiler.prototype.watch = function(watchOptions, handler) {
119119
var compilerStatus = this.compilers.map(function() {
120120
return false;
121121
});
122-
123122
runWithDependencies(this.compilers, function(compiler, callback) {
124123
var compilerIdx = this.compilers.indexOf(compiler);
125124
var firstRun = true;
126-
var watching = compiler.watch(watchOptions, function(err, stats) {
125+
var watching = compiler.watch(Array.isArray(watchOptions) ? watchOptions[compilerIdx] : watchOptions, function(err, stats) {
127126
if(err)
128127
handler(err);
129128
if(stats) {

‎lib/webpack.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function webpack(options, callback) {
4040
if(callback) {
4141
if(typeof callback !== "function") throw new Error("Invalid argument: callback");
4242
if(options.watch === true || (Array.isArray(options) && options.some(o => o.watch))) {
43-
const watchOptions = (!Array.isArray(options) ? options : options[0]).watchOptions || {};
43+
const watchOptions = Array.isArray(options) ? options.map(o => o.watchOptions || {}) : (options.watchOptions || {});
4444
return compiler.watch(watchOptions, callback);
4545
}
4646
compiler.run(callback);

‎test/MultiCompiler.test.js‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ describe("MultiCompiler", () => {
270270
beforeEach(() => {
271271
setupTwoCompilerEnvironment(env);
272272
env.callback = sinon.spy();
273-
env.options = {
273+
env.options = [{
274274
testWatchOptions: true
275-
};
275+
}, {
276+
testWatchOptions2: true
277+
}];
276278
env.result = env.myMultiCompiler.watch(env.options, env.callback);
277279
});
278280

@@ -283,9 +285,9 @@ describe("MultiCompiler", () => {
283285

284286
it("calls watch on each compiler with original options", () => {
285287
env.compiler1WatchCallbacks.length.should.be.exactly(1);
286-
env.compiler1WatchCallbacks[0].options.should.be.exactly(env.options);
288+
env.compiler1WatchCallbacks[0].options.should.be.exactly(env.options[0]);
287289
env.compiler2WatchCallbacks.length.should.be.exactly(1);
288-
env.compiler2WatchCallbacks[0].options.should.be.exactly(env.options);
290+
env.compiler2WatchCallbacks[0].options.should.be.exactly(env.options[1]);
289291
});
290292

291293
it("calls the callback when all compilers watch", () => {
@@ -365,21 +367,23 @@ describe("MultiCompiler", () => {
365367
name: "compiler2"
366368
});
367369
env.callback = sinon.spy();
368-
env.options = {
370+
env.options = [{
369371
testWatchOptions: true
370-
};
372+
}, {
373+
testWatchOptions2: true
374+
}];
371375
env.result = env.myMultiCompiler.watch(env.options, env.callback);
372376
});
373377

374378
it("calls run on each compiler in dependency order", () => {
375379
env.compiler1WatchCallbacks.length.should.be.exactly(0);
376380
env.compiler2WatchCallbacks.length.should.be.exactly(1);
377-
env.compiler2WatchCallbacks[0].options.should.be.exactly(env.options);
381+
env.compiler2WatchCallbacks[0].options.should.be.exactly(env.options[1]);
378382
env.compiler2WatchCallbacks[0].callback(null, {
379383
hash: "bar"
380384
});
381385
env.compiler1WatchCallbacks.length.should.be.exactly(1);
382-
env.compiler1WatchCallbacks[0].options.should.be.exactly(env.options);
386+
env.compiler1WatchCallbacks[0].options.should.be.exactly(env.options[0]);
383387
});
384388

385389
it("calls the callback when all compilers run in dependency order", () => {

0 commit comments

Comments
 (0)