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

Commit 03bb4aa

Browse files
bebrawjoshwiens
authored andcommitted
fix(schema): connect loader schema with the code properly
1 parent 8ce93d5 commit 03bb4aa

File tree

7 files changed

+25
-19
lines changed

7 files changed

+25
-19
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var Chunk = require("webpack/lib/Chunk");
1010
var OrderUndefinedError = require("./OrderUndefinedError");
1111
var loaderUtils = require("loader-utils");
1212
var schemaTester = require('./schema/validator');
13+
var loaderSchema = require('./schema/loader-schema.json');
14+
var pluginSchema = require('./schema/plugin-schema.json');
1315

1416
var NS = fs.realpathSync(__dirname);
1517

@@ -120,7 +122,7 @@ function ExtractTextPlugin(options) {
120122
if(isString(options)) {
121123
options = { filename: options };
122124
} else {
123-
schemaTester(options);
125+
schemaTester(pluginSchema, options);
124126
}
125127
this.filename = options.filename;
126128
this.id = options.id != null ? options.id : ++nextId;
@@ -185,7 +187,7 @@ ExtractTextPlugin.prototype.extract = function(options) {
185187
if(Array.isArray(options) || isString(options) || typeof options.options === "object" || typeof options.query === 'object') {
186188
options = { loader: options };
187189
} else {
188-
schemaTester(options);
190+
schemaTester(loaderSchema, options);
189191
}
190192
var loader = options.loader;
191193
var before = options.fallbackLoader || [];

schema/loader-schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"additionalProperties": false,
5+
"properties": {
6+
"allChunks": { "type": "boolean"},
7+
"disable": { "type": "boolean" },
8+
"omit": { "type": "boolean" },
9+
"remove": { "type": "boolean" },
10+
"fallbackLoader": { "type": ["string", "array", "object"] },
11+
"filename": { "type": "string" },
12+
"loader": { "type": ["string", "array", "object"] },
13+
"publicPath": { "type": "string" }
14+
}
15+
}
File renamed without changes.

schema/valid.json

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

schema/validator.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
var Ajv = require('ajv');
22
var ajv = new Ajv({allErrors: true});
3-
var json = require('./schema.json');
43

5-
module.exports = function validate(data) {
4+
module.exports = function validate(schema, data) {
65
var ajv = new Ajv();
7-
var isValid = ajv.validate(json, data);
6+
var isValid = ajv.validate(schema, data);
87

98
if(!isValid) {
109
throw new Error(ajv.errorsText());

test/cases/simple-query-object/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module.exports = {
33
entry: "./index",
44
module: {
55
loaders: [
6-
{ test: /\.css$/, loader: ExtractTextPlugin.extract({
6+
{ test: /\.css$/, use: ExtractTextPlugin.extract({
77
fallbackLoader: "style-loader",
8-
loader: { loader: "css-loader", query: {
8+
loader: { loader: "css-loader", options: {
99
sourceMap: true
1010
} }
1111
}) }

test/cases/simple-queryless-object/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module.exports = {
33
entry: "./index",
44
module: {
55
loaders: [
6-
{ test: /\.css$/, loader: ExtractTextPlugin.extract({
6+
{ test: /\.css$/, use: ExtractTextPlugin.extract({
77
fallbackLoader: { loader: "style-loader" },
8-
loader: { loader: "css-loader", query: {
8+
loader: { loader: "css-loader", options: {
99
sourceMap: true
1010
} }
1111
}) }

0 commit comments

Comments
 (0)