Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit dfeb347

Browse files
evilebottnawimichael-ciniawsky
authored andcommitted
fix: validation schema (schema-utils) (#527)
1 parent d0e88d0 commit dfeb347

File tree

7 files changed

+46
-48
lines changed

7 files changed

+46
-48
lines changed

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ var ExtractedModule = require("./ExtractedModule");
99
var Chunk = require("webpack/lib/Chunk");
1010
var OrderUndefinedError = require("./OrderUndefinedError");
1111
var loaderUtils = require("loader-utils");
12-
var schemaTester = require('./schema/validator');
13-
var loaderSchema = require('./schema/loader-schema');
14-
var pluginSchema = require('./schema/plugin-schema.json');
12+
var validateOptions = require('schema-utils');
1513

1614
var NS = fs.realpathSync(__dirname);
1715

@@ -122,7 +120,7 @@ function ExtractTextPlugin(options) {
122120
if(isString(options)) {
123121
options = { filename: options };
124122
} else {
125-
schemaTester(pluginSchema, options);
123+
validateOptions('./schema/plugin.json', options, 'Extract Text Plugin');
126124
}
127125
this.filename = options.filename;
128126
this.id = options.id != null ? options.id : ++nextId;
@@ -201,7 +199,7 @@ ExtractTextPlugin.prototype.extract = function(options) {
201199
if(Array.isArray(options) || isString(options) || typeof options.options === "object" || typeof options.query === 'object') {
202200
options = { loader: options };
203201
} else {
204-
schemaTester(loaderSchema, options);
202+
validateOptions('./schema/loader.json', options, 'Extract Text Plugin (Loader)');
205203
}
206204
var loader = options.use ||  options.loader;
207205
var before = options.fallback || options.fallbackLoader || [];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"webpack": "^2.2.0"
1919
},
2020
"dependencies": {
21-
"ajv": "^4.11.2",
21+
"schema-utils": "^0.3.0",
2222
"async": "^2.1.2",
2323
"loader-utils": "^1.0.2",
2424
"webpack-sources": "^0.1.0"

schema/loader-schema.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

schema/loader.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "object",
3+
"additionalProperties": false,
4+
"properties": {
5+
"allChunks": {
6+
"type": "boolean"
7+
},
8+
"disable": {
9+
"type": "boolean"
10+
},
11+
"omit": {
12+
"type": "boolean"
13+
},
14+
"remove": {
15+
"type": "boolean"
16+
},
17+
"fallback": {
18+
"type": ["string", "array", "object"]
19+
},
20+
"filename": {
21+
"type": "string"
22+
},
23+
"use": {
24+
"type": ["string", "array", "object"]
25+
},
26+
"publicPath": {
27+
"type": "string"
28+
},
29+
"fallbackLoader": {
30+
"type": ["string", "array", "object"]
31+
},
32+
"loader": {
33+
"type": ["string", "array", "object"]
34+
}
35+
}
36+
}

schema/plugin-schema.json renamed to schema/plugin.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"$schema": "http://json-schema.org/draft-04/schema#",
32
"type": "object",
43
"additionalProperties": false,
54
"properties": {
@@ -14,16 +13,13 @@
1413
"fallback": {
1514
"description": "A loader that webpack can fall back to if the original one fails.",
1615
"modes": {
17-
"type": "string",
18-
"type": "object",
19-
"type": "array"
16+
"type": ["string", "object", "array"]
2017
}
2118
},
2219
"filename": {
2320
"description": "The filename and path that ExtractTextPlugin will extract to",
2421
"modes": {
25-
"type": "string",
26-
"type": "function"
22+
"type": ["string", "function"]
2723
}
2824
},
2925
"ignoreOrder": {
@@ -33,9 +29,7 @@
3329
"loader": {
3430
"description": "The loader that ExtractTextPlugin will attempt to load through.",
3531
"modes": {
36-
"type": "string",
37-
"type": "object",
38-
"type": "array"
32+
"type": ["string", "object", "array"]
3933
}
4034
},
4135
"publicPath": {

schema/validator.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/extract.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe("ExtractTextPlugin.extract()", function() {
2929
ExtractTextPlugin.extract({style: 'file.css'});
3030
},
3131
function(err) {
32-
return err.message === 'data[\'style\'] should NOT have additional properties';
32+
return err.message === 'Validation Error\n\n' +
33+
'Extract Text Plugin (Loader) Invalid Options\n\n' +
34+
'options[\'style\'] should NOT have additional properties\n';
3335
}
3436
);
3537
});

0 commit comments

Comments
 (0)