1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { validate } = require("schema-utils");
|
9 |
|
10 |
|
11 | const DID_YOU_MEAN = {
|
12 | rules: "module.rules",
|
13 | loaders: "module.rules or module.rules.*.use",
|
14 | query: "module.rules.*.options (BREAKING CHANGE since webpack 5)",
|
15 | noParse: "module.noParse",
|
16 | filename: "output.filename or module.rules.*.generator.filename",
|
17 | file: "output.filename",
|
18 | chunkFilename: "output.chunkFilename",
|
19 | chunkfilename: "output.chunkFilename",
|
20 | ecmaVersion:
|
21 | "output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
22 | ecmaversion:
|
23 | "output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
24 | ecma:
|
25 | "output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
26 | path: "output.path",
|
27 | pathinfo: "output.pathinfo",
|
28 | pathInfo: "output.pathinfo",
|
29 | jsonpFunction: "output.chunkLoadingGlobal (BREAKING CHANGE since webpack 5)",
|
30 | chunkCallbackName:
|
31 | "output.chunkLoadingGlobal (BREAKING CHANGE since webpack 5)",
|
32 | jsonpScriptType: "output.scriptType (BREAKING CHANGE since webpack 5)",
|
33 | hotUpdateFunction: "output.hotUpdateGlobal (BREAKING CHANGE since webpack 5)",
|
34 | splitChunks: "optimization.splitChunks",
|
35 | immutablePaths: "snapshot.immutablePaths",
|
36 | managedPaths: "snapshot.managedPaths",
|
37 | maxModules: "stats.modulesSpace (BREAKING CHANGE since webpack 5)",
|
38 | hashedModuleIds:
|
39 | 'optimization.moduleIds: "hashed" (BREAKING CHANGE since webpack 5)',
|
40 | namedChunks:
|
41 | 'optimization.chunkIds: "named" (BREAKING CHANGE since webpack 5)',
|
42 | namedModules:
|
43 | 'optimization.moduleIds: "named" (BREAKING CHANGE since webpack 5)',
|
44 | occurrenceOrder:
|
45 | 'optimization.chunkIds: "size" and optimization.moduleIds: "size" (BREAKING CHANGE since webpack 5)',
|
46 | automaticNamePrefix:
|
47 | "optimization.splitChunks.[cacheGroups.*].idHint (BREAKING CHANGE since webpack 5)",
|
48 | noEmitOnErrors:
|
49 | "optimization.emitOnErrors (BREAKING CHANGE since webpack 5: logic is inverted to avoid negative flags)",
|
50 | Buffer:
|
51 | "to use the ProvidePlugin to process the Buffer variable to modules as polyfill\n" +
|
52 | "BREAKING CHANGE: webpack 5 no longer provided Node.js polyfills by default.\n" +
|
53 | "Note: if you are using 'node.Buffer: false', you can just remove that as this is the default behavior now.\n" +
|
54 | "To provide a polyfill to modules use:\n" +
|
55 | 'new ProvidePlugin({ Buffer: ["buffer", "Buffer"] }) and npm install buffer.',
|
56 | process:
|
57 | "to use the ProvidePlugin to process the process variable to modules as polyfill\n" +
|
58 | "BREAKING CHANGE: webpack 5 no longer provided Node.js polyfills by default.\n" +
|
59 | "Note: if you are using 'node.process: false', you can just remove that as this is the default behavior now.\n" +
|
60 | "To provide a polyfill to modules use:\n" +
|
61 | 'new ProvidePlugin({ process: "process" }) and npm install buffer.'
|
62 | };
|
63 |
|
64 | const REMOVED = {
|
65 | concord:
|
66 | "BREAKING CHANGE: resolve.concord has been removed and is no longer avaiable.",
|
67 | devtoolLineToLine:
|
68 | "BREAKING CHANGE: output.devtoolLineToLine has been removed and is no longer avaiable."
|
69 | };
|
70 |
|
71 |
|
72 | const validateSchema = (schema, options) => {
|
73 | validate(schema, options, {
|
74 | name: "Webpack",
|
75 | postFormatter: (formattedError, error) => {
|
76 | const children = error.children;
|
77 | if (
|
78 | children &&
|
79 | children.some(
|
80 | child =>
|
81 | child.keyword === "absolutePath" &&
|
82 | child.dataPath === ".output.filename"
|
83 | )
|
84 | ) {
|
85 | return `${formattedError}\nPlease use output.path to specify absolute path and output.filename for the file name.`;
|
86 | }
|
87 |
|
88 | if (
|
89 | children &&
|
90 | children.some(
|
91 | child => child.keyword === "pattern" && child.dataPath === ".devtool"
|
92 | )
|
93 | ) {
|
94 | return (
|
95 | `${formattedError}\n` +
|
96 | "BREAKING CHANGE since webpack 5: The devtool option is more strict.\n" +
|
97 | "Please strictly follow the order of the keywords in the pattern."
|
98 | );
|
99 | }
|
100 |
|
101 | if (error.keyword === "additionalProperties") {
|
102 | const params = (error.params);
|
103 | if (
|
104 | Object.prototype.hasOwnProperty.call(
|
105 | DID_YOU_MEAN,
|
106 | params.additionalProperty
|
107 | )
|
108 | ) {
|
109 | return `${formattedError}\nDid you mean ${
|
110 | DID_YOU_MEAN[params.additionalProperty]
|
111 | }?`;
|
112 | }
|
113 |
|
114 | if (
|
115 | Object.prototype.hasOwnProperty.call(
|
116 | REMOVED,
|
117 | params.additionalProperty
|
118 | )
|
119 | ) {
|
120 | return `${formattedError}\n${REMOVED[params.additionalProperty]}?`;
|
121 | }
|
122 |
|
123 | if (!error.dataPath) {
|
124 | if (params.additionalProperty === "debug") {
|
125 | return (
|
126 | `${formattedError}\n` +
|
127 | "The 'debug' property was removed in webpack 2.0.0.\n" +
|
128 | "Loaders should be updated to allow passing this option via loader options in module.rules.\n" +
|
129 | "Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:\n" +
|
130 | "plugins: [\n" +
|
131 | " new webpack.LoaderOptionsPlugin({\n" +
|
132 | " debug: true\n" +
|
133 | " })\n" +
|
134 | "]"
|
135 | );
|
136 | }
|
137 |
|
138 | if (params.additionalProperty) {
|
139 | return (
|
140 | `${formattedError}\n` +
|
141 | "For typos: please correct them.\n" +
|
142 | "For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.\n" +
|
143 | " Loaders should be updated to allow passing options via loader options in module.rules.\n" +
|
144 | " Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:\n" +
|
145 | " plugins: [\n" +
|
146 | " new webpack.LoaderOptionsPlugin({\n" +
|
147 | " // test: /\\.xxx$/, // may apply this only for some modules\n" +
|
148 | " options: {\n" +
|
149 | ` ${params.additionalProperty}: …\n` +
|
150 | " }\n" +
|
151 | " })\n" +
|
152 | " ]"
|
153 | );
|
154 | }
|
155 | }
|
156 | }
|
157 |
|
158 | return formattedError;
|
159 | }
|
160 | });
|
161 | };
|
162 | module.exports = validateSchema;
|