Skip to content

Commit 7add543

Browse files
committed
Merge branch 'master' into SpaceK33z-fix-schema-instanceof
2 parents 9158378 + c7de73e commit 7add543

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

bin/convert-argv.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ fs.existsSync = fs.existsSync || path.existsSync;
44
var resolve = require("enhanced-resolve");
55
var interpret = require("interpret");
66
var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
7-
var validateWebpackOptions = require("../lib/validateWebpackOptions");
87

98
module.exports = function(yargs, argv, convertOptions) {
109

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Gajus Kuizinas @gajus
44
*/
5-
var webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
65
var Ajv = require("ajv");
76
var ajv = new Ajv({
87
errorDataPath: "configuration",
98
allErrors: true,
109
verbose: true
1110
});
1211
require('ajv-keywords')(ajv);
13-
var validate = ajv.compile(webpackOptionsSchema);
1412

15-
function validateWebpackOptions(options) {
13+
function validateSchema(schema, options) {
1614
if(Array.isArray(options)) {
17-
var errors = options.map(validateObject);
15+
var errors = options.map(validateObject.bind(this, schema));
1816
errors.forEach(function(list, idx) {
1917
list.forEach(function applyPrefix(err) {
2018
err.dataPath = "[" + idx + "]" + err.dataPath;
@@ -27,11 +25,12 @@ function validateWebpackOptions(options) {
2725
return arr.concat(items);
2826
}, []);
2927
} else {
30-
return validateObject(options);
28+
return validateObject(schema, options);
3129
}
3230
}
3331

34-
function validateObject(options) {
32+
function validateObject(schema, options) {
33+
var validate = ajv.compile(schema);
3534
var valid = validate(options);
3635
return valid ? [] : filterErrors(validate.errors);
3736
}
@@ -61,4 +60,4 @@ function filterErrors(errors) {
6160
return newErrors;
6261
}
6362

64-
module.exports = validateWebpackOptions;
63+
module.exports = validateSchema;

lib/webpack.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ var MultiCompiler = require("./MultiCompiler");
77
var NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
88
var WebpackOptionsApply = require("./WebpackOptionsApply");
99
var WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
10-
var validateWebpackOptions = require("./validateWebpackOptions");
10+
var validateSchema = require("./validateSchema");
1111
var WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
12+
var webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
1213

1314
function webpack(options, callback) {
14-
var webpackOptionsValidationErrors = validateWebpackOptions(options);
15+
var webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
1516
if(webpackOptionsValidationErrors.length) {
1617
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
1718
}
@@ -52,7 +53,9 @@ webpack.WebpackOptionsApply = WebpackOptionsApply;
5253
webpack.Compiler = Compiler;
5354
webpack.MultiCompiler = MultiCompiler;
5455
webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin;
55-
webpack.validate = validateWebpackOptions;
56+
webpack.validate = validateSchema.bind(this, webpackOptionsSchema);
57+
webpack.validateSchema = validateSchema;
58+
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
5659

5760
function exportPlugins(exports, path, plugins) {
5861
plugins.forEach(function(name) {

0 commit comments

Comments
 (0)