Skip to content

Commit fd4c004

Browse files
committed
use new style of passing watch options
1 parent 98663e7 commit fd4c004

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

bin/convert-argv.js

Lines changed: 8 additions & 7 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

@@ -68,18 +68,19 @@ module.exports = function(optimist, argv, convertOptions) {
6868
}
6969

7070
if(argv.context) {
71-
options.context = path.resolve(argv.context)
71+
options.context = path.resolve(argv.context);
7272
}
7373
if(!options.context) {
7474
options.context = process.cwd();
7575
}
7676

7777
if(argv["watch"]) {
78-
options.watch = true;
78+
options.doWatch = true;
7979
}
8080

8181
if(argv["watch-delay"]) {
82-
options.watchDelay = +argv["watch-delay"];
82+
options.watch = options.watch || {};
83+
options.watch.aggregateTimeout = +argv["watch-delay"];
8384
}
8485

8586
function processOptions(options) {
@@ -92,7 +93,7 @@ module.exports = function(optimist, argv, convertOptions) {
9293
if(finalize) {
9394
finalize();
9495
}
95-
} else if(typeof argv[name] != "undefined") {
96+
} else if(typeof argv[name] !== "undefined") {
9697
if(init) {
9798
init();
9899
}
@@ -109,7 +110,7 @@ module.exports = function(optimist, argv, convertOptions) {
109110
if(i < 0) {
110111
return fn(null, content, idx);
111112
} else {
112-
return fn(content.substr(0, i), content.substr(i+1), idx);
113+
return fn(content.substr(0, i), content.substr(i + 1), idx);
113114
}
114115
}, init, finalize);
115116
}
@@ -468,7 +469,7 @@ module.exports = function(optimist, argv, convertOptions) {
468469
addTo("main", content);
469470
}
470471
} else {
471-
addTo(content.substr(0, i), content.substr(i+1));
472+
addTo(content.substr(0, i), content.substr(i + 1));
472473
}
473474
});
474475
}

bin/webpack.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ try {
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,4 +166,8 @@ var compiler = webpack(options, function(err, stats) {
167166
lastHash = stats.hash;
168167
process.stdout.write(stats.toString(outputOptions) + "\n");
169168
}
170-
});
169+
}
170+
if(options.doWatch)
171+
compiler.watch(options.watch, compilerCallback);
172+
else
173+
compiler.run(compilerCallback);

0 commit comments

Comments
 (0)