Skip to content

Commit ac61996

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature/validate-plugin-options
Conflicts: schemas/webpackOptionsSchema.json
2 parents 41c24d1 + dd47437 commit ac61996

15 files changed

Lines changed: 1732 additions & 1224 deletions

‎examples/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
[multiple-entry-points-commons-chunk-css-bundle](multiple-entry-points-commons-chunk-css-bundle)
2323

24-
[names-chunks](names-chunks) example demonstrating merging of chunks with named chunks
24+
[named-chunks](named-chunks) example demonstrating merging of chunks with named chunks
2525

2626
[two-explicit-vendor-chunks](two-explicit-vendor-chunks)
2727

‎lib/Compilation.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ class Compilation extends Tapable {
14251425
}
14261426

14271427
createChildCompiler(name, outputOptions, plugins) {
1428-
var idx = (this.childrenCounters[name] || 0);
1428+
const idx = (this.childrenCounters[name] || 0);
14291429
this.childrenCounters[name] = idx + 1;
14301430
return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins);
14311431
}

‎lib/DllModuleFactory.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
"use strict";
66

7-
var Tapable = require("tapable");
8-
var DllModule = require("./DllModule");
7+
const Tapable = require("tapable");
8+
const DllModule = require("./DllModule");
99

1010
class DllModuleFactory extends Tapable {
1111
constructor() {

‎lib/ExternalsPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
var ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
7+
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
88

99
class ExternalsPlugin {
1010
constructor(type, externals) {

‎lib/FlagDependencyUsagePlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FlagDependencyUsagePlugin {
3030
else if(usedExports === true)
3131
module.usedExports = true;
3232
else if(Array.isArray(usedExports)) {
33-
var old = module.usedExports ? module.usedExports.length : -1;
33+
const old = module.usedExports ? module.usedExports.length : -1;
3434
module.usedExports = addToSet(module.usedExports || [], usedExports);
3535
if(module.usedExports.length === old)
3636
return;

‎lib/OptionsDefaulter.js‎

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

77
function getProperty(obj, name) {
88
name = name.split(".");
9-
for(var i = 0; i < name.length - 1; i++) {
9+
for(let i = 0; i < name.length - 1; i++) {
1010
obj = obj[name[i]];
1111
if(typeof obj !== "object" || !obj) return;
1212
}
@@ -15,7 +15,7 @@ function getProperty(obj, name) {
1515

1616
function setProperty(obj, name, value) {
1717
name = name.split(".");
18-
for(var i = 0; i < name.length - 1; i++) {
18+
for(let i = 0; i < name.length - 1; i++) {
1919
if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
2020
if(!obj[name[i]]) obj[name[i]] = {};
2121
obj = obj[name[i]];

‎lib/WebpackOptionsValidationError.js‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ const getSchemaPartText = (schemaPart, additionalPath) => {
3535
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
3636
let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
3737
if(schemaPart.description)
38-
schemaText += `\n${schemaPart.description}`;
38+
schemaText += `\n-> ${schemaPart.description}`;
3939
return schemaText;
4040
};
4141

42+
const getSchemaPartDescription = schemaPart => {
43+
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
44+
if(schemaPart.description)
45+
return `\n-> ${schemaPart.description}`;
46+
return "";
47+
};
48+
49+
const filterChildren = children => {
50+
return children.filter(err => err.keyword !== "anyOf" && err.keyword !== "allOf" && err.keyword !== "oneOf");
51+
};
52+
4253
const indent = (str, prefix, firstLine) => {
4354
if(firstLine) {
4455
return prefix + str.replace(/\n(?!$)/g, "\n" + prefix);
@@ -143,8 +154,16 @@ class WebpackOptionsValidationError extends WebpackError {
143154
return baseMessage;
144155
} else if(err.keyword === "oneOf" || err.keyword === "anyOf") {
145156
if(err.children && err.children.length > 0) {
157+
if(err.schema.length === 1) {
158+
const lastChild = err.children[err.children.length - 1];
159+
const remainingChildren = err.children.slice(0, err.children.length - 1);
160+
return WebpackOptionsValidationError.formatValidationError(Object.assign({}, lastChild, {
161+
children: remainingChildren,
162+
parentSchema: Object.assign({}, err.parentSchema, lastChild.parentSchema)
163+
}));
164+
}
146165
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` +
147-
`Details:\n${err.children.map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
166+
`Details:\n${filterChildren(err.children).map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
148167
}
149168
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`;
150169

@@ -158,29 +177,33 @@ class WebpackOptionsValidationError extends WebpackError {
158177
} else if(err.keyword === "type") {
159178
switch(err.params.type) {
160179
case "object":
161-
return `${dataPath} should be an object.`;
180+
return `${dataPath} should be an object.${getSchemaPartDescription(err.parentSchema)}`;
162181
case "string":
163-
return `${dataPath} should be a string.`;
182+
return `${dataPath} should be a string.${getSchemaPartDescription(err.parentSchema)}`;
164183
case "boolean":
165-
return `${dataPath} should be a boolean.`;
184+
return `${dataPath} should be a boolean.${getSchemaPartDescription(err.parentSchema)}`;
166185
case "number":
167-
return `${dataPath} should be a number.`;
186+
return `${dataPath} should be a number.${getSchemaPartDescription(err.parentSchema)}`;
168187
case "array":
169188
return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`;
170189
}
171190
return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`;
172191
} else if(err.keyword === "instanceof") {
173-
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`;
192+
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}`;
174193
} else if(err.keyword === "required") {
175194
const missingProperty = err.params.missingProperty.replace(/^\./, "");
176195
return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ["properties", missingProperty])}`;
177-
} else if(err.keyword === "minLength" || err.keyword === "minItems") {
196+
} else if(err.keyword === "minimum") {
197+
return `${dataPath} ${err.message}.${getSchemaPartDescription(err.parentSchema)}`;
198+
} else if(err.keyword === "uniqueItems") {
199+
return `${dataPath} should not contain the item '${err.data[err.params.i]}' twice.${getSchemaPartDescription(err.parentSchema)}`;
200+
} else if(err.keyword === "minLength" || err.keyword === "minItems" || err.keyword === "minProperties") {
178201
if(err.params.limit === 1)
179-
return `${dataPath} should not be empty.`;
202+
return `${dataPath} should not be empty.${getSchemaPartDescription(err.parentSchema)}`;
180203
else
181-
return `${dataPath} ${err.message}`;
204+
return `${dataPath} ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
182205
} else if(err.keyword === "absolutePath") {
183-
const baseMessage = `${dataPath}: ${err.message}`;
206+
const baseMessage = `${dataPath}: ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
184207
if(dataPath === "configuration.output.filename") {
185208
return `${baseMessage}\n` +
186209
"Please use output.path to specify absolute path and output.filename for the file name.";

‎lib/dependencies/HarmonyDetectionParserPlugin.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency
99
module.exports = class HarmonyDetectionParserPlugin {
1010
apply(parser) {
1111
parser.plugin("program", (ast) => {
12-
var isHarmony = ast.body.some(statement => {
12+
const isHarmony = ast.body.some(statement => {
1313
return /^(Import|Export).*Declaration$/.test(statement.type);
1414
});
1515
if(isHarmony) {
@@ -32,7 +32,7 @@ module.exports = class HarmonyDetectionParserPlugin {
3232
module.exportsArgument = "__webpack_exports__";
3333
}
3434
});
35-
var nonHarmonyIdentifiers = ["define", "exports"];
35+
const nonHarmonyIdentifiers = ["define", "exports"];
3636
nonHarmonyIdentifiers.forEach(identifer => {
3737
parser.plugin(`evaluate typeof ${identifer}`, nullInHarmony);
3838
parser.plugin(`typeof ${identifer}`, skipInHarmony);

‎lib/dependencies/HarmonyImportDependency.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author Tobias Koppers @sokra
44
*/
55
"use strict";
6-
var ModuleDependency = require("./ModuleDependency");
6+
const ModuleDependency = require("./ModuleDependency");
77

88
class HarmonyImportDependency extends ModuleDependency {
99
constructor(request, importedVar, range) {

‎lib/dependencies/LocalModulesHelpers.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const lookup = (parent, mod) => {
1414
segs = mod.split("/");
1515
path.pop();
1616

17-
for(var i = 0; i < segs.length; i++) {
18-
var seg = segs[i];
17+
for(let i = 0; i < segs.length; i++) {
18+
const seg = segs[i];
1919
if(seg === "..") path.pop();
2020
else if(seg !== ".") path.push(seg);
2121
}
@@ -25,7 +25,7 @@ const lookup = (parent, mod) => {
2525

2626
LocalModulesHelpers.addLocalModule = (state, name) => {
2727
if(!state.localModules) state.localModules = [];
28-
var m = new LocalModule(state.module, name, state.localModules.length);
28+
const m = new LocalModule(state.module, name, state.localModules.length);
2929
state.localModules.push(m);
3030
return m;
3131
};
@@ -36,7 +36,7 @@ LocalModulesHelpers.getLocalModule = (state, name, namedModule) => {
3636
// resolve dependency name relative to the defining named module
3737
name = lookup(namedModule, name);
3838
}
39-
for(var i = 0; i < state.localModules.length; i++) {
39+
for(let i = 0; i < state.localModules.length; i++) {
4040
if(state.localModules[i].name === name)
4141
return state.localModules[i];
4242
}

0 commit comments

Comments
 (0)