This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
index.js
96 lines (81 loc) · 2.49 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import postcss from "postcss"
import { isSupported } from "caniuse-api"
import libraryFeatures from "./features"
import featuresActivationMap from "./features-activation-map"
import warnForDuplicates from "./warn-for-duplicates"
import warnForDeprecations from "./warn-for-deprecations"
const plugin = postcss.plugin("postcss-cssnext", (options) => {
options = {
console: console,
warnForDuplicates: true,
warnForDeprecations: true,
features: {},
// options.browsers is deliberately undefined by default to inherit
// browserslist default behavior
...options,
}
const features = options.features
// propagate browsers option to plugins that supports it
const pluginsToPropagateBrowserOption = [ "autoprefixer", "rem" ]
pluginsToPropagateBrowserOption.forEach((name) => {
const feature = features[name]
if (feature !== false) {
features[name] = {
browsers: (
feature && feature.browsers
? feature.browsers
: options.browsers
),
...(feature || {}),
}
}
})
// autoprefixer doesn't like an "undefined" value. Related to coffee ?
if (features.autoprefixer && features.autoprefixer.browsers === undefined) {
delete features.autoprefixer.browsers
}
const processor = postcss()
if (options.warnForDeprecations) {
processor.use(warnForDeprecations({
console: options.console,
}))
}
// features
Object.keys(libraryFeatures).forEach(key => {
// feature is auto enabled if: not disable && (enabled || no data yet ||
// !supported yet)
if (
// feature is not disabled
features[key] !== false &&
(
// feature is enabled
features[key] === true ||
// feature don't have any browsers data (yet)
featuresActivationMap[key] === undefined ||
// feature is not yet supported by the browsers scope
(
featuresActivationMap[key] &&
featuresActivationMap[key][0] &&
!isSupported(featuresActivationMap[key][0], options.browsers)
)
)
) {
const plugin = libraryFeatures[key](
typeof features[key] === "object"
? { ...features[key] }
: undefined
)
processor.use(plugin)
}
})
if (options.warnForDuplicates) {
processor.use(warnForDuplicates({
keys: Object.keys(libraryFeatures),
console: options.console,
}))
}
return processor
})
// es5/6 support
plugin.features = libraryFeatures
module.exports = plugin