1 | "use strict";
|
2 |
|
3 | var _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 |
|
5 | var _postcss = require("postcss");
|
6 |
|
7 | var _postcss2 = _interopRequireDefault(_postcss);
|
8 |
|
9 | var _caniuseApi = require("caniuse-api");
|
10 |
|
11 | var _features = require("./features");
|
12 |
|
13 | var _features2 = _interopRequireDefault(_features);
|
14 |
|
15 | var _featuresActivationMap = require("./features-activation-map");
|
16 |
|
17 | var _featuresActivationMap2 = _interopRequireDefault(_featuresActivationMap);
|
18 |
|
19 | var _warnForDuplicates = require("./warn-for-duplicates");
|
20 |
|
21 | var _warnForDuplicates2 = _interopRequireDefault(_warnForDuplicates);
|
22 |
|
23 | var _warnForDeprecations = require("./warn-for-deprecations");
|
24 |
|
25 | var _warnForDeprecations2 = _interopRequireDefault(_warnForDeprecations);
|
26 |
|
27 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
28 |
|
29 | var 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 |
|
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 |
|
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 |
|
65 | Object.keys(_features2.default).forEach(function (key) {
|
66 |
|
67 |
|
68 | if (
|
69 |
|
70 | features[key] !== false && (
|
71 |
|
72 | features[key] === true ||
|
73 |
|
74 |
|
75 | _featuresActivationMap2.default[key] === undefined ||
|
76 |
|
77 |
|
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 |
|
95 | );plugin.features = _features2.default;
|
96 |
|
97 | module.exports = plugin; |
\ | No newline at end of file |