@@ -17,7 +17,15 @@ import sh from 'shelljs'
17
17
18
18
sh . config . silent = true
19
19
20
- const makeSchema = ( schemaOptions , schemaExtension ) => {
20
+ const defaultSchemaOptions = {
21
+ rules : {
22
+ 'no-root-files-node-modules-nameclash' : true ,
23
+ 'loader-enforce-include-or-exclude' : false ,
24
+ 'loader-prefer-include' : false ,
25
+ } ,
26
+ }
27
+
28
+ function makeSchema ( schemaOptions , schemaExtension ) {
21
29
const resolveSchema = resolveSchemaFn ( schemaOptions )
22
30
const moduleSchema = moduleSchemaFn ( schemaOptions )
23
31
@@ -59,20 +67,10 @@ const makeSchema = (schemaOptions, schemaExtension) => {
59
67
return schemaExtension ? schema . concat ( schemaExtension ) : schema
60
68
}
61
69
62
- const defaultSchemaOptions = {
63
- rules : {
64
- 'no-root-files-node-modules-nameclash' : true ,
65
- 'loader-enforce-include-or-exclude' : false ,
66
- 'loader-prefer-include' : false ,
67
- } ,
68
- }
69
-
70
- // Easier consumability for require (default use case for non-transpiled webpack configs)
71
- module . exports = function validate ( config , options = { } ) {
70
+ function validate ( config , options ) {
72
71
const {
73
72
// Don't return the config object and throw on error, but just return the validation result
74
73
returnValidation, // bool
75
- quiet, // bool
76
74
schema : overrideSchema , // Don't take internal schema, but override with this one
77
75
schemaExtension, // Internal schema will be `Joi.concat`-ted with this schema if supplied
78
76
rules,
@@ -92,11 +90,36 @@ module.exports = function validate(config, options = {}) {
92
90
process . exit ( 1 )
93
91
}
94
92
93
+ return config
94
+ }
95
+
96
+ // Easier consumability for require (default use case for non-transpiled webpack configs)
97
+ function validateRoot ( config , options = { } ) {
98
+ const {
99
+ quiet,
100
+ } = options
101
+
102
+ let validationResult ,
103
+ multiValidationResults
104
+
105
+ if ( Array . isArray ( config ) ) {
106
+ multiValidationResults = [ ]
107
+ config . forEach ( ( cfg ) => {
108
+ multiValidationResults . push (
109
+ validate ( cfg , options )
110
+ )
111
+ } )
112
+ } else {
113
+ validationResult = validate ( config , options )
114
+ }
115
+
95
116
if ( ! quiet ) {
96
117
console . info ( chalk . green ( '[webpack-validator] Config is valid.' ) )
97
118
}
98
119
99
- return config
120
+ return validationResult || multiValidationResults
100
121
}
101
122
102
- module . exports . Joi = Joi
123
+ exports . validate = validate
124
+ exports . validateRoot = validateRoot
125
+ exports . Joi = Joi
0 commit comments