Skip to content

Commit 29a1b54

Browse files
halfzebraTheLarkInn
authored andcommitted
Added better validation for entry in option schema (webpack#3567)
Added better validation for entry in option schema (webpack#3567) * Added better validation for entry in option schema * Fixed option validation schema * Improved error reporting for empty entry bundle * Added a test for empty entry bundle
1 parent 7296cbe commit 29a1b54

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

lib/WebpackOptionsValidationError.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ WebpackOptionsValidationError.formatValidationError = function formatValidationE
9595
var missingProperty = err.params.missingProperty.replace(/^\./, "");
9696
return dataPath + " misses the property '" + missingProperty + "'.\n" +
9797
getSchemaPartText(err.parentSchema, ["properties", missingProperty]);
98+
case "minItems":
9899
case "minLength":
99100
if(err.params.limit === 1)
100101
return dataPath + " should not be empty.";

schemas/webpackOptionsSchema.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,19 @@
3737
},
3838
"entry": {
3939
"description": "The entry point(s) of the compilation.",
40-
"anyOf": [
40+
"oneOf": [
4141
{
42+
"minProperties": 1,
4243
"additionalProperties": {
43-
"anyOf": [
44+
"oneOf": [
4445
{
4546
"description": "The string is resolved to a module which is loaded upon startup.",
4647
"minLength": 1,
4748
"type": "string"
4849
},
4950
{
50-
"allOf": [
51-
{
52-
"$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues"
53-
}
54-
],
55-
"description": "All modules are loaded upon startup. The last one is exported."
51+
"description": "All modules are loaded upon startup. The last one is exported.",
52+
"$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues"
5653
}
5754
]
5855
},

test/Validation.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ describe("Validation", function() {
3838
" * configuration.entry should be an array:",
3939
" [non-empty string]"
4040
]
41+
}, {
42+
name: "empty entry bundle array",
43+
config: {
44+
entry: {
45+
"bundle": []
46+
}
47+
},
48+
message: [
49+
" - configuration.entry should be one of these:",
50+
" object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]",
51+
" The entry point(s) of the compilation.",
52+
" Details:",
53+
" * configuration.entry['bundle'] should be a string.",
54+
" * configuration.entry['bundle'] should not be empty.",
55+
" * configuration.entry['bundle'] should be one of these:",
56+
" non-empty string | [non-empty string]",
57+
" * configuration.entry should be a string.",
58+
" * configuration.entry should be an array:",
59+
" [non-empty string]"
60+
]
4161
}, {
4262
name: "invalid instanceof",
4363
config: {

0 commit comments

Comments
 (0)