Skip to content

Commit 11a578a

Browse files
committed
Merge branch 'master' into webpack-2
Conflicts: lib/NormalModuleFactory.js
2 parents 599c39d + c5eceb0 commit 11a578a

13 files changed

Lines changed: 288 additions & 201 deletions

‎bin/convert-argv.js‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,37 @@ module.exports = function(optimist, argv, convertOptions) {
8080
}
8181

8282
if(argv["watch"]) {
83+
// TODO remove this in next major version
84+
if(options.watch && typeof options.watch === "object") {
85+
console.warn("options.watch is deprecated: use options.watchOptions instead");
86+
options.watchOptions = options.watch;
87+
}
88+
// TODO remove this in next major version
8389
if(options.watchDelay) {
84-
console.warn("watchDelay is deprecated: Use 'watch.aggregateTimeout' instead.");
85-
options.watch = options.watch || {};
86-
options.watch.aggregateTimeout = options.watchDelay;
90+
console.warn("options.watchDelay is deprecated: Use 'options.watchOptions.aggregateTimeout' instead");
91+
options.watchOptions = options.watchOptions || {};
92+
options.watchOptions.aggregateTimeout = options.watchDelay;
8793
}
88-
options.doWatch = true;
94+
options.watch = true;
8995
}
9096

9197
if(argv["watch-delay"]) {
92-
options.watch = options.watch || {};
93-
options.watch.aggregateTimeout = +argv["watch-delay"];
98+
console.warn("--watch-delay is deprecated: Use '--watch-aggregate-timeout' instead");
99+
options.watchOptions = options.watchOptions || {};
100+
options.watchOptions.aggregateTimeout = +argv["watch-delay"];
94101
}
95102

96103
if(argv["watch-aggregate-timeout"]) {
97-
options.watch = options.watch || {};
98-
options.watch.aggregateTimeout = +argv["watch-aggregate-timeout"];
104+
options.watchOptions = options.watchOptions || {};
105+
options.watchOptions.aggregateTimeout = +argv["watch-aggregate-timeout"];
99106
}
100107

101108
if(argv["watch-poll"]) {
102-
options.watch = options.watch || {};
109+
options.watchOptions = options.watchOptions || {};
103110
if(typeof argv["watch-poll"] !== "boolean")
104-
options.watch.poll = +argv["watch-poll"];
111+
options.watchOptions.poll = +argv["watch-poll"];
105112
else
106-
options.watch.poll = true;
113+
options.watchOptions.poll = true;
107114
}
108115

