Skip to content

Commit

Permalink
Merge pull request #14813 from webpack/bugfix/pre-compiled-schema
Browse files Browse the repository at this point in the history
fix pre-compiled schema validation for Infinity and arrays
  • Loading branch information
sokra committed Nov 24, 2021
2 parents 0065223 + a26b3f8 commit cdd50a8
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 15 deletions.
11 changes: 9 additions & 2 deletions lib/util/create-schema-validation.js
Expand Up @@ -9,11 +9,18 @@ const memoize = require("./memoize");

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

const createSchemaValidation = (check = v => false, getSchema, options) => {
const createSchemaValidation = (check, getSchema, options) => {
getSchema = memoize(getSchema);
return value => {
if (!check(value)) {
if (check && !check(value)) {
getValidate()(getSchema(), value, options);
if (check) {
require("util").deprecate(
() => {},
"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
)();
}
}
};
};
Expand Down
10 changes: 9 additions & 1 deletion lib/webpack.js
Expand Up @@ -96,6 +96,9 @@ const createCompiler = rawOptions => {
* @returns {MultiCompiler} the multi compiler object
*/

const asArray = options =>
Array.isArray(options) ? Array.from(options) : [options];

const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
/**
* @param {WebpackOptions | (ReadonlyArray<WebpackOptions> & MultiCompilerOptions)} options options
Expand All @@ -104,8 +107,13 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
*/
(options, callback) => {
const create = () => {
if (!webpackOptionsSchemaCheck(options)) {
if (!asArray(options).every(webpackOptionsSchemaCheck)) {
getValidateSchema()(webpackOptionsSchema, options);
util.deprecate(
() => {},
"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
)();
}
/** @type {MultiCompiler|Compiler} */
let compiler;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -98,7 +98,7 @@
"style-loader": "^2.0.0",
"terser": "^5.7.0",
"toml": "^3.0.0",
"tooling": "webpack/tooling#v1.20.0",
"tooling": "webpack/tooling#v1.20.1",
"ts-loader": "^8.0.2",
"typescript": "^4.2.0-beta",
"url-loader": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion schemas/WebpackOptions.check.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion schemas/plugins/DllReferencePlugin.check.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion schemas/plugins/HashedModuleIdsPlugin.check.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schemas/plugins/ProgressPlugin.check.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schemas/plugins/asset/AssetParserOptions.check.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schemas/plugins/optimize/LimitChunkCountPlugin.check.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdd50a8

Please sign in to comment.