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

Commit 0ec10e6

Browse files
author
evilebottnawi
committed
fix: validation schema with latest ajv
1 parent d0e88d0 commit 0ec10e6

File tree

6 files changed

+11
-28
lines changed

6 files changed

+11
-28
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +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');
12+
var validateOptions = require('schema-utils');
1313
var loaderSchema = require('./schema/loader-schema');
1414
var pluginSchema = require('./schema/plugin-schema.json');
1515

@@ -122,7 +122,7 @@ function ExtractTextPlugin(options) {
122122
if(isString(options)) {
123123
options = { filename: options };
124124
} else {
125-
schemaTester(pluginSchema, options);
125+
validateOptions(pluginSchema, options, ' Extract Text Plugin');
126126
}
127127
this.filename = options.filename;
128128
this.id = options.id != null ? options.id : ++nextId;
@@ -201,7 +201,7 @@ ExtractTextPlugin.prototype.extract = function(options) {
201201
if(Array.isArray(options) || isString(options) || typeof options.options === "object" || typeof options.query === 'object') {
202202
options = { loader: options };
203203
} else {
204-
schemaTester(loaderSchema, options);
204+
validateOptions(loaderSchema, options, 'Extract Text Loader');
205205
}
206206
var loader = options.use ||  options.loader;
207207
var before = options.fallback || options.fallbackLoader || [];

package.json

+1-1
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

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
2-
"$schema": "http://json-schema.org/draft-04/schema#",
32
"type": "object",
43
"additionalProperties": false,
54
"properties": {

schema/plugin-schema.json

+3-9
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

-13
This file was deleted.

test/extract.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ 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+
console.log(err.message)
33+
return err.message === 'Validation Error\n\n' +
34+
'Extract Text Loader Invalid Options\n\n'
35+
+ 'options[\'style\'] should NOT have additional properties\n';
3336
}
3437
);
3538
});

0 commit comments

Comments
 (0)