109116
function processOptions(options) {

‎bin/webpack.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ Error.stackTrackLimit = 30;
145145
var lastHash = null;
146146
var compiler = webpack(options);
147147
function compilerCallback(err, stats) {
148-
if(!options.doWatch) {
148+
if(!options.watch) {
149149
// Do not keep cache anymore
150150
compiler.purgeInputFileSystem();
151151
}
152152
if(err) {
153153
lastHash = null;
154154
console.error(err.stack || err);
155155
if(err.details) console.error(err.details);
156-
if(!options.doWatch) {
156+
if(!options.watch) {
157157
process.on("exit", function() {
158158
process.exit(1);
159159
});
@@ -172,7 +172,9 @@ function compilerCallback(err, stats) {
172172
});
173173
}
174174
}
175-
if(options.doWatch)
176-
compiler.watch(options.watch, compilerCallback);
177-
else
175+
if(options.watch) {
176+
var primaryOptions = !Array.isArray(options) ? options : options[0];
177+
var watchOptions = primaryOptions.watchOptions || primaryOptions.watch || {};
178+
compiler.watch(watchOptions, compilerCallback);
179+
} else
178180
compiler.run(compilerCallback);

‎lib/BannerPlugin.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33
Author Tobias Koppers @sokra
44
*/
55
var ConcatSource = require("webpack-core/lib/ConcatSource");
6+
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
67

78
function wrapComment(str) {
89
if(str.indexOf("\n") < 0) return "/*! " + str + " */";
910
return "/*!\n * " + str.split("\n").join("\n * ") + "\n */";
1011
}
1112

1213
function BannerPlugin(banner, options) {
13-
if(!options) options = {};
14-
this.banner = options.raw ? banner : wrapComment(banner);
15-
this.entryOnly = options.entryOnly;
14+
this.options = options || {};
15+
this.banner = this.options.raw ? banner : wrapComment(banner);
1616
}
1717
module.exports = BannerPlugin;
18+
1819
BannerPlugin.prototype.apply = function(compiler) {
20+
var options = this.options;
1921
var banner = this.banner;
20-
var entryOnly = this.entryOnly;
22+
2123
compiler.plugin("compilation", function(compilation) {
2224
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
2325
chunks.forEach(function(chunk) {
24-
if(entryOnly && !chunk.initial) return;
25-
chunk.files.forEach(function(file) {
26+
if(options.entryOnly && !chunk.initial) return;
27+
chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).forEach(function(file) {
2628
compilation.assets[file] = new ConcatSource(banner, "\n", compilation.assets[file]);
2729
});
2830
});

‎lib/ExternalModuleFactoryDecorator.js‎

Lines changed: 0 additions & 85 deletions
This file was deleted.

‎lib/ExternalModuleFactoryPlugin.js‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
var ExternalModule = require("./ExternalModule");
6+
7+
function ExternalModuleFactoryPlugin(type, externals) {
8+
this.type = type;
9+
this.externals = externals;
10+
}
11+
module.exports = ExternalModuleFactoryPlugin;
12+
13+
ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
14+
var globalType = this.type;
15+
normalModuleFactory.plugin("factory", function(factory) {
16+
return function(data, callback) {
17+
var context = data.context;
18+
var dependency = data.dependency;
19+
function handleExternal(value, type, callback) {
20+
if(typeof type === "function") {
21+
callback = type;
22+
type = undefined;
23+
}
24+
if(value === false) return factory(data, callback);
25+
if(value === true) value = dependency.request;
26+
if(typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
27+
var idx = value.indexOf(" ");
28+
type = value.substr(0, idx);
29+
value = value.substr(idx + 1);
30+
}
31+
callback(null, new ExternalModule(value, type || globalType));
32+
return true;
33+
}
34+
(function handleExternals(externals, callback) {
35+
if(typeof externals === "string") {
36+
if(externals === dependency.request) {
37+
return handleExternal(dependency.request, callback);
38+
}
39+
} else if(Array.isArray(externals)) {
40+
var i = 0;
41+
(function next() {
42+
do {
43+
var async = true;
44+
if(i >= externals.length) return callback();
45+
handleExternals(externals[i++], function(err, module) {
46+
if(err) return callback(err);
47+
if(!module) {
48+
if(async) {
49+
async = false;
50+
return;
51+
}
52+
return next();
53+
}
54+
callback(null, module);
55+
});
56+
} while(!async);
57+
async = false;
58+
}());
59+
return;
60+
} else if(externals instanceof RegExp) {
61+
if(externals.test(dependency.request)) {
62+
return handleExternal(dependency.request, callback);
63+
}
64+
} else if(typeof externals === "function") {
65+
externals.call(null, context, dependency.request, function(err, value, type) {
66+
if(err) return callback(err);
67+
if(typeof value !== "undefined") {
68+
handleExternal(value, type, callback);
69+
} else {
70+
callback();
71+
}
72+
});
73+
return;
74+
} else if(typeof externals === "object" && Object.prototype.hasOwnProperty.call(externals, dependency.request)) {
75+
return handleExternal(externals[dependency.request], callback);
76+
}
77+
callback();
78+
}(this.externals, function(err, module) {
79+
if(err) return callback(err);
80+
if(!module) return handleExternal(false, callback);
81+
return callback(null, module);
82+
}));
83+
}.bind(this);
84+
}.bind(this));
85+
};

‎lib/ExternalsPlugin.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var ExternalModuleFactoryDecorator = require("./ExternalModuleFactoryDecorator");
5+
var ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
66

77
function ExternalsPlugin(type, externals) {
88
this.type = type;
@@ -11,6 +11,6 @@ function ExternalsPlugin(type, externals) {
1111
module.exports = ExternalsPlugin;
1212
ExternalsPlugin.prototype.apply = function(compiler) {
1313
compiler.plugin("compile", function(params) {
14-
params.normalModuleFactory = new ExternalModuleFactoryDecorator(params.normalModuleFactory, this.type, this.externals);
14+
params.normalModuleFactory.apply(new ExternalModuleFactoryPlugin(this.type, this.externals));
1515
}.bind(this));
16-
};
16+
};

0 commit comments

Comments
 (0)