Skip to content

Commit ff78483

Browse files
committed
Merge branch 'master' into webpack-2
Conflicts: bin/webpack.js package.json
2 parents f4b9d5f + ac84ef7 commit ff78483

104 files changed

Lines changed: 1521 additions & 683 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintrc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"rules": {
66
"strict": 0,
77
"curly": 0,
8-
"eol-last": 0,
8+
"eol-last": 1,
99
"no-shadow": 0,
1010
"no-redeclare": 1,
1111
"no-extra-bind": 1,

‎bin/config-optimist.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ module.exports = function(optimist) {
4949

5050
.boolean("watch").alias("watch", "w").describe("watch")
5151

52+
.describe("watch-aggregate-timeout")
53+
54+
.describe("watch-poll")
55+
5256
.boolean("hot").alias("hot", "h").describe("hot")
5357

5458
.boolean("debug").describe("debug")

‎bin/convert-argv.js‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var path = require("path");
22
var fs = require("fs");
33
fs.existsSync = fs.existsSync || path.existsSync;
44
var resolve = require("enhanced-resolve");
5-
var interpret = require('interpret');
5+
var interpret = require("interpret");
66

77
module.exports = function(optimist, argv, convertOptions) {
88

@@ -73,18 +73,37 @@ module.exports = function(optimist, argv, convertOptions) {
7373
}
7474

7575
if(argv.context) {
76-
options.context = path.resolve(argv.context)
76+
options.context = path.resolve(argv.context);
7777
}
7878
if(!options.context) {
7979
options.context = process.cwd();
8080
}
8181

8282
if(argv["watch"]) {
83-
options.watch = true;
83+
if(options.watchDelay) {
84+
console.warn("watchDelay is deprecated: Use 'watch.aggregateTimeout' instead.");
85+
options.watch = options.watch || {};
86+
options.watch.aggregateTimeout = options.watchDelay;
87+
}
88+
options.doWatch = true;
8489
}
8590

8691
if(argv["watch-delay"]) {
87-
options.watchDelay = +argv["watch-delay"];
92+
options.watch = options.watch || {};
93+
options.watch.aggregateTimeout = +argv["watch-delay"];
94+
}
95+
96+
if(argv["watch-aggregate-timeout"]) {
97+
options.watch = options.watch || {};
98+
options.watch.aggregateTimeout = +argv["watch-aggregate-timeout"];
99+
}
100+
101+
if(argv["watch-poll"]) {
102+
options.watch = options.watch || {};
103+
if(typeof argv["watch-poll"] !== "boolean")
104+
options.watch.poll = +argv["watch-poll"];
105+
else
106+
options.watch.poll = true;
88107
}
89108

90109
function processOptions(options) {
@@ -97,7 +116,7 @@ module.exports = function(optimist, argv, convertOptions) {
97116
if(finalize) {
98117
finalize();
99118
}
100-
} else if(typeof argv[name] != "undefined") {
119+
} else if(typeof argv[name] !== "undefined") {
101120
if(init) {
102121
init();
103122
}
@@ -114,7 +133,7 @@ module.exports = function(optimist, argv, convertOptions) {
114133
if(i < 0) {
115134
return fn(null, content, idx);
116135
} else {
117-
return fn(content.substr(0, i), content.substr(i+1), idx);
136+
return fn(content.substr(0, i), content.substr(i + 1), idx);
118137
}
119138
}, init, finalize);
120139
}
@@ -283,11 +302,6 @@ module.exports = function(optimist, argv, convertOptions) {
283302
});
284303

285304
mapArgToBooleanInverse("cache");
286-
mapArgToBoolean("watch");
287-
288-
ifArg("watch-delay", function(value) {
289-
options.watchDelay = value;
290-
});
291305

292306
ifBooleanArg("hot", function() {
293307
ensureArray(options, "plugins");
@@ -464,7 +478,7 @@ module.exports = function(optimist, argv, convertOptions) {
464478
addTo("main", content);
465479
}
466480
} else {
467-
addTo(content.substr(0, i), content.substr(i+1));
481+
addTo(content.substr(0, i), content.substr(i + 1));
468482
}
469483
});
470484
}

‎bin/webpack.js‎

100755100644
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ var path = require("path");
88
// Local version replace global one
99
try {
1010
var localWebpack = require.resolve(path.join(process.cwd(), "node_modules", "webpack", "bin", "webpack.js"));
11-
if(__filename != localWebpack) {
11+
if(__filename !== localWebpack) {
1212
return require(localWebpack);
1313
}
1414
} catch(e) {}
15-
var fs = require("fs");
16-
var util = require("util");
1715
var optimist = require("optimist")
1816
.usage("webpack " + require("../package.json").version + "\n" +
19-
"Usage: http://webpack.github.io/docs/cli.html")
17+
"Usage: http://webpack.github.io/docs/cli.html");
2018

