Skip to content

Commit 101850c

Browse files
committed
assign correct records and cache to child compilations
This is a breaking change because plugins or loader could rely on this incorrect behavior When using child compilations plugins and loaders should use a unique compiler name or use a consistent order fixes webpack#2777
1 parent bf3652b commit 101850c

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/Compilation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Compilation extends Tapable {
8080
this.children = [];
8181
this.dependencyFactories = new Map();
8282
this.dependencyTemplates = new Map();
83+
this.childrenCounters = {};
8384
}
8485

8586
getStats() {
@@ -1218,8 +1219,10 @@ class Compilation extends Tapable {
12181219
return this.mainTemplate.applyPluginsWaterfall("asset-path", filename, data);
12191220
}
12201221

1221-
createChildCompiler(name, outputOptions) {
1222-
return this.compiler.createChildCompiler(this, name, outputOptions);
1222+
createChildCompiler(name, outputOptions, plugins) {
1223+
var idx = (this.childrenCounters[name] || 0);
1224+
this.childrenCounters[name] = idx + 1;
1225+
return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins);
12231226
}
12241227

12251228
checkConstraints() {

lib/Compiler.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var Stats = require("./Stats");
1010
var NormalModuleFactory = require("./NormalModuleFactory");
1111
var ContextModuleFactory = require("./ContextModuleFactory");
1212

13+
var makePathsRelative = require("./util/identifier").makePathsRelative;
14+
1315
function Watching(compiler, watchOptions, handler) {
1416
this.startTime = null;
1517
this.invalid = false;
@@ -407,7 +409,7 @@ Compiler.prototype.readRecords = function readRecords(callback) {
407409
});
408410
};
409411

410-
Compiler.prototype.createChildCompiler = function(compilation, compilerName, outputOptions, plugins) {
412+
Compiler.prototype.createChildCompiler = function(compilation, compilerName, compilerIndex, outputOptions, plugins) {
411413
var childCompiler = new Compiler();
412414
if(Array.isArray(plugins)) {
413415
plugins.forEach(plugin => childCompiler.apply(plugin));
@@ -423,8 +425,23 @@ Compiler.prototype.createChildCompiler = function(compilation, compilerName, out
423425
childCompiler.resolvers = this.resolvers;
424426
childCompiler.fileTimestamps = this.fileTimestamps;
425427
childCompiler.contextTimestamps = this.contextTimestamps;
426-
if(!this.records[compilerName]) this.records[compilerName] = [];
427-
this.records[compilerName].push(childCompiler.records = {});
428+
429+
var relativeCompilerName = makePathsRelative(this.context, compilerName);
430+
if(!this.records[relativeCompilerName]) this.records[relativeCompilerName] = [];
431+
if(this.records[relativeCompilerName][compilerIndex])
432+
childCompiler.records = this.records[relativeCompilerName][compilerIndex];
433+
else
434+
this.records[relativeCompilerName].push(childCompiler.records = {});
435+
436+
if(this.cache) {
437+
if(!this.cache.children) this.cache.children = {};
438+
if(!this.cache.children[compilerName]) this.cache.children[compilerName] = [];
439+
if(this.cache.children[compilerName][compilerIndex])
440+
childCompiler.cache = this.cache.children[compilerName][compilerIndex];
441+
else
442+
this.cache.children[compilerName].push(childCompiler.cache = {});
443+
}
444+
428445
childCompiler.options = Object.create(this.options);
429446
childCompiler.options.output = Object.create(childCompiler.options.output);
430447
for(name in outputOptions) {

0 commit comments

Comments
 (0)