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

Commit

Permalink
fix: validation schema (schema-utils) (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and michael-ciniawsky committed Jun 7, 2017
1 parent d0e88d0 commit dfeb347
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 48 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ var ExtractedModule = require("./ExtractedModule");
var Chunk = require("webpack/lib/Chunk");
var OrderUndefinedError = require("./OrderUndefinedError");
var loaderUtils = require("loader-utils");
var schemaTester = require('./schema/validator');
var loaderSchema = require('./schema/loader-schema');
var pluginSchema = require('./schema/plugin-schema.json');
var validateOptions = require('schema-utils');

var NS = fs.realpathSync(__dirname);

Expand Down Expand Up @@ -122,7 +120,7 @@ function ExtractTextPlugin(options) {
if(isString(options)) {
options = { filename: options };
} else {
schemaTester(pluginSchema, options);
validateOptions('./schema/plugin.json', options, 'Extract Text Plugin');
}
this.filename = options.filename;
this.id = options.id != null ? options.id : ++nextId;
Expand Down Expand Up @@ -201,7 +199,7 @@ ExtractTextPlugin.prototype.extract = function(options) {
if(Array.isArray(options) || isString(options) || typeof options.options === "object" || typeof options.query === 'object') {
options = { loader: options };
} else {
schemaTester(loaderSchema, options);
validateOptions('./schema/loader.json', options, 'Extract Text Plugin (Loader)');
}
var loader = options.use ||  options.loader;
var before = options.fallback || options.fallbackLoader || [];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"webpack": "^2.2.0"
},
"dependencies": {
"ajv": "^4.11.2",
"schema-utils": "^0.3.0",
"async": "^2.1.2",
"loader-utils": "^1.0.2",
"webpack-sources": "^0.1.0"
Expand Down
19 changes: 0 additions & 19 deletions schema/loader-schema.js

This file was deleted.

36 changes: 36 additions & 0 deletions schema/loader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"type": "object",
"additionalProperties": false,
"properties": {
"allChunks": {
"type": "boolean"
},
"disable": {
"type": "boolean"
},
"omit": {
"type": "boolean"
},
"remove": {
"type": "boolean"
},
"fallback": {
"type": ["string", "array", "object"]
},
"filename": {
"type": "string"
},
"use": {
"type": ["string", "array", "object"]
},
"publicPath": {
"type": "string"
},
"fallbackLoader": {
"type": ["string", "array", "object"]
},
"loader": {
"type": ["string", "array", "object"]
}
}
}
12 changes: 3 additions & 9 deletions schema/plugin-schema.json → schema/plugin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
Expand All @@ -14,16 +13,13 @@
"fallback": {
"description": "A loader that webpack can fall back to if the original one fails.",
"modes": {
"type": "string",
"type": "object",
"type": "array"
"type": ["string", "object", "array"]
}
},
"filename": {
"description": "The filename and path that ExtractTextPlugin will extract to",
"modes": {
"type": "string",
"type": "function"
"type": ["string", "function"]
}
},
"ignoreOrder": {
Expand All @@ -33,9 +29,7 @@
"loader": {
"description": "The loader that ExtractTextPlugin will attempt to load through.",
"modes": {
"type": "string",
"type": "object",
"type": "array"
"type": ["string", "object", "array"]
}
},
"publicPath": {
Expand Down
13 changes: 0 additions & 13 deletions schema/validator.js

This file was deleted.

4 changes: 3 additions & 1 deletion test/extract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ describe("ExtractTextPlugin.extract()", function() {
ExtractTextPlugin.extract({style: 'file.css'});
},
function(err) {
return err.message === 'data[\'style\'] should NOT have additional properties';
return err.message === 'Validation Error\n\n' +
'Extract Text Plugin (Loader) Invalid Options\n\n' +
'options[\'style\'] should NOT have additional properties\n';
}
);
});
Expand Down

0 comments on commit dfeb347

Please sign in to comment.