2119
require("./config-optimist")(optimist);
2220

@@ -59,7 +57,7 @@ function ifArg(name, fn, init) {
5957
if(Array.isArray(argv[name])) {
6058
if(init) init();
6159
argv[name].forEach(fn);
62-
} else if(typeof argv[name] != "undefined") {
60+
} else if(typeof argv[name] !== "undefined") {
6361
if(init) init();
6462
fn(argv[name], -1);
6563
}
@@ -145,16 +143,17 @@ var webpack = require("../lib/webpack.js");
145143

146144
Error.stackTrackLimit = 30;
147145
var lastHash = null;
148-
var compiler = webpack(options, function(err, stats) {
149-
if(!options.watch) {
146+
var compiler = webpack(options);
147+
function compilerCallback(err, stats) {
148+
if(!options.doWatch) {
150149
// Do not keep cache anymore
151150
compiler.purgeInputFileSystem();
152151
}
153152
if(err) {
154153
lastHash = null;
155154
console.error(err.stack || err);
156155
if(err.details) console.error(err.details);
157-
if(!options.watch) {
156+
if(!options.doWatch) {
158157
process.on("exit", function() {
159158
process.exit(1);
160159
});
@@ -167,9 +166,13 @@ var compiler = webpack(options, function(err, stats) {
167166
lastHash = stats.hash;
168167
process.stdout.write(stats.toString(outputOptions) + "\n");
169168
}
170-
if(!options.watch && stats.hasErrors()) {
169+
if(!options.doWatch && stats.hasErrors()) {
171170
process.on("exit", function() {
172171
process.exit(2);
173172
});
174173
}
175-
});
174+
}
175+
if(options.doWatch)
176+
compiler.watch(options.watch, compilerCallback);
177+
else
178+
compiler.run(compilerCallback);

‎examples/build-common.js‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,28 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var cp = require('child_process');
5+
var cp = require("child_process");
66
var tc = require("./template-common");
7-
var Stats = require("../lib/Stats");
8-
// var webpackGraph = require("webpack-graph");
97
var fs = require("fs");
10-
var path = require("path");
118

129
var extraArgs = "";
1310

14-
var targetArgs = global.NO_TARGET_ARGS?"":" ./example.js js/output.js";
15-
var displayReasons = global.NO_REASONS?"":" --display-reasons";
16-
cp.exec("node ../../bin/webpack.js"+displayReasons+" --display-chunks --display-modules --display-origins --output-public-path \"js/\" -p "+extraArgs+targetArgs, function (error, stdout, stderr) {
11+
var targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
12+
var displayReasons = global.NO_REASONS ? "" : " --display-reasons";
13+
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-modules --display-origins --output-public-path \"js/\" -p " + extraArgs + targetArgs, function (error, stdout, stderr) {
1714
if(stderr)
1815
console.log(stderr);
1916
if (error !== null)
2017
console.log(error);
2118
var readme = tc(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
22-
cp.exec("node ../../bin/webpack.js"+displayReasons+" --display-chunks --display-modules --display-origins --output-public-path \"js/\" --optimize-occurence-order --output-pathinfo "+extraArgs+targetArgs, function (error, stdout, stderr) {
19+
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-modules --display-origins --output-public-path \"js/\" --output-pathinfo " + extraArgs + targetArgs, function (error, stdout, stderr) {
2320
console.log(stdout);
2421
if(stderr)
2522
console.log(stderr);
2623
if (error !== null)
2724
console.log(error);
28-
// var stats = JSON.parse(stdout);
29-
// var formatedStats = Stats.jsonToString(stats, {
30-
// context: process.cwd(),
31-
// verbose: true
32-
// });
33-
// var filenameShortener = createFilenameShortener(process.cwd());
3425
readme = tc(readme, process.cwd(), stdout.replace(/[\r\n]*$/, ""));
3526
readme = readme.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
3627
fs.writeFile("README.md", readme, "utf-8", function() {});
37-
// fs.writeFile("graph.svg", webpackGraph(stats, {
38-
// nameShortener: filenameShortener,
39-
// width: 500,
40-
// height: 300
41-
// }), "utf-8", function() {});
4228
});
4329
});

0 commit comments

Comments
 (0)