Skip to content

Commit 3292d25

Browse files
mightyalekseyAlexey Litvinov
authored andcommitted
validation draft
1 parent 7a54d1f commit 3292d25

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const identity = require('lodash').identity;
66
const readFileSync = require('fs').readFileSync;
77
const relative = require('path').relative;
88
const resolve = require('path').resolve;
9+
const validate = require('./validate');
910

1011
const postcss = require('postcss');
1112
const Values = require('postcss-modules-values');
@@ -27,19 +28,23 @@ module.exports = function setupHook({
2728
use,
2829
rootDir: context = process.cwd(),
2930
}) {
31+
validate(arguments[0]);
32+
3033
const tokensByFile = {};
3134

32-
let scopedName = function () {};
35+
let scopedName;
3336
if (generateScopedName) {
3437
scopedName = typeof generateScopedName !== 'function'
3538
? genericNames(generateScopedName || '[name]__[local]___[hash:base64:5]', {context})
3639
: generateScopedName;
3740
} else {
3841
// small fallback
39-
scopedName = (local, filename) => Scope.generateScopedName(local, relative(context, filename));
42+
scopedName = (local, filename) => {
43+
return Scope.generateScopedName(local, relative(context, filename));
44+
};
4045
}
4146

42-
const plugins = [
47+
const plugins = (use || [
4348
...prepend,
4449
Values,
4550
mode
@@ -50,7 +55,7 @@ module.exports = function setupHook({
5055
: ExtractImports,
5156
new Scope({generateScopedName: scopedName}),
5257
...append,
53-
].concat(new Parser({fetch})); // no pushing in order to avoid the possible mutations;
58+
]).concat(new Parser({fetch})); // no pushing in order to avoid the possible mutations;
5459

5560
// https://github.com/postcss/postcss#options
5661
const runner = postcss(plugins);

lib/validate.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const rules = {
2+
// hook
3+
extensions: 'array|string',
4+
preprocessCss: 'function',
5+
processCss: 'function',
6+
to: 'string',
7+
// plugins
8+
append: 'array',
9+
prepend: 'array',
10+
use: 'array',
11+
createImportedName: 'function',
12+
generateScopedName: 'function|string',
13+
mode: 'string',
14+
rootDir: 'string',
15+
};
16+
17+
module.exports = function validate(options) {}

0 commit comments

Comments
 (0)