Skip to content

Commit e054999

Browse files
committed
Merge branch 'next' into refactoring/plugin-system-all
2 parents 149d54d + d7b9437 commit e054999

45 files changed

Lines changed: 927 additions & 160 deletions

Some content is hidden

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

bin/convert-argv.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ module.exports = function(yargs, argv, convertOptions) {
100100
};
101101

102102
var requireConfig = function requireConfig(configPath) {
103-
var options = require(configPath);
103+
var options = (function WEBPACK_OPTIONS() {
104+
return require(configPath);
105+
})();
104106
options = prepareOptions(options, argv);
105107
return options;
106108
};

bin/webpack.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
var path = require("path");
88

9+
var ErrorHelpers = require("../lib/ErrorHelpers");
10+
911
// Local version replace global one
1012
try {
1113
var localWebpack = require.resolve(path.join(process.cwd(), "node_modules", "webpack", "bin", "webpack.js"));
@@ -150,6 +152,7 @@ yargs.options({
150152
// This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process).
151153
// To prevent this we use the yargs.parse API and exit the process normally
152154
yargs.parse(process.argv.slice(2), (err, argv, output) => {
155+
Error.stackTraceLimit = 30;
153156

154157
// arguments validation failed
155158
if(err && output) {
@@ -168,7 +171,27 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
168171
argv["display"] = "verbose";
169172
}
170173

171-
var options = require("./convert-argv")(yargs, argv);
174+
try {
175+
var options = require("./convert-argv")(yargs, argv);
176+
} catch(err) {
177+
if(err.name !== "ValidationError") {
178+
throw err;
179+
}
180+
181+
var stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message);
182+
var message = err.message + "\n" + stack;
183+
184+
if(argv.color) {
185+
console.error(
186+
`\u001b[1m\u001b[31m${message}\u001b[39m\u001b[22m`
187+
);
188+
} else {
189+
console.error(message);
190+
}
191+
192+
process.exitCode = 1;
193+
return;
194+
}
172195

173196
function ifArg(name, fn, init) {
174197
if(Array.isArray(argv[name])) {
@@ -328,7 +351,6 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
328351

329352
var webpack = require("../lib/webpack.js");
330353

331-
Error.stackTraceLimit = 30;
332354
var lastHash = null;
333355
var compiler;
334356
try {

examples/code-splitted-css-bundle/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ body {
7272
## Uncompressed
7373

7474
```
75-
Hash: eb83e18f883b3782ac4e
75+
Hash: 07cd62e8204ce12e5e90
7676
Version: webpack next
7777
Asset Size Chunks Chunk Names
7878
ce21cbdd9b894e6af794813eb3fdaf60.png 119 bytes [emitted]
@@ -112,7 +112,7 @@ Child extract-text-webpack-plugin ../../node_modules/extract-text-webpack-plugin
112112
## Minimized (uglify-js, no zip)
113113

114114
```
115-
Hash: 3d67c808fc684d446a10
115+
Hash: 875c8c7227c51a7a972d
116116
Version: webpack next
117117
Asset Size Chunks Chunk Names
118118
ce21cbdd9b894e6af794813eb3fdaf60.png 119 bytes [emitted]

examples/externals/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
var a = typeof exports === 'object' ? factory(require("add"), require("./math")["subtract"]) : factory(root["add"], root["subtract"]);
5959
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
6060
}
61-
})(this, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__2__) {
61+
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__2__) {
6262
```
6363
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
6464
@@ -190,7 +190,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
190190
Hash: ffa746601696f82316c5
191191
Version: webpack next
192192
Asset Size Chunks Chunk Names
193-
output.js 4.43 KiB 0 [emitted] main
193+
output.js 4.47 KiB 0 [emitted] main
194194
Entrypoint main = output.js
195195
chunk {0} output.js (main) 197 bytes [entry] [rendered]
196196
> main [0] ./example.js
@@ -208,7 +208,7 @@ chunk {0} output.js (main) 197 bytes [entry] [rendered]
208208
Hash: ffa746601696f82316c5
209209
Version: webpack next
210210
Asset Size Chunks Chunk Names
211-
output.js 1.02 KiB 0 [emitted] main
211+
output.js 1.05 KiB 0 [emitted] main
212212
Entrypoint main = output.js
213213
chunk {0} output.js (main) 197 bytes [entry] [rendered]
214214
> main [0] ./example.js

examples/harmony-library/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
exports["MyLibrary"] = factory();
2727
else
2828
root["MyLibrary"] = factory();
29-
})(this, function() {
29+
})(typeof self !== 'undefined' ? self : this, function() {
3030
```
3131
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
3232
@@ -140,7 +140,7 @@ function increment() {
140140
Hash: 3644f1adc4c521a71110
141141
Version: webpack next
142142
Asset Size Chunks Chunk Names
143-
MyLibrary.umd.js 3.63 KiB 0 [emitted] main
143+
MyLibrary.umd.js 3.66 KiB 0 [emitted] main
144144
Entrypoint main = MyLibrary.umd.js
145145
chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
146146
> main [0] ./example.js
@@ -155,7 +155,7 @@ chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
155155
Hash: 3644f1adc4c521a71110
156156
Version: webpack next
157157
Asset Size Chunks Chunk Names
158-
MyLibrary.umd.js 922 bytes 0 [emitted] main
158+
MyLibrary.umd.js 952 bytes 0 [emitted] main
159159
Entrypoint main = MyLibrary.umd.js
160160
chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
161161
> main [0] ./example.js

examples/multi-part-library/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
exports["alpha"] = factory();
4444
else
4545
root["MyLibrary"] = root["MyLibrary"] || {}, root["MyLibrary"]["alpha"] = factory();
46-
})(this, function() {
46+
})(typeof self !== 'undefined' ? self : this, function() {
4747
```
4848
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
4949
@@ -152,7 +152,7 @@ module.exports = "alpha";
152152
exports["beta"] = factory();
153153
else
154154
root["MyLibrary"] = root["MyLibrary"] || {}, root["MyLibrary"]["beta"] = factory();
155-
})(this, function() {
155+
})(typeof self !== 'undefined' ? self : this, function() {
156156
return /******/ (function(modules) { // webpackBootstrap
157157
/******/ // The module cache
158158
/******/ var installedModules = {};
@@ -249,8 +249,8 @@ module.exports = "beta";
249249
Hash: 17fa97a0dfa6b745377a
250250
Version: webpack next
251251
Asset Size Chunks Chunk Names
252-
MyLibrary.beta.js 3.24 KiB 0 [emitted] beta
253-
MyLibrary.alpha.js 3.24 KiB 1 [emitted] alpha
252+
MyLibrary.beta.js 3.28 KiB 0 [emitted] beta
253+
MyLibrary.alpha.js 3.27 KiB 1 [emitted] alpha
254254
Entrypoint alpha = MyLibrary.alpha.js
255255
Entrypoint beta = MyLibrary.beta.js
256256
chunk {0} MyLibrary.beta.js (beta) 24 bytes [entry] [rendered]
@@ -269,8 +269,8 @@ chunk {1} MyLibrary.alpha.js (alpha) 25 bytes [entry] [rendered]
269269
Hash: 17fa97a0dfa6b745377a
270270
Version: webpack next
271271
Asset Size Chunks Chunk Names
272-
MyLibrary.beta.js 825 bytes 0 [emitted] beta
273-
MyLibrary.alpha.js 827 bytes 1 [emitted] alpha
272+
MyLibrary.beta.js 855 bytes 0 [emitted] beta
273+
MyLibrary.alpha.js 857 bytes 1 [emitted] alpha
274274
Entrypoint alpha = MyLibrary.alpha.js
275275
Entrypoint beta = MyLibrary.beta.js
276276
chunk {0} MyLibrary.beta.js (beta) 24 bytes [entry] [rendered]

lib/BannerPlugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const ConcatSource = require("webpack-sources").ConcatSource;
99
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
1010
const Template = require("./Template");
1111

12+
const validateOptions = require("schema-utils");
13+
const schema = require("../schemas/plugins/BannerPlugin.json");
14+
1215
const wrapComment = (str) => {
1316
if(!str.includes("\n")) return Template.toComment(str);
1417
return `/*!\n * ${str.replace(/\*\//g, "* /").split("\n").join("\n * ")}\n */`;
@@ -18,6 +21,9 @@ class BannerPlugin {
1821
constructor(options) {
1922
if(arguments.length > 1)
2023
throw new Error("BannerPlugin only takes one argument (pass an options object)");
24+
25+
validateOptions(schema, options, "Banner Plugin");
26+
2127
if(typeof options === "string")
2228
options = {
2329
banner: options

lib/DllPlugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ const DllEntryPlugin = require("./DllEntryPlugin");
88
const LibManifestPlugin = require("./LibManifestPlugin");
99
const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
1010

11+
const validateOptions = require("schema-utils");
12+
const schema = require("../schemas/plugins/DllPlugin.json");
13+
1114
class DllPlugin {
1215
constructor(options) {
16+
validateOptions(schema, options, "Dll Plugin");
1317
this.options = options;
1418
}
1519

lib/DllReferencePlugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
1010
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
1111
const NullFactory = require("./NullFactory");
1212

13+
const validateOptions = require("schema-utils");
14+
const schema = require("../schemas/plugins/DllReferencePlugin.json");
15+
1316
class DllReferencePlugin {
1417
constructor(options) {
18+
validateOptions(schema, options, "Dll Reference Plugin");
1519
this.options = options;
1620
}
1721

lib/ErrorHelpers.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@
66

77
const loaderFlag = "LOADER_EXECUTION";
88

9-
exports.cutOffLoaderExecution = (stack) => {
9+
const webpackOptionsFlag = "WEBPACK_OPTIONS";
10+
11+
exports.cutOffByFlag = (stack, flag) => {
1012
stack = stack.split("\n");
1113
for(let i = 0; i < stack.length; i++)
12-
if(stack[i].indexOf(loaderFlag) >= 0)
14+
if(stack[i].indexOf(flag) >= 0)
1315
stack.length = i;
1416
return stack.join("\n");
1517
};
1618

19+
exports.cutOffLoaderExecution = (stack) => exports.cutOffByFlag(stack, loaderFlag);
20+
21+
exports.cutOffWebpackOptinos = (stack) => exports.cutOffByFlag(stack, webpackOptionsFlag);
22+
23+
exports.cutOffMultilineMessage = (stack, message) => {
24+
stack = stack.split("\n");
25+
message = message.split("\n");
26+
27+
return stack.reduce((acc, line, idx) => line.indexOf(message[idx]) < 0 ? acc.concat(line) : acc, []).join("\n");
28+
};
29+
1730
exports.cutOffMessage = (stack, message) => {
1831
const nextLine = stack.indexOf("\n");
1932
if(nextLine === -1) {
@@ -29,3 +42,9 @@ exports.cleanUp = (stack, message) => {
2942
stack = exports.cutOffMessage(stack, message);
3043
return stack;
3144
};
45+
46+
exports.cleanUpWebpackOptions = (stack, message) => {
47+
stack = exports.cutOffWebpackOptinos(stack);
48+
stack = exports.cutOffMultilineMessage(stack, message);
49+
return stack;
50+
};

0 commit comments

Comments
 (0)