This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -9,7 +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/valid ' ) ;
12+ var schemaTester = require ( './schema/validator ' ) ;
1313
1414var NS = fs . realpathSync ( __dirname ) ;
1515
@@ -105,7 +105,6 @@ function getOrder(a, b) {
105105}
106106
107107function ExtractTextPlugin ( options ) {
108- schemaTester ( options ) ;
109108 if ( arguments . length > 1 ) {
110109 throw new Error ( "Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " +
111110 "object *or* the name of the result file.\n" +
@@ -120,6 +119,8 @@ function ExtractTextPlugin(options) {
120119 }
121120 if ( isString ( options ) ) {
122121 options = { filename : options } ;
122+ } else {
123+ schemaTester ( options ) ;
123124 }
124125 this . filename = options . filename ;
125126 this . id = options . id != null ? options . id : ++ nextId ;
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 ( "Your ExtractTextPlugin config is not correct. Please double check." ) ;
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 ( "throws if an incorrect config is passed in" , function ( ) {
15+ should . throws ( function ( ) {
16+ ExtractTextPlugin . extract ( [ 'style-loader' , '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 ( "does not throw if a filename is specified" , function ( ) {
27+ should . doesNotThrow ( function ( ) {
28+ ExtractTextPlugin . extract ( "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