Skip to content

Commit 0dbaa41

Browse files
committed
Added basic json schema validation. A more robust json schema needs to be created
1 parent c8494f3 commit 0dbaa41

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +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/valid');
1213

1314
var NS = fs.realpathSync(__dirname);
1415

@@ -104,6 +105,7 @@ function getOrder(a, b) {
104105
}
105106

106107
function ExtractTextPlugin(options) {
108+
schemaTester(options);
107109
if(arguments.length > 1) {
108110
throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " +
109111
"object *or* the name of the result file.\n" +

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"webpack-sources": "^0.1.0"
1313
},
1414
"devDependencies": {
15+
"ajv": "^4.11.2",
1516
"codecov.io": "^0.1.2",
1617
"coveralls": "^2.11.2",
1718
"css-loader": "^0.21.0",

schema/schema.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"properties": {
5+
"fallbackLoader": {
6+
"type": "object",
7+
"properties": {
8+
"type": {
9+
"type": "string"
10+
}
11+
},
12+
"required": [
13+
"type"
14+
]
15+
},
16+
"loader": {
17+
"type": "object",
18+
"properties": {
19+
"type": {
20+
"type": "string"
21+
}
22+
},
23+
"required": [
24+
"type"
25+
]
26+
},
27+
"publicPath": {
28+
"type": "object",
29+
"properties": {
30+
"type": {
31+
"type": "string"
32+
}
33+
},
34+
"required": [
35+
"type"
36+
]
37+
},
38+
"disable": {
39+
"type": "object",
40+
"properties": {
41+
"type": {
42+
"type": "string"
43+
}
44+
},
45+
"required": [
46+
"type"
47+
]
48+
},
49+
"allChunks": {
50+
"type": "object",
51+
"properties": {
52+
"type": {
53+
"type": "string"
54+
}
55+
},
56+
"required": [
57+
"type"
58+
]
59+
},
60+
"filename": {
61+
"type": "object",
62+
"properties": {
63+
"type": {
64+
"type": "string"
65+
}
66+
},
67+
"required": [
68+
"type"
69+
]
70+
}
71+
},
72+
"required": [
73+
"fallbackLoader",
74+
"loader",
75+
"publicPath",
76+
"disable",
77+
"allChunks",
78+
"filename"
79+
]
80+
}

schema/valid.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var Ajv = require('ajv');
2+
var ajv = new Ajv({allErrors: true});
3+
var json = require('./schema.json');
4+
5+
module.exports = function validate(data) {
6+
var validSchema = ajv.compile(json);
7+
var valid = validSchema(data);
8+
9+
if(!valid) {
10+
throw new Error("Your ExtractTextPlugin config is not correct. Please double check.");
11+
} else {
12+
console.log('your stuff works');
13+
}
14+
}

schema/valid.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"fallbackLoader": { "type": "string" },
3+
"loader": { "type": "string" },
4+
"publicPath": { "type": "string" },
5+
"disable": { "type": "boolean" },
6+
"allChunks": { "type": "boolean"},
7+
"filename": { "type": "string" }
8+
}

0 commit comments

Comments
 (0)