webpack 4.1.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,319 +1,316 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Gajus Kuizinas @gajus
4
- */
5
- "use strict";
6
-
7
- const WebpackError = require("./WebpackError");
8
- const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
9
-
10
- const getSchemaPart = (path, parents, additionalPath) => {
11
- parents = parents || 0;
12
- path = path.split("/");
13
- path = path.slice(0, path.length - parents);
14
- if (additionalPath) {
15
- additionalPath = additionalPath.split("/");
16
- path = path.concat(additionalPath);
17
- }
18
- let schemaPart = webpackOptionsSchema;
19
- for (let i = 1; i < path.length; i++) {
20
- const inner = schemaPart[path[i]];
21
- if (inner) schemaPart = inner;
22
- }
23
- return schemaPart;
24
- };
25
-
26
- const getSchemaPartText = (schemaPart, additionalPath) => {
27
- if (additionalPath) {
28
- for (let i = 0; i < additionalPath.length; i++) {
29
- const inner = schemaPart[additionalPath[i]];
30
- if (inner) schemaPart = inner;
31
- }
32
- }
33
- while (schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
34
- let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
35
- if (schemaPart.description) schemaText += `\n-> ${schemaPart.description}`;
36
- return schemaText;
37
- };
38
-
39
- const getSchemaPartDescription = schemaPart => {
40
- while (schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
41
- if (schemaPart.description) return `\n-> ${schemaPart.description}`;
42
- return "";
43
- };
44
-
45
- const filterChildren = children => {
46
- return children.filter(
47
- err =>
48
- err.keyword !== "anyOf" &&
49
- err.keyword !== "allOf" &&
50
- err.keyword !== "oneOf"
51
- );
52
- };
53
-
54
- const indent = (str, prefix, firstLine) => {
55
- if (firstLine) {
56
- return prefix + str.replace(/\n(?!$)/g, "\n" + prefix);
57
- } else {
58
- return str.replace(/\n(?!$)/g, `\n${prefix}`);
59
- }
60
- };
61
-
62
- class WebpackOptionsValidationError extends WebpackError {
63
- constructor(validationErrors) {
64
- super();
65
-
66
- this.name = "WebpackOptionsValidationError";
67
- this.message =
68
- "Invalid configuration object. " +
69
- "Webpack has been initialised using a configuration object that does not match the API schema.\n" +
70
- validationErrors
71
- .map(
72
- err =>
73
- " - " +
74
- indent(
75
- WebpackOptionsValidationError.formatValidationError(err),
76
- " ",
77
- false
78
- )
79
- )
80
- .join("\n");
81
- this.validationErrors = validationErrors;
82
-
83
- Error.captureStackTrace(this, this.constructor);
84
- }
85
-
86
- static formatSchema(schema, prevSchemas) {
87
- prevSchemas = prevSchemas || [];
88
-
89
- const formatInnerSchema = (innerSchema, addSelf) => {
90
- if (!addSelf)
91
- return WebpackOptionsValidationError.formatSchema(
92
- innerSchema,
93
- prevSchemas
94
- );
95
- if (prevSchemas.includes(innerSchema)) return "(recursive)";
96
- return WebpackOptionsValidationError.formatSchema(
97
- innerSchema,
98
- prevSchemas.concat(schema)
99
- );
100
- };
101
-
102
- if (schema.type === "string") {
103
- if (schema.minLength === 1) return "non-empty string";
104
- else if (schema.minLength > 1)
105
- return `string (min length ${schema.minLength})`;
106
- return "string";
107
- } else if (schema.type === "boolean") {
108
- return "boolean";
109
- } else if (schema.type === "number") {
110
- return "number";
111
- } else if (schema.type === "object") {
112
- if (schema.properties) {
113
- const required = schema.required || [];
114
- return `object { ${Object.keys(schema.properties)
115
- .map(property => {
116
- if (!required.includes(property)) return property + "?";
117
- return property;
118
- })
119
- .concat(schema.additionalProperties ? ["..."] : [])
120
- .join(", ")} }`;
121
- }
122
- if (schema.additionalProperties) {
123
- return `object { <key>: ${formatInnerSchema(
124
- schema.additionalProperties
125
- )} }`;
126
- }
127
- return "object";
128
- } else if (schema.type === "array") {
129
- return `[${formatInnerSchema(schema.items)}]`;
130
- }
131
-
132
- switch (schema.instanceof) {
133
- case "Function":
134
- return "function";
135
- case "RegExp":
136
- return "RegExp";
137
- }
138
- if (schema.$ref) return formatInnerSchema(getSchemaPart(schema.$ref), true);
139
- if (schema.allOf) return schema.allOf.map(formatInnerSchema).join(" & ");
140
- if (schema.oneOf) return schema.oneOf.map(formatInnerSchema).join(" | ");
141
- if (schema.anyOf) return schema.anyOf.map(formatInnerSchema).join(" | ");
142
- if (schema.enum)
143
- return schema.enum.map(item => JSON.stringify(item)).join(" | ");
144
- return JSON.stringify(schema, 0, 2);
145
- }
146
-
147
- static formatValidationError(err) {
148
- const dataPath = `configuration${err.dataPath}`;
149
- if (err.keyword === "additionalProperties") {
150
- const baseMessage = `${dataPath} has an unknown property '${
151
- err.params.additionalProperty
152
- }'. These properties are valid:\n${getSchemaPartText(err.parentSchema)}`;
153
- if (!err.dataPath) {
154
- switch (err.params.additionalProperty) {
155
- case "debug":
156
- return (
157
- `${baseMessage}\n` +
158
- "The 'debug' property was removed in webpack 2.\n" +
159
- "Loaders should be updated to allow passing this option via loader options in module.rules.\n" +
160
- "Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:\n" +
161
- "plugins: [\n" +
162
- " new webpack.LoaderOptionsPlugin({\n" +
163
- " debug: true\n" +
164
- " })\n" +
165
- "]"
166
- );
167
- }
168
- return (
169
- baseMessage +
170
- "\n" +
171
- "For typos: please correct them.\n" +
172
- "For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.\n" +
173
- " Loaders should be updated to allow passing options via loader options in module.rules.\n" +
174
- " Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:\n" +
175
- " plugins: [\n" +
176
- " new webpack.LoaderOptionsPlugin({\n" +
177
- " // test: /\\.xxx$/, // may apply this only for some modules\n" +
178
- " options: {\n" +
179
- ` ${err.params.additionalProperty}: ...\n` +
180
- " }\n" +
181
- " })\n" +
182
- " ]"
183
- );
184
- }
185
- return baseMessage;
186
- } else if (err.keyword === "oneOf" || err.keyword === "anyOf") {
187
- if (err.children && err.children.length > 0) {
188
- if (err.schema.length === 1) {
189
- const lastChild = err.children[err.children.length - 1];
190
- const remainingChildren = err.children.slice(
191
- 0,
192
- err.children.length - 1
193
- );
194
- return WebpackOptionsValidationError.formatValidationError(
195
- Object.assign({}, lastChild, {
196
- children: remainingChildren,
197
- parentSchema: Object.assign(
198
- {},
199
- err.parentSchema,
200
- lastChild.parentSchema
201
- )
202
- })
203
- );
204
- }
205
- return (
206
- `${dataPath} should be one of these:\n${getSchemaPartText(
207
- err.parentSchema
208
- )}\n` +
209
- `Details:\n${filterChildren(err.children)
210
- .map(
211
- err =>
212
- " * " +
213
- indent(
214
- WebpackOptionsValidationError.formatValidationError(err),
215
- " ",
216
- false
217
- )
218
- )
219
- .join("\n")}`
220
- );
221
- }
222
- return `${dataPath} should be one of these:\n${getSchemaPartText(
223
- err.parentSchema
224
- )}`;
225
- } else if (err.keyword === "enum") {
226
- if (
227
- err.parentSchema &&
228
- err.parentSchema.enum &&
229
- err.parentSchema.enum.length === 1
230
- ) {
231
- return `${dataPath} should be ${getSchemaPartText(err.parentSchema)}`;
232
- }
233
- return `${dataPath} should be one of these:\n${getSchemaPartText(
234
- err.parentSchema
235
- )}`;
236
- } else if (err.keyword === "allOf") {
237
- return `${dataPath} should be:\n${getSchemaPartText(err.parentSchema)}`;
238
- } else if (err.keyword === "type") {
239
- switch (err.params.type) {
240
- case "object":
241
- return `${dataPath} should be an object.${getSchemaPartDescription(
242
- err.parentSchema
243
- )}`;
244
- case "string":
245
- return `${dataPath} should be a string.${getSchemaPartDescription(
246
- err.parentSchema
247
- )}`;
248
- case "boolean":
249
- return `${dataPath} should be a boolean.${getSchemaPartDescription(
250
- err.parentSchema
251
- )}`;
252
- case "number":
253
- return `${dataPath} should be a number.${getSchemaPartDescription(
254
- err.parentSchema
255
- )}`;
256
- case "array":
257
- return `${dataPath} should be an array:\n${getSchemaPartText(
258
- err.parentSchema
259
- )}`;
260
- }
261
- return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(
262
- err.parentSchema
263
- )}`;
264
- } else if (err.keyword === "instanceof") {
265
- return `${dataPath} should be an instance of ${getSchemaPartText(
266
- err.parentSchema
267
- )}`;
268
- } else if (err.keyword === "required") {
269
- const missingProperty = err.params.missingProperty.replace(/^\./, "");
270
- return `${dataPath} misses the property '${
271
- missingProperty
272
- }'.\n${getSchemaPartText(err.parentSchema, [
273
- "properties",
274
- missingProperty
275
- ])}`;
276
- } else if (err.keyword === "minimum") {
277
- return `${dataPath} ${err.message}.${getSchemaPartDescription(
278
- err.parentSchema
279
- )}`;
280
- } else if (err.keyword === "uniqueItems") {
281
- return `${dataPath} should not contain the item '${
282
- err.data[err.params.i]
283
- }' twice.${getSchemaPartDescription(err.parentSchema)}`;
284
- } else if (
285
- err.keyword === "minLength" ||
286
- err.keyword === "minItems" ||
287
- err.keyword === "minProperties"
288
- ) {
289
- if (err.params.limit === 1)
290
- return `${dataPath} should not be empty.${getSchemaPartDescription(
291
- err.parentSchema
292
- )}`;
293
- else
294
- return `${dataPath} ${err.message}${getSchemaPartDescription(
295
- err.parentSchema
296
- )}`;
297
- } else if (err.keyword === "absolutePath") {
298
- const baseMessage = `${dataPath}: ${
299
- err.message
300
- }${getSchemaPartDescription(err.parentSchema)}`;
301
- if (dataPath === "configuration.output.filename") {
302
- return (
303
- `${baseMessage}\n` +
304
- "Please use output.path to specify absolute path and output.filename for the file name."
305
- );
306
- }
307
- return baseMessage;
308
- } else {
309
- // eslint-disable-line no-fallthrough
310
- return `${dataPath} ${err.message} (${JSON.stringify(
311
- err,
312
- 0,
313
- 2
314
- )}).\n${getSchemaPartText(err.parentSchema)}`;
315
- }
316
- }
317
- }
318
-
319
- module.exports = WebpackOptionsValidationError;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Gajus Kuizinas @gajus
4
+ */
5
+ "use strict";
6
+
7
+ const WebpackError = require("./WebpackError");
8
+ const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
9
+
10
+ const getSchemaPart = (path, parents, additionalPath) => {
11
+ parents = parents || 0;
12
+ path = path.split("/");
13
+ path = path.slice(0, path.length - parents);
14
+ if (additionalPath) {
15
+ additionalPath = additionalPath.split("/");
16
+ path = path.concat(additionalPath);
17
+ }
18
+ let schemaPart = webpackOptionsSchema;
19
+ for (let i = 1; i < path.length; i++) {
20
+ const inner = schemaPart[path[i]];
21
+ if (inner) schemaPart = inner;
22
+ }
23
+ return schemaPart;
24
+ };
25
+
26
+ const getSchemaPartText = (schemaPart, additionalPath) => {
27
+ if (additionalPath) {
28
+ for (let i = 0; i < additionalPath.length; i++) {
29
+ const inner = schemaPart[additionalPath[i]];
30
+ if (inner) schemaPart = inner;
31
+ }
32
+ }
33
+ while (schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
34
+ let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
35
+ if (schemaPart.description) schemaText += `\n-> ${schemaPart.description}`;
36
+ return schemaText;
37
+ };
38
+
39
+ const getSchemaPartDescription = schemaPart => {
40
+ while (schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
41
+ if (schemaPart.description) return `\n-> ${schemaPart.description}`;
42
+ return "";
43
+ };
44
+
45
+ const filterChildren = children => {
46
+ return children.filter(
47
+ err =>
48
+ err.keyword !== "anyOf" &&
49
+ err.keyword !== "allOf" &&
50
+ err.keyword !== "oneOf"
51
+ );
52
+ };
53
+
54
+ const indent = (str, prefix, firstLine) => {
55
+ if (firstLine) {
56
+ return prefix + str.replace(/\n(?!$)/g, "\n" + prefix);
57
+ } else {
58
+ return str.replace(/\n(?!$)/g, `\n${prefix}`);
59
+ }
60
+ };
61
+
62
+ class WebpackOptionsValidationError extends WebpackError {
63
+ constructor(validationErrors) {
64
+ super();
65
+
66
+ this.name = "WebpackOptionsValidationError";
67
+ this.message =
68
+ "Invalid configuration object. " +
69
+ "Webpack has been initialised using a configuration object that does not match the API schema.\n" +
70
+ validationErrors
71
+ .map(
72
+ err =>
73
+ " - " +
74
+ indent(
75
+ WebpackOptionsValidationError.formatValidationError(err),
76
+ " ",
77
+ false
78
+ )
79
+ )
80
+ .join("\n");
81
+ this.validationErrors = validationErrors;
82
+
83
+ Error.captureStackTrace(this, this.constructor);
84
+ }
85
+
86
+ static formatSchema(schema, prevSchemas) {
87
+ prevSchemas = prevSchemas || [];
88
+
89
+ const formatInnerSchema = (innerSchema, addSelf) => {
90
+ if (!addSelf)
91
+ return WebpackOptionsValidationError.formatSchema(
92
+ innerSchema,
93
+ prevSchemas
94
+ );
95
+ if (prevSchemas.includes(innerSchema)) return "(recursive)";
96
+ return WebpackOptionsValidationError.formatSchema(
97
+ innerSchema,
98
+ prevSchemas.concat(schema)
99
+ );
100
+ };
101
+
102
+ if (schema.type === "string") {
103
+ if (schema.minLength === 1) return "non-empty string";
104
+ else if (schema.minLength > 1)
105
+ return `string (min length ${schema.minLength})`;
106
+ return "string";
107
+ } else if (schema.type === "boolean") {
108
+ return "boolean";
109
+ } else if (schema.type === "number") {
110
+ return "number";
111
+ } else if (schema.type === "object") {
112
+ if (schema.properties) {
113
+ const required = schema.required || [];
114
+ return `object { ${Object.keys(schema.properties)
115
+ .map(property => {
116
+ if (!required.includes(property)) return property + "?";
117
+ return property;
118
+ })
119
+ .concat(schema.additionalProperties ? [""] : [])
120
+ .join(", ")} }`;
121
+ }
122
+ if (schema.additionalProperties) {
123
+ return `object { <key>: ${formatInnerSchema(
124
+ schema.additionalProperties
125
+ )} }`;
126
+ }
127
+ return "object";
128
+ } else if (schema.type === "array") {
129
+ return `[${formatInnerSchema(schema.items)}]`;
130
+ }
131
+
132
+ switch (schema.instanceof) {
133
+ case "Function":
134
+ return "function";
135
+ case "RegExp":
136
+ return "RegExp";
137
+ }
138
+ if (schema.$ref) return formatInnerSchema(getSchemaPart(schema.$ref), true);
139
+ if (schema.allOf) return schema.allOf.map(formatInnerSchema).join(" & ");
140
+ if (schema.oneOf) return schema.oneOf.map(formatInnerSchema).join(" | ");
141
+ if (schema.anyOf) return schema.anyOf.map(formatInnerSchema).join(" | ");
142
+ if (schema.enum)
143
+ return schema.enum.map(item => JSON.stringify(item)).join(" | ");
144
+ return JSON.stringify(schema, 0, 2);
145
+ }
146
+
147
+ static formatValidationError(err) {
148
+ const dataPath = `configuration${err.dataPath}`;
149
+ if (err.keyword === "additionalProperties") {
150
+ const baseMessage = `${dataPath} has an unknown property '${
151
+ err.params.additionalProperty
152
+ }'. These properties are valid:\n${getSchemaPartText(err.parentSchema)}`;
153
+ if (!err.dataPath) {
154
+ switch (err.params.additionalProperty) {
155
+ case "debug":
156
+ return (
157
+ `${baseMessage}\n` +
158
+ "The 'debug' property was removed in webpack 2.0.0.\n" +
159
+ "Loaders should be updated to allow passing this option via loader options in module.rules.\n" +
160
+ "Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:\n" +
161
+ "plugins: [\n" +
162
+ " new webpack.LoaderOptionsPlugin({\n" +
163
+ " debug: true\n" +
164
+ " })\n" +
165
+ "]"
166
+ );
167
+ }
168
+ return (
169
+ `${baseMessage}\n` +
170
+ "For typos: please correct them.\n" +
171
+ "For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.\n" +
172
+ " Loaders should be updated to allow passing options via loader options in module.rules.\n" +
173
+ " Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:\n" +
174
+ " plugins: [\n" +
175
+ " new webpack.LoaderOptionsPlugin({\n" +
176
+ " // test: /\\.xxx$/, // may apply this only for some modules\n" +
177
+ " options: {\n" +
178
+ ` ${err.params.additionalProperty}: …\n` +
179
+ " }\n" +
180
+ " })\n" +
181
+ " ]"
182
+ );
183
+ }
184
+ return baseMessage;
185
+ } else if (err.keyword === "oneOf" || err.keyword === "anyOf") {
186
+ if (err.children && err.children.length > 0) {
187
+ if (err.schema.length === 1) {
188
+ const lastChild = err.children[err.children.length - 1];
189
+ const remainingChildren = err.children.slice(
190
+ 0,
191
+ err.children.length - 1
192
+ );
193
+ return WebpackOptionsValidationError.formatValidationError(
194
+ Object.assign({}, lastChild, {
195
+ children: remainingChildren,
196
+ parentSchema: Object.assign(
197
+ {},
198
+ err.parentSchema,
199
+ lastChild.parentSchema
200
+ )
201
+ })
202
+ );
203
+ }
204
+ return (
205
+ `${dataPath} should be one of these:\n${getSchemaPartText(
206
+ err.parentSchema
207
+ )}\n` +
208
+ `Details:\n${filterChildren(err.children)
209
+ .map(
210
+ err =>
211
+ " * " +
212
+ indent(
213
+ WebpackOptionsValidationError.formatValidationError(err),
214
+ " ",
215
+ false
216
+ )
217
+ )
218
+ .join("\n")}`
219
+ );
220
+ }
221
+ return `${dataPath} should be one of these:\n${getSchemaPartText(
222
+ err.parentSchema
223
+ )}`;
224
+ } else if (err.keyword === "enum") {
225
+ if (
226
+ err.parentSchema &&
227
+ err.parentSchema.enum &&
228
+ err.parentSchema.enum.length === 1
229
+ ) {
230
+ return `${dataPath} should be ${getSchemaPartText(err.parentSchema)}`;
231
+ }
232
+ return `${dataPath} should be one of these:\n${getSchemaPartText(
233
+ err.parentSchema
234
+ )}`;
235
+ } else if (err.keyword === "allOf") {
236
+ return `${dataPath} should be:\n${getSchemaPartText(err.parentSchema)}`;
237
+ } else if (err.keyword === "type") {
238
+ switch (err.params.type) {
239
+ case "object":
240
+ return `${dataPath} should be an object.${getSchemaPartDescription(
241
+ err.parentSchema
242
+ )}`;
243
+ case "string":
244
+ return `${dataPath} should be a string.${getSchemaPartDescription(
245
+ err.parentSchema
246
+ )}`;
247
+ case "boolean":
248
+ return `${dataPath} should be a boolean.${getSchemaPartDescription(
249
+ err.parentSchema
250
+ )}`;
251
+ case "number":
252
+ return `${dataPath} should be a number.${getSchemaPartDescription(
253
+ err.parentSchema
254
+ )}`;
255
+ case "array":
256
+ return `${dataPath} should be an array:\n${getSchemaPartText(
257
+ err.parentSchema
258
+ )}`;
259
+ }
260
+ return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(
261
+ err.parentSchema
262
+ )}`;
263
+ } else if (err.keyword === "instanceof") {
264
+ return `${dataPath} should be an instance of ${getSchemaPartText(
265
+ err.parentSchema
266
+ )}`;
267
+ } else if (err.keyword === "required") {
268
+ const missingProperty = err.params.missingProperty.replace(/^\./, "");
269
+ return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(
270
+ err.parentSchema,
271
+ ["properties", missingProperty]
272
+ )}`;
273
+ } else if (err.keyword === "minimum") {
274
+ return `${dataPath} ${err.message}.${getSchemaPartDescription(
275
+ err.parentSchema
276
+ )}`;
277
+ } else if (err.keyword === "uniqueItems") {
278
+ return `${dataPath} should not contain the item '${
279
+ err.data[err.params.i]
280
+ }' twice.${getSchemaPartDescription(err.parentSchema)}`;
281
+ } else if (
282
+ err.keyword === "minLength" ||
283
+ err.keyword === "minItems" ||
284
+ err.keyword === "minProperties"
285
+ ) {
286
+ if (err.params.limit === 1)
287
+ return `${dataPath} should not be empty.${getSchemaPartDescription(
288
+ err.parentSchema
289
+ )}`;
290
+ else
291
+ return `${dataPath} ${err.message}${getSchemaPartDescription(
292
+ err.parentSchema
293
+ )}`;
294
+ } else if (err.keyword === "absolutePath") {
295
+ const baseMessage = `${dataPath}: ${
296
+ err.message
297
+ }${getSchemaPartDescription(err.parentSchema)}`;
298
+ if (dataPath === "configuration.output.filename") {
299
+ return (
300
+ `${baseMessage}\n` +
301
+ "Please use output.path to specify absolute path and output.filename for the file name."
302
+ );
303
+ }
304
+ return baseMessage;
305
+ } else {
306
+ // eslint-disable-line no-fallthrough
307
+ return `${dataPath} ${err.message} (${JSON.stringify(
308
+ err,
309
+ 0,
310
+ 2
311
+ )}).\n${getSchemaPartText(err.parentSchema)}`;
312
+ }
313
+ }
314
+ }
315
+
316
+ module.exports = WebpackOptionsValidationError;