File tree 6 files changed +85
-0
lines changed
6 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ var ExtractedModule = require("./ExtractedModule");
9
9
var Chunk = require ( "webpack/lib/Chunk" ) ;
10
10
var OrderUndefinedError = require ( "./OrderUndefinedError" ) ;
11
11
var loaderUtils = require ( "loader-utils" ) ;
12
+ var schemaTester = require ( './schema/validator' ) ;
12
13
13
14
var NS = fs . realpathSync ( __dirname ) ;
14
15
@@ -118,6 +119,8 @@ function ExtractTextPlugin(options) {
118
119
}
119
120
if ( isString ( options ) ) {
120
121
options = { filename : options } ;
122
+ } else {
123
+ schemaTester ( options ) ;
121
124
}
122
125
this . filename = options . filename ;
123
126
this . id = options . id != null ? options . id : ++ nextId ;
@@ -181,6 +184,8 @@ ExtractTextPlugin.prototype.extract = function(options) {
181
184
}
182
185
if ( Array . isArray ( options ) || isString ( options ) || typeof options . options === "object" || typeof options . query === 'object' ) {
183
186
options = { loader : options } ;
187
+ } else {
188
+ schemaTester ( options ) ;
184
189
}
185
190
var loader = options . loader ;
186
191
var before = options . fallbackLoader || [ ] ;
Original file line number Diff line number Diff line change 15
15
"webpack-sources" : " ^0.1.0"
16
16
},
17
17
"devDependencies" : {
18
+ "ajv" : " ^4.11.2" ,
18
19
"codecov.io" : " ^0.1.2" ,
19
20
"coveralls" : " ^2.11.2" ,
20
21
"css-loader" : " ^0.26.1" ,
Original file line number Diff line number Diff line change
1
+ {
2
+ "$schema" : " http://json-schema.org/draft-04/schema#" ,
3
+ "type" : " object" ,
4
+ "additionalProperties" : false ,
5
+ "properties" : {
6
+ "allChunks" : {
7
+ "description" : " " ,
8
+ "type" : " boolean"
9
+ },
10
+ "disable" : {
11
+ "description" : " " ,
12
+ "type" : " boolean"
13
+ },
14
+ "fallbackLoader" : {
15
+ "description" : " A loader that webpack can fall back to if the original one fails." ,
16
+ "modes" : {
17
+ "type" : " string" ,
18
+ "type" : " object" ,
19
+ "type" : " array"
20
+ }
21
+ },
22
+ "filename" : {
23
+ "description" : " The filename and path that ExtractTextPlugin will extract to" ,
24
+ "type" : " string"
25
+ },
26
+ "loader" : {
27
+ "description" : " The loader that ExtractTextPlugin will attempt to load through." ,
28
+ "modes" : {
29
+ "type" : " string" ,
30
+ "type" : " object" ,
31
+ "type" : " array"
32
+ }
33
+ },
34
+ "publicPath" : {
35
+ "description" : " " ,
36
+ "type" : " string"
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "allChunks" : { "type" : " boolean" },
3
+ "disable" : { "type" : " boolean" },
4
+ "fallbackLoader" : { "type" : " string" },
5
+ "filename" : { "type" : " string" },
6
+ "loader" : { "type" : " string" },
7
+ "publicPath" : { "type" : " string" }
8
+ }
Original file line number Diff line number Diff line change
1
+ var Ajv = require ( 'ajv' ) ;
2
+ var ajv = new Ajv ( { allErrors : true } ) ;
3
+ var json = require ( './schema.json' ) ;
4
+
5
+ module . exports = function validate ( data ) {
6
+ var validSchema = ajv . compile ( json ) ;
7
+ var valid = validSchema ( data ) ;
8
+
9
+ if ( ! valid ) {
10
+ throw new Error ( ajv . errorsText ( ) ) ;
11
+ }
12
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,26 @@ describe("ExtractTextPlugin.extract()", function() {
10
10
} ) ;
11
11
} ) ;
12
12
13
+ context ( "json schema validation" , function ( ) {
14
+ it ( "does not throw if a filename is specified" , function ( ) {
15
+ should . doesNotThrow ( function ( ) {
16
+ ExtractTextPlugin . extract ( "file.css" ) ;
17
+ } ) ;
18
+ } ) ;
19
+
20
+ it ( "does not throw if a correct config object is passed in" , function ( ) {
21
+ should . doesNotThrow ( function ( ) {
22
+ ExtractTextPlugin . extract ( { loader : 'css-loader' } ) ;
23
+ } ) ;
24
+ } ) ;
25
+
26
+ it ( "throws if an incorrect config is passed in" , function ( ) {
27
+ should . throws ( function ( ) {
28
+ ExtractTextPlugin . extract ( { style : 'file.css' } ) ;
29
+ } ) ;
30
+ } ) ;
31
+ } ) ;
32
+
13
33
context ( "specifying loader" , function ( ) {
14
34
it ( "accepts a loader string" , function ( ) {
15
35
ExtractTextPlugin . extract ( "css-loader" ) . should . deepEqual ( [
You can’t perform that action at this time.
0 commit comments