Skip to content

Commit 9870165

Browse files
authored
Merge pull request webpack#6008 from EugeneHlushko/bugfix-issue-6003
Lookup the provided plugins on the options, throw for invalid arguments.
2 parents aa212a6 + 89ef8e0 commit 9870165

File tree

2 files changed

+142
-2
lines changed

2 files changed

+142
-2
lines changed

schemas/webpackOptionsSchema.json

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
{
22
"additionalProperties": false,
33
"definitions": {
4+
"common.pluginFunction": {
5+
"description": "Function acting as plugin",
6+
"instanceof": "Function",
7+
"properties": {
8+
"apply": {
9+
"description": "The run point of the plugin, required method.",
10+
"instanceof": "Function"
11+
}
12+
},
13+
"additionalProperties": true,
14+
"required": [
15+
"apply"
16+
]
17+
},
18+
"common.pluginObject": {
19+
"description": "Plugin instance",
20+
"type": "object",
21+
"properties": {
22+
"apply": {
23+
"description": "The run point of the plugin, required method.",
24+
"instanceof": "Function"
25+
}
26+
},
27+
"additionalProperties": true,
28+
"required": [
29+
"apply"
30+
]
31+
},
432
"common.arrayOfStringOrStringArrayValues": {
533
"items": {
634
"description": "string or array of strings",
@@ -613,7 +641,18 @@
613641
},
614642
"plugins": {
615643
"description": "Plugins for the resolver",
616-
"type": "array"
644+
"type": "array",
645+
"items": {
646+
"description": "Plugin of type object or instanceof Function",
647+
"anyOf": [
648+
{
649+
"$ref": "#/definitions/common.pluginObject"
650+
},
651+
{
652+
"$ref": "#/definitions/common.pluginFunction"
653+
}
654+
]
655+
}
617656
},
618657
"resolver": {
619658
"description": "Custom resolver"
@@ -1286,7 +1325,18 @@
12861325
},
12871326
"plugins": {
12881327
"description": "Add additional plugins to the compiler.",
1289-
"type": "array"
1328+
"type": "array",
1329+
"items": {
1330+
"description": "Plugin of type object or instanceof Function",
1331+
"anyOf": [
1332+
{
1333+
"$ref": "#/definitions/common.pluginObject"
1334+
},
1335+
{
1336+
"$ref": "#/definitions/common.pluginFunction"
1337+
}
1338+
]
1339+
}
12901340
},
12911341
"profile": {
12921342
"description": "Capture timing information for each module.",

test/Validation.test.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,96 @@ describe("Validation", () => {
255255
" - configuration.stats should be one of these:"
256256
);
257257
}
258+
}, {
259+
name: "Invalid plugin provided: bool",
260+
config: {
261+
entry: "foo.js",
262+
plugins: [
263+
false
264+
]
265+
},
266+
message: [
267+
" - configuration.plugins[0] should be one of these:",
268+
" object { apply, ... } | function",
269+
" -> Plugin of type object or instanceof Function",
270+
" Details:",
271+
" * configuration.plugins[0] should be an object.",
272+
" -> Plugin instance",
273+
" * configuration.plugins[0] should be an instance of function",
274+
" -> Function acting as plugin"
275+
]
276+
}, {
277+
name: "Invalid plugin provided: array",
278+
config: {
279+
entry: "foo.js",
280+
plugins: [
281+
[]
282+
]
283+
},
284+
message: [
285+
" - configuration.plugins[0] should be one of these:",
286+
" object { apply, ... } | function",
287+
" -> Plugin of type object or instanceof Function",
288+
" Details:",
289+
" * configuration.plugins[0] should be an object.",
290+
" -> Plugin instance",
291+
" * configuration.plugins[0] should be an instance of function",
292+
" -> Function acting as plugin"
293+
]
294+
}, {
295+
name: "Invalid plugin provided: string",
296+
config: {
297+
entry: "foo.js",
298+
plugins: ["abc123"]
299+
},
300+
message: [
301+
" - configuration.plugins[0] should be one of these:",
302+
" object { apply, ... } | function",
303+
" -> Plugin of type object or instanceof Function",
304+
" Details:",
305+
" * configuration.plugins[0] should be an object.",
306+
" -> Plugin instance",
307+
" * configuration.plugins[0] should be an instance of function",
308+
" -> Function acting as plugin"
309+
]
310+
}, {
311+
name: "Invalid plugin provided: int",
312+
config: {
313+
entry: "foo.js",
314+
plugins: [
315+
12
316+
]
317+
},
318+
message: [
319+
" - configuration.plugins[0] should be one of these:",
320+
" object { apply, ... } | function",
321+
" -> Plugin of type object or instanceof Function",
322+
" Details:",
323+
" * configuration.plugins[0] should be an object.",
324+
" -> Plugin instance",
325+
" * configuration.plugins[0] should be an instance of function",
326+
" -> Function acting as plugin"
327+
]
328+
}, {
329+
name: "Invalid plugin provided: object without apply function",
330+
config: {
331+
entry: "foo.js",
332+
plugins: [{}]
333+
},
334+
message: [
335+
" - configuration.plugins[0] should be one of these:",
336+
" object { apply, ... } | function",
337+
" -> Plugin of type object or instanceof Function",
338+
" Details:",
339+
" * configuration.plugins[0] misses the property 'apply'.",
340+
" function",
341+
" -> The run point of the plugin, required method.",
342+
" * configuration.plugins[0] misses the property 'apply'.",
343+
" function",
344+
" -> The run point of the plugin, required method.",
345+
" * configuration.plugins[0] should be an instance of function",
346+
" -> Function acting as plugin"
347+
]
258348
}];
259349

260350
testCases.forEach((testCase) => {

0 commit comments

Comments
 (0)