Skip to content

Commit cdd50a8

Browse files
authored
Merge pull request #14813 from webpack/bugfix/pre-compiled-schema
fix pre-compiled schema validation for Infinity and arrays
2 parents 0065223 + a26b3f8 commit cdd50a8

12 files changed

Lines changed: 30 additions & 15 deletions

lib/util/create-schema-validation.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ const memoize = require("./memoize");
99

1010
const getValidate = memoize(() => require("schema-utils").validate);
1111

12-
const createSchemaValidation = (check = v => false, getSchema, options) => {
12+
const createSchemaValidation = (check, getSchema, options) => {
1313
getSchema = memoize(getSchema);
1414
return value => {
15-
if (!check(value)) {
15+
if (check && !check(value)) {
1616
getValidate()(getSchema(), value, options);
17+
if (check) {
18+
require("util").deprecate(
19+
() => {},
20+
"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
21+
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
22+
)();
23+
}
1724
}
1825
};
1926
};

lib/webpack.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const createCompiler = rawOptions => {
9696
* @returns {MultiCompiler} the multi compiler object
9797
*/
9898

99+
const asArray = options =>
100+
Array.isArray(options) ? Array.from(options) : [options];
101+
99102
const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
100103
/**
101104
* @param {WebpackOptions | (ReadonlyArray<WebpackOptions> & MultiCompilerOptions)} options options
@@ -104,8 +107,13 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
104107
*/
105108
(options, callback) => {
106109
const create = () => {
107-
if (!webpackOptionsSchemaCheck(options)) {
110+
if (!asArray(options).every(webpackOptionsSchemaCheck)) {
108111
getValidateSchema()(webpackOptionsSchema, options);
112+
util.deprecate(
113+
() => {},
114+
"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
115+
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
116+
)();
109117
}
110118
/** @type {MultiCompiler|Compiler} */
111119
let compiler;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"style-loader": "^2.0.0",
9999
"terser": "^5.7.0",
100100
"toml": "^3.0.0",
101-
"tooling": "webpack/tooling#v1.20.0",
101+
"tooling": "webpack/tooling#v1.20.1",
102102
"ts-loader": "^8.0.2",
103103
"typescript": "^4.2.0-beta",
104104
"url-loader": "^4.1.0",

schemas/WebpackOptions.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/plugins/DllReferencePlugin.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/plugins/HashedModuleIdsPlugin.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/plugins/ProgressPlugin.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/plugins/asset/AssetParserOptions.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/plugins/optimize/AggressiveSplittingPlugin.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/plugins/optimize/LimitChunkCountPlugin.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)