Skip to content

Commit 711a382

Browse files
committed
refactor ModuleFactory to take an object instead of multiple arguments
1 parent 21a7252 commit 711a382

8 files changed

Lines changed: 33 additions & 16 deletions

lib/Compilation.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
208208
};
209209

210210
var factory = item[0];
211-
factory.create(module.context, dependencies[0], function(err, dependentModule) {
211+
factory.create({
212+
context: module.context,
213+
dependencies: dependencies
214+
}, function(err, dependentModule) {
212215
function isOptional() {
213216
return dependencies.filter(function(d) {
214217
return !d.optional;
@@ -344,7 +347,10 @@ Compilation.prototype._addModuleChain = function process(context, dependency, on
344347
throw new Error("No dependency factory available for this dependency type: " + dependency.constructor.name);
345348
}
346349

347-
moduleFactory.create(context, dependency, function(err, module) {
350+
moduleFactory.create({
351+
context: context,
352+
dependencies: [dependency]
353+
}, function(err, module) {
348354
if(err) {
349355
return errorAndCallback(new EntryModuleNotFoundError(err));
350356
}

lib/ContextModuleFactory.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ module.exports = ContextModuleFactory;
1818
ContextModuleFactory.prototype = Object.create(Tapable.prototype);
1919
ContextModuleFactory.prototype.constructor = ContextModuleFactory;
2020

21-
ContextModuleFactory.prototype.create = function(context, dependency, callback) {
21+
ContextModuleFactory.prototype.create = function(data, callback) {
2222
var module = this;
23+
var context = data.context;
24+
var dependencies = data.dependencies;
25+
var dependency = dependencies[0];
2326
this.applyPluginsAsyncWaterfall("before-resolve", {
2427
context: context,
2528
request: dependency.request,
2629
recursive: dependency.recursive,
2730
regExp: dependency.regExp,
28-
async: dependency.async
31+
async: dependency.async,
32+
dependencies: dependencies
2933
}, function(err, result) {
3034
if(err) return callback(err);
3135

@@ -37,6 +41,7 @@ ContextModuleFactory.prototype.create = function(context, dependency, callback)
3741
var recursive = result.recursive;
3842
var regExp = result.regExp;
3943
var asyncContext = result.async;
44+
var dependencies = result.dependencies;
4045

4146
var loaders, resource, loadersPrefix = "";
4247
var idx = request.lastIndexOf("!");
@@ -80,6 +85,7 @@ ContextModuleFactory.prototype.create = function(context, dependency, callback)
8085
recursive: recursive,
8186
regExp: regExp,
8287
async: asyncContext,
88+
dependencies: dependencies,
8389
resolveDependencies: module.resolveDependencies.bind(module)
8490
}, function(err, result) {
8591
if(err) return callback(err);

lib/DelegatedModuleFactoryPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ DelegatedModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
2121
if(scope) {
2222
normalModuleFactory.plugin("factory", function(factory) {
2323
return function(data, callback) {
24-
var dependency = data.dependency;
24+
var dependency = data.dependencies[0];
2525
var request = dependency.request;
2626
if(request && request.indexOf(scope + "/") === 0) {
2727
var innerRequest = "." + request.substr(scope.length);

lib/DllModuleFactory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = DllModuleFactory;
1313
DllModuleFactory.prototype = Object.create(Tapable.prototype);
1414
DllModuleFactory.prototype.constructor = DllModuleFactory;
1515

16-
DllModuleFactory.prototype.create = function(context, dependency, callback) {
17-
callback(null, new DllModule(context, dependency.dependencies, dependency.name, dependency.type));
16+
DllModuleFactory.prototype.create = function(data, callback) {
17+
var dependency = data.dependencies[0];
18+
callback(null, new DllModule(data.context, dependency.dependencies, dependency.name, dependency.type));
1819
};

lib/ExternalModuleFactoryPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
1515
normalModuleFactory.plugin("factory", function(factory) {
1616
return function(data, callback) {
1717
var context = data.context;
18-
var dependency = data.dependency;
18+
var dependency = data.dependencies[0];
1919

2020
function handleExternal(value, type, callback) {
2121
if(typeof type === "function") {

lib/MultiModuleFactory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = MultiModuleFactory;
1313
MultiModuleFactory.prototype = Object.create(Tapable.prototype);
1414
MultiModuleFactory.prototype.constructor = MultiModuleFactory;
1515

16-
MultiModuleFactory.prototype.create = function(context, dependency, callback) {
17-
callback(null, new MultiModule(context, dependency.dependencies, dependency.name));
16+
MultiModuleFactory.prototype.create = function(data, callback) {
17+
var dependency = data.dependencies[0];
18+
callback(null, new MultiModule(data.context, dependency.dependencies, dependency.name));
1819
};

lib/NormalModuleFactory.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function NormalModuleFactory(context, resolvers, parser, options) {
135135
callback(null, {
136136
context: context,
137137
request: loaders.concat([resource]).join("!"),
138+
dependencies: data.dependencies,
138139
userRequest: userRequest,
139140
rawRequest: request,
140141
loaders: loaders,
@@ -151,15 +152,17 @@ module.exports = NormalModuleFactory;
151152
NormalModuleFactory.prototype = Object.create(Tapable.prototype);
152153
NormalModuleFactory.prototype.constructor = NormalModuleFactory;
153154

154-
NormalModuleFactory.prototype.create = function(context, dependency, callback) {
155+
NormalModuleFactory.prototype.create = function(data, callback) {
155156
var _this = this;
156-
context = context || this.context;
157-
var request = dependency.request;
157+
var context = data.context || this.context;
158+
var dependencies = data.dependencies;
159+
var request = dependencies[0].request;
160+
var contextInfo = data.contextInfo || {};
158161
_this.applyPluginsAsyncWaterfall("before-resolve", {
159-
contextInfo: {},
162+
contextInfo: contextInfo,
160163
context: context,
161164
request: request,
162-
dependency: dependency
165+
dependencies: dependencies
163166
}, function(err, result) {
164167
if(err) return callback(err);
165168

lib/NullFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
function NullFactory() {}
66
module.exports = NullFactory;
77

8-
NullFactory.prototype.create = function(context, dependency, callback) {
8+
NullFactory.prototype.create = function(data, callback) {
99
return callback();
1010
};

0 commit comments

Comments
 (0)