Skip to content

Commit

Permalink
Merge pull request #4704 from webpack/bugfix/child-records-cache
Browse files Browse the repository at this point in the history
assign correct records and cache to child compilations
  • Loading branch information
sokra committed May 16, 2017
2 parents d5d0428 + 101850c commit ee541d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/Compilation.js
Expand Up @@ -80,6 +80,7 @@ class Compilation extends Tapable {
this.children = [];
this.dependencyFactories = new Map();
this.dependencyTemplates = new Map();
this.childrenCounters = {};
}

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

createChildCompiler(name, outputOptions) {
return this.compiler.createChildCompiler(this, name, outputOptions);
createChildCompiler(name, outputOptions, plugins) {
var idx = (this.childrenCounters[name] || 0);
this.childrenCounters[name] = idx + 1;
return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins);
}

checkConstraints() {
Expand Down
23 changes: 20 additions & 3 deletions lib/Compiler.js
Expand Up @@ -10,6 +10,8 @@ var Stats = require("./Stats");
var NormalModuleFactory = require("./NormalModuleFactory");
var ContextModuleFactory = require("./ContextModuleFactory");

var makePathsRelative = require("./util/identifier").makePathsRelative;

function Watching(compiler, watchOptions, handler) {
this.startTime = null;
this.invalid = false;
Expand Down Expand Up @@ -407,7 +409,7 @@ Compiler.prototype.readRecords = function readRecords(callback) {
});
};

Compiler.prototype.createChildCompiler = function(compilation, compilerName, outputOptions, plugins) {
Compiler.prototype.createChildCompiler = function(compilation, compilerName, compilerIndex, outputOptions, plugins) {
var childCompiler = new Compiler();
if(Array.isArray(plugins)) {
plugins.forEach(plugin => childCompiler.apply(plugin));
Expand All @@ -423,8 +425,23 @@ Compiler.prototype.createChildCompiler = function(compilation, compilerName, out
childCompiler.resolvers = this.resolvers;
childCompiler.fileTimestamps = this.fileTimestamps;
childCompiler.contextTimestamps = this.contextTimestamps;
if(!this.records[compilerName]) this.records[compilerName] = [];
this.records[compilerName].push(childCompiler.records = {});

var relativeCompilerName = makePathsRelative(this.context, compilerName);
if(!this.records[relativeCompilerName]) this.records[relativeCompilerName] = [];
if(this.records[relativeCompilerName][compilerIndex])
childCompiler.records = this.records[relativeCompilerName][compilerIndex];
else
this.records[relativeCompilerName].push(childCompiler.records = {});

if(this.cache) {
if(!this.cache.children) this.cache.children = {};
if(!this.cache.children[compilerName]) this.cache.children[compilerName] = [];
if(this.cache.children[compilerName][compilerIndex])
childCompiler.cache = this.cache.children[compilerName][compilerIndex];
else
this.cache.children[compilerName].push(childCompiler.cache = {});
}

childCompiler.options = Object.create(this.options);
childCompiler.options.output = Object.create(childCompiler.options.output);
for(name in outputOptions) {
Expand Down

0 comments on commit ee541d9

Please sign in to comment.