From 03bb4aa50f4cf2b580512d066c82886230303571 Mon Sep 17 00:00:00 2001 From: Juho Vepsalainen Date: Sat, 28 Jan 2017 19:05:30 +0200 Subject: [PATCH] fix(schema): connect loader schema with the code properly --- index.js | 6 ++++-- schema/loader-schema.json | 15 +++++++++++++++ schema/{schema.json => plugin-schema.json} | 0 schema/valid.json | 10 ---------- schema/validator.js | 5 ++--- test/cases/simple-query-object/webpack.config.js | 4 ++-- .../simple-queryless-object/webpack.config.js | 4 ++-- 7 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 schema/loader-schema.json rename schema/{schema.json => plugin-schema.json} (100%) delete mode 100644 schema/valid.json diff --git a/index.js b/index.js index 44c01f4b..6893af4b 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,8 @@ 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.json'); +var pluginSchema = require('./schema/plugin-schema.json'); var NS = fs.realpathSync(__dirname); @@ -120,7 +122,7 @@ function ExtractTextPlugin(options) { if(isString(options)) { options = { filename: options }; } else { - schemaTester(options); + schemaTester(pluginSchema, options); } this.filename = options.filename; this.id = options.id != null ? options.id : ++nextId; @@ -185,7 +187,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(options); + schemaTester(loaderSchema, options); } var loader = options.loader; var before = options.fallbackLoader || []; diff --git a/schema/loader-schema.json b/schema/loader-schema.json new file mode 100644 index 00000000..da041463 --- /dev/null +++ b/schema/loader-schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "additionalProperties": false, + "properties": { + "allChunks": { "type": "boolean"}, + "disable": { "type": "boolean" }, + "omit": { "type": "boolean" }, + "remove": { "type": "boolean" }, + "fallbackLoader": { "type": ["string", "array", "object"] }, + "filename": { "type": "string" }, + "loader": { "type": ["string", "array", "object"] }, + "publicPath": { "type": "string" } + } +} diff --git a/schema/schema.json b/schema/plugin-schema.json similarity index 100% rename from schema/schema.json rename to schema/plugin-schema.json diff --git a/schema/valid.json b/schema/valid.json deleted file mode 100644 index e9ac0907..00000000 --- a/schema/valid.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "allChunks": { "type": "boolean"}, - "disable": { "type": "boolean" }, - "omit": { "type": "boolean" }, - "remove": { "type": "boolean" }, - "fallbackLoader": { "type": "string" }, - "filename": { "type": "string" }, - "loader": { "type": "string" }, - "publicPath": { "type": "string" } -} diff --git a/schema/validator.js b/schema/validator.js index fa6244ff..40b2e099 100644 --- a/schema/validator.js +++ b/schema/validator.js @@ -1,10 +1,9 @@ var Ajv = require('ajv'); var ajv = new Ajv({allErrors: true}); -var json = require('./schema.json'); -module.exports = function validate(data) { +module.exports = function validate(schema, data) { var ajv = new Ajv(); - var isValid = ajv.validate(json, data); + var isValid = ajv.validate(schema, data); if(!isValid) { throw new Error(ajv.errorsText()); diff --git a/test/cases/simple-query-object/webpack.config.js b/test/cases/simple-query-object/webpack.config.js index da458a60..984c47b3 100644 --- a/test/cases/simple-query-object/webpack.config.js +++ b/test/cases/simple-query-object/webpack.config.js @@ -3,9 +3,9 @@ module.exports = { entry: "./index", module: { loaders: [ - { test: /\.css$/, loader: ExtractTextPlugin.extract({ + { test: /\.css$/, use: ExtractTextPlugin.extract({ fallbackLoader: "style-loader", - loader: { loader: "css-loader", query: { + loader: { loader: "css-loader", options: { sourceMap: true } } }) } diff --git a/test/cases/simple-queryless-object/webpack.config.js b/test/cases/simple-queryless-object/webpack.config.js index 36741d5d..d6e23f8d 100644 --- a/test/cases/simple-queryless-object/webpack.config.js +++ b/test/cases/simple-queryless-object/webpack.config.js @@ -3,9 +3,9 @@ module.exports = { entry: "./index", module: { loaders: [ - { test: /\.css$/, loader: ExtractTextPlugin.extract({ + { test: /\.css$/, use: ExtractTextPlugin.extract({ fallbackLoader: { loader: "style-loader" }, - loader: { loader: "css-loader", query: { + loader: { loader: "css-loader", options: { sourceMap: true } } }) }