File tree 7 files changed +96
-6
lines changed 7 files changed +96
-6
lines changed Original file line number Diff line number Diff line change 1
1
## purifycss-webpack
2
2
3
+ 0.2.0 / 2017-01-24
4
+ ==================
5
+
6
+ * Feature - Add stricter plugin option validation.
7
+
3
8
0.1.1 / 2017-01-23
4
9
==================
5
10
Original file line number Diff line number Diff line change
1
+ const assert = require ( 'assert' ) ;
2
+ const validateOptions = require ( '../src/validate-options' ) . default ;
3
+
4
+ describe ( 'Validate options' , function ( ) {
5
+ it ( 'fails empty data' , function ( ) {
6
+ const result = validateOptions ( ) ;
7
+
8
+ assert . ok ( ! result . isValid ) ;
9
+ assert . ok ( result . error ) ;
10
+ } ) ;
11
+
12
+ it ( 'fails empty data' , function ( ) {
13
+ const result = validateOptions ( { } ) ;
14
+
15
+ assert . ok ( ! result . isValid ) ;
16
+ assert . ok ( result . error ) ;
17
+ } ) ;
18
+
19
+ it ( 'does not fail if paths are provided' , function ( ) {
20
+ const result = validateOptions ( { paths : [ './foo' ] } ) ;
21
+
22
+ assert . ok ( result . isValid ) ;
23
+ assert . ok ( ! result . error ) ;
24
+ } ) ;
25
+
26
+ it ( 'does not allow arbitrary properties' , function ( ) {
27
+ const result = validateOptions ( { paths : [ './foo' ] , foobar : [ './foo' ] } ) ;
28
+
29
+ assert . ok ( ! result . isValid ) ;
30
+ assert . ok ( result . error ) ;
31
+ } ) ;
32
+ } ) ;
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ module.exports = [
25
25
parts . purifyCSS ( {
26
26
verbose : true ,
27
27
paths : glob . sync ( `${ PATHS . app } /*` ) ,
28
- extensions : [ '.css' , '.html ']
28
+ fileExtensions : [ '.css' ]
29
29
} )
30
30
) ,
31
31
merge (
@@ -45,7 +45,7 @@ module.exports = [
45
45
first : glob . sync ( `${ PATHS . app } /*` ) ,
46
46
second : glob . sync ( `${ PATHS . another } /*` )
47
47
} ,
48
- extensions : [ '.css' , '.html ']
48
+ fileExtensions : [ '.css' ]
49
49
} )
50
50
)
51
51
] ;
Original file line number Diff line number Diff line change 46
46
"webpack" : " ^1.9 || 2 || ^2.1.0-beta || ^2.2.0-rc"
47
47
},
48
48
"dependencies" : {
49
- "webpack-sources" : " ^0.1.4" ,
50
- "purify-css" : " ^1.1.9"
49
+ "ajv" : " ^4.11.2" ,
50
+ "purify-css" : " ^1.1.9" ,
51
+ "webpack-sources" : " ^0.1.4"
51
52
},
52
53
"devDependencies" : {
53
54
"babel-cli" : " ^6.18.0" ,
Original file line number Diff line number Diff line change @@ -2,10 +2,13 @@ const purify = require('purify-css');
2
2
const ConcatSource = require ( 'webpack-sources' ) . ConcatSource ;
3
3
const parse = require ( './parse' ) ;
4
4
const search = require ( './search' ) ;
5
+ const validateOptions = require ( './validate-options' ) . default ;
5
6
6
7
module . exports = function PurifyPlugin ( options ) {
7
- if ( typeof options !== 'object' || ! options . paths ) {
8
- throw new Error ( 'You should pass an options object containing an array of paths at least' ) ;
8
+ const validation = validateOptions ( options ) ;
9
+
10
+ if ( ! validation . isValid ) {
11
+ throw new Error ( validation . error ) ;
9
12
}
10
13
11
14
return {
Original file line number Diff line number Diff line change
1
+ export default {
2
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
3
+ additionalProperties : false ,
4
+ type : 'object' ,
5
+ properties : {
6
+ fileExtensions : {
7
+ type : 'array' ,
8
+ items : {
9
+ type : 'string'
10
+ }
11
+ } ,
12
+ moduleExtensions : {
13
+ type : 'array' ,
14
+ items : {
15
+ type : 'string'
16
+ }
17
+ } ,
18
+ paths : {
19
+ type : [ 'array' , 'object' ] ,
20
+ items : {
21
+ type : 'string'
22
+ }
23
+ } ,
24
+ purifyOptions : {
25
+ type : 'object' ,
26
+ properties : { }
27
+ } ,
28
+ verbose : {
29
+ type : 'boolean'
30
+ }
31
+ } ,
32
+ required : [
33
+ 'paths'
34
+ ]
35
+ } ;
Original file line number Diff line number Diff line change
1
+ import Ajv from 'ajv' ;
2
+ import schema from './schema' ;
3
+
4
+ function validateOptions ( data ) {
5
+ const ajv = new Ajv ( ) ;
6
+ const isValid = ajv . validate ( schema , data ) ;
7
+
8
+ return {
9
+ isValid,
10
+ error : ajv . errors && ajv . errorsText ( )
11
+ } ;
12
+ }
13
+
14
+ export default validateOptions ;
You can’t perform that action at this time.
0 commit comments