UNPKG

3.15 kBJavaScriptView Raw
1"use strict";
2
3var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4
5var _postcss = require("postcss");
6
7var _postcss2 = _interopRequireDefault(_postcss);
8
9var _caniuseApi = require("caniuse-api");
10
11var _features = require("./features");
12
13var _features2 = _interopRequireDefault(_features);
14
15var _featuresActivationMap = require("./features-activation-map");
16
17var _featuresActivationMap2 = _interopRequireDefault(_featuresActivationMap);
18
19var _warnForDuplicates = require("./warn-for-duplicates");
20
21var _warnForDuplicates2 = _interopRequireDefault(_warnForDuplicates);
22
23var _warnForDeprecations = require("./warn-for-deprecations");
24
25var _warnForDeprecations2 = _interopRequireDefault(_warnForDeprecations);
26
27function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
29var plugin = _postcss2.default.plugin("postcss-cssnext", function (options) {
30 options = _extends({
31 console: console,
32 warnForDuplicates: true,
33 warnForDeprecations: true,
34 features: {}
35 }, options);
36
37 var features = options.features;
38
39 // propagate browsers option to plugins that supports it
40 var pluginsToPropagateBrowserOption = ["autoprefixer", "rem"];
41 pluginsToPropagateBrowserOption.forEach(function (name) {
42 var feature = features[name];
43
44 if (feature !== false) {
45 features[name] = _extends({
46 browsers: feature && feature.browsers ? feature.browsers : options.browsers
47 }, feature || {});
48 }
49 }
50
51 // autoprefixer doesn't like an "undefined" value. Related to coffee ?
52 );if (features.autoprefixer && features.autoprefixer.browsers === undefined) {
53 delete features.autoprefixer.browsers;
54 }
55
56 var processor = (0, _postcss2.default)();
57
58 if (options.warnForDeprecations) {
59 processor.use((0, _warnForDeprecations2.default)({
60 console: options.console
61 }));
62 }
63
64 // features
65 Object.keys(_features2.default).forEach(function (key) {
66 // feature is auto enabled if: not disable && (enabled || no data yet ||
67 // !supported yet)
68 if (
69 // feature is not disabled
70 features[key] !== false && (
71 // feature is enabled
72 features[key] === true ||
73
74 // feature don't have any browsers data (yet)
75 _featuresActivationMap2.default[key] === undefined ||
76
77 // feature is not yet supported by the browsers scope
78 _featuresActivationMap2.default[key] && _featuresActivationMap2.default[key][0] && !(0, _caniuseApi.isSupported)(_featuresActivationMap2.default[key][0], options.browsers))) {
79 var _plugin = _features2.default[key](typeof features[key] === "object" ? _extends({}, features[key]) : undefined);
80 processor.use(_plugin);
81 }
82 });
83
84 if (options.warnForDuplicates) {
85 processor.use((0, _warnForDuplicates2.default)({
86 keys: Object.keys(_features2.default),
87 console: options.console
88 }));
89 }
90
91 return processor;
92}
93
94// es5/6 support
95);plugin.features = _features2.default;
96
97module.exports = plugin;
\No newline at end of file