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

Commit

Permalink
fix(schema): connect loader schema with the code properly
Browse files Browse the repository at this point in the history
  • Loading branch information
bebraw authored and joshwiens committed Jan 28, 2017
1 parent 8ce93d5 commit 03bb4aa
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 || [];
Expand Down
15 changes: 15 additions & 0 deletions schema/loader-schema.json
Original file line number Diff line number Diff line change
@@ -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" }
}
}
File renamed without changes.
10 changes: 0 additions & 10 deletions schema/valid.json

This file was deleted.

5 changes: 2 additions & 3 deletions schema/validator.js
Original file line number Diff line number Diff line change
@@ -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());
Expand Down
4 changes: 2 additions & 2 deletions test/cases/simple-query-object/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
} }
}) }
Expand Down
4 changes: 2 additions & 2 deletions test/cases/simple-queryless-object/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
} }
}) }
Expand Down

0 comments on commit 03bb4aa

Please sign in to comment.