22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Gajus Kuizinas @gajus
44*/
5- var webpackOptionsSchema = require ( "../schemas/webpackOptionsSchema.json" ) ;
65var Ajv = require ( "ajv" ) ;
76var ajv = new Ajv ( {
87 errorDataPath : "configuration" ,
98 allErrors : true ,
109 verbose : true
1110} ) ;
1211require ( '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 ;
0 commit comments