1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _browserslist = _interopRequireDefault(require("browserslist"));
|
---|
9 |
|
---|
10 | var _plugins = _interopRequireDefault(require("./plugins"));
|
---|
11 |
|
---|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
13 |
|
---|
14 | function pluginCreator(opts = {}) {
|
---|
15 | return {
|
---|
16 | postcssPlugin: 'stylehacks',
|
---|
17 |
|
---|
18 | OnceExit(css, {
|
---|
19 | result
|
---|
20 | }) {
|
---|
21 | const resultOpts = result.opts || {};
|
---|
22 | const browsers = (0, _browserslist.default)(null, {
|
---|
23 | stats: resultOpts.stats,
|
---|
24 | path: __dirname,
|
---|
25 | env: resultOpts.env
|
---|
26 | });
|
---|
27 |
|
---|
28 | const processors = _plugins.default.reduce((list, Plugin) => {
|
---|
29 | const hack = new Plugin(result);
|
---|
30 | const applied = browsers.some(browser => {
|
---|
31 | return hack.targets.some(target => browser === target);
|
---|
32 | });
|
---|
33 |
|
---|
34 | if (applied) {
|
---|
35 | return list;
|
---|
36 | }
|
---|
37 |
|
---|
38 | return [...list, hack];
|
---|
39 | }, []);
|
---|
40 |
|
---|
41 | css.walk(node => {
|
---|
42 | processors.forEach(proc => {
|
---|
43 | if (!~proc.nodeTypes.indexOf(node.type)) {
|
---|
44 | return;
|
---|
45 | }
|
---|
46 |
|
---|
47 | if (opts.lint) {
|
---|
48 | return proc.detectAndWarn(node);
|
---|
49 | }
|
---|
50 |
|
---|
51 | return proc.detectAndResolve(node);
|
---|
52 | });
|
---|
53 | });
|
---|
54 | }
|
---|
55 |
|
---|
56 | };
|
---|
57 | }
|
---|
58 |
|
---|
59 | pluginCreator.detect = node => {
|
---|
60 | return _plugins.default.some(Plugin => {
|
---|
61 | const hack = new Plugin();
|
---|
62 | return hack.any(node);
|
---|
63 | });
|
---|
64 | };
|
---|
65 |
|
---|
66 | pluginCreator.postcss = true;
|
---|
67 | var _default = pluginCreator;
|
---|
68 | exports.default = _default;
|
---|
69 | module.exports = exports.default; |
---|