UNPKG

2.87 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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; };
8
9function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
11var _postcss = require("postcss");
12
13var _postcss2 = _interopRequireDefault(_postcss);
14
15var _caniuseApi = require("caniuse-api");
16
17var _features = require("./features");
18
19var _features2 = _interopRequireDefault(_features);
20
21var _featuresActivationMap = require("./features-activation-map");
22
23var _featuresActivationMap2 = _interopRequireDefault(_featuresActivationMap);
24
25var plugin = _postcss2["default"].plugin("postcss-cssnext", function (options) {
26 options = _extends({
27 features: {}
28 }, options);
29
30 var features = options.features;
31
32 // propagate browsers option to autoprefixer
33 if (features.autoprefixer !== false) {
34 features.autoprefixer = _extends({
35 browsers: features.autoprefixer && features.autoprefixer.browsers ? features.autoprefixer.browsers : options.browsers
36 }, features.autoprefixer || {});
37
38 // autoprefixer doesn't like an "undefined" value. Related to coffee ?
39 if (features.autoprefixer.browsers === undefined) {
40 delete features.autoprefixer.browsers;
41 }
42 }
43
44 var processor = (0, _postcss2["default"])();
45
46 // features
47 Object.keys(_features2["default"]).forEach(function (key) {
48 // feature is auto enabled if: not disable && (enabled || no data yet ||
49 // !supported yet)
50 if (
51 // feature is not disabled
52 features[key] !== false && (
53 // feature is enabled
54 features[key] === true ||
55
56 // feature don't have any browsers data (yet)
57 _featuresActivationMap2["default"][key] === undefined ||
58
59 // feature is not yet supported by the browsers scope
60 _featuresActivationMap2["default"][key] && _featuresActivationMap2["default"][key][0] && !(0, _caniuseApi.isSupported)(_featuresActivationMap2["default"][key][0], options.browsers))) {
61 var _plugin = _features2["default"][key](typeof features[key] === "object" ? _extends({}, features[key]) : undefined);
62 processor.use(_plugin);
63 }
64 });
65
66 return processor;
67});
68
69// according to the way babel transpile es6 module
70// we cannot use the following syntax to export features
71//
72// export { libraryFeatures as features }
73//
74// babel only add `module.exports = exports["default"];` if there is only one
75// thing exported
76// so we add `features` as a plugin property
77plugin.features = _features2["default"];
78
79exports["default"] = plugin;
80module.exports = exports["default"];
81// options.browsers is deliberately undefined by default to inherit
82// browserslist default behavior
\No newline at end of file