This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +85
-0
lines changed Expand file tree Collapse file tree 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");
99var Chunk = require ( "webpack/lib/Chunk" ) ;
1010var OrderUndefinedError = require ( "./OrderUndefinedError" ) ;
1111var loaderUtils = require ( "loader-utils" ) ;
12+ var schemaTester = require ( './schema/validator' ) ;
1213
1314var NS = fs . realpathSync ( __dirname ) ;
1415
@@ -118,6 +119,8 @@ function ExtractTextPlugin(options) {
118119 }
119120 if ( isString ( options ) ) {
120121 options = { filename : options } ;
122+ } else {
123+ schemaTester ( options ) ;
121124 }
122125 this . filename = options . filename ;
123126 this . id = options . id != null ? options . id : ++ nextId ;
@@ -181,6 +184,8 @@ ExtractTextPlugin.prototype.extract = function(options) {
181184 }
182185 if ( Array . isArray ( options ) || isString ( options ) || typeof options . options === "object" || typeof options . query === 'object' ) {
183186 options = { loader : options } ;
187+ } else {
188+ schemaTester ( options ) ;
184189 }
185190 var loader = options . loader ;
186191 var before = options . fallbackLoader || [ ] ;
Original file line number Diff line number Diff line change 1515 "webpack-sources" : " ^0.1.0"
1616 },
1717 "devDependencies" : {
18+ "ajv" : " ^4.11.2" ,
1819 "codecov.io" : " ^0.1.2" ,
1920 "coveralls" : " ^2.11.2" ,
2021 "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() {
1010 } ) ;
1111 } ) ;
1212
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+
1333 context ( "specifying loader" , function ( ) {
1434 it ( "accepts a loader string" , function ( ) {
1535 ExtractTextPlugin . extract ( "css-loader" ) . should . deepEqual ( [
You can’t perform that action at this time.
0 commit comments