-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cjs
47 lines (38 loc) · 1002 Bytes
/
index.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const picomatch = require('picomatch');
const postcss = require('postcss');
const slash = require('slash');
function createMatch(patterns) {
return patterns.length > 0
? (file) => {
const globs = patterns.map((item) => slash(item));
return picomatch(globs, { dot: true, format: slash })(slash(file));
}
: undefined;
}
function matcher({ plugins = [], include = [], exclude = [] } = {}) {
const includes = createMatch(include);
const excludes = createMatch(exclude);
const processer = postcss(
plugins.map((item) => (typeof item === 'string' ? require(item) : item)),
);
return (
root,
{
opts,
root: {
source: {
input: { file },
},
},
},
) => {
const match =
file &&
(includes ? includes(file) : true) &&
(excludes ? !excludes(file) : true);
return match ? processer.process(root, opts) : {};
};
}
matcher.postcss = true;
module.exports = matcher;