Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit e76b7ef

Browse files
committed
Update Plugin: Support a browserslist
1 parent d4b09d4 commit e76b7ef

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
// tooling
2+
const browserslist = require('browserslist');
23
const postcss = require('postcss');
34
const selectorParser = require('postcss-selector-parser');
45

56
// plugin
67
module.exports = postcss.plugin('postcss-dir-pseudo-class', (opts) => (root) => {
8+
// client browser list
9+
const clientBrowserList = browserslist(opts && opts.browsers, {
10+
path: root.source && root.source.input && root.source.input.file
11+
});
12+
13+
// whether this library is needed
14+
const requiresPolyfill = clientBrowserList.some(
15+
(clientBrowser) => browserslist('chrome > 0, edge > 0, firefox <= 48, ie > 0, safari > 0').some(
16+
(polyfillBrowser) => polyfillBrowser === clientBrowser
17+
)
18+
);
19+
20+
if (!requiresPolyfill) {
21+
return;
22+
}
23+
724
// walk rules using the :dir pseudo-class
825
root.walkRules(/:dir\([^\)]*\)/, (rule) => {
926
// update the rule selector

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"node": ">=4.0.0"
2323
},
2424
"dependencies": {
25+
"browserslist": "^2.1.4",
2526
"postcss": "^6.0.1",
2627
"postcss-selector-parser": "^2.2.3"
2728
},

0 commit comments

Comments
 (0)