Skip to content

Commit 6826ba5

Browse files
authored
update: use PostCSS 8 API. (#125)
* BREAKING CHANGE: require PostCSS 8 and Node >= 10.. * Move postcss to peer dependencies.
1 parent f16d55c commit 6826ba5

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ language: node_js
22
cache: yarn
33
node_js:
44
- node
5+
- "12"
56
- "10"
6-
- "8"
7-
- "6"

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@
4545
"eslint-config-i-am-meticulous": "^11.0.0",
4646
"eslint-plugin-babel": "^5.2.1",
4747
"eslint-plugin-import": "^2.14.0",
48-
"jison-gho": "^0.6.1-215"
48+
"jison-gho": "^0.6.1-215",
49+
"postcss": "^8.2.2"
4950
},
5051
"dependencies": {
51-
"postcss": "^7.0.27",
5252
"postcss-selector-parser": "^6.0.2",
5353
"postcss-value-parser": "^4.0.2"
5454
},
55+
"peerDependencies": {
56+
"postcss": "^8.2.2"
57+
},
5558
"ava": {
5659
"require": [
5760
"@babel/register",

src/index.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import {plugin} from 'postcss';
2-
31
import transform from './lib/transform';
42

5-
export default plugin('postcss-calc', (opts) => {
3+
function pluginCreator(opts) {
64
const options = Object.assign({
75
precision: 5,
86
preserve: false,
@@ -11,21 +9,28 @@ export default plugin('postcss-calc', (opts) => {
119
selectors: false
1210
}, opts);
1311

14-
return (css, result) => {
15-
css.walk(node => {
16-
const { type } = node;
12+
return {
13+
postcssPlugin: 'postcss-calc',
14+
OnceExit(css, { result }) {
15+
css.walk(node => {
16+
const { type } = node;
17+
18+
if (type === 'decl') {
19+
transform(node, "value", options, result);
20+
}
21+
22+
if (type === 'atrule' && options.mediaQueries) {
23+
transform(node, "params", options, result);
24+
}
1725

18-
if (type === 'decl') {
19-
transform(node, "value", options, result);
20-
}
26+
if (type === 'rule' && options.selectors) {
27+
transform(node, "selector", options, result);
28+
}
29+
});
30+
}
31+
}
32+
}
2133

22-
if (type === 'atrule' && options.mediaQueries) {
23-
transform(node, "params", options, result);
24-
}
34+
pluginCreator.postcss = true;
2535

26-
if (type === 'rule' && options.selectors) {
27-
transform(node, "selector", options, result);
28-
}
29-
});
30-
};
31-
});
36+
export default pluginCreator;

yarn.lock

+16-6
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,11 @@ color-name@1.1.3:
13491349
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
13501350
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
13511351

1352+
colorette@^1.2.1:
1353+
version "1.2.1"
1354+
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
1355+
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
1356+
13521357
commander@^2.8.1:
13531358
version "2.20.0"
13541359
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
@@ -3141,6 +3146,11 @@ nan@^2.9.2:
31413146
resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7"
31423147
integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==
31433148

3149+
nanoid@^3.1.20:
3150+
version "3.1.20"
3151+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
3152+
integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==
3153+
31443154
nanomatch@^1.2.9:
31453155
version "1.2.13"
31463156
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -3627,14 +3637,14 @@ postcss-value-parser@^4.0.2:
36273637
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.0.3.tgz#651ff4593aa9eda8d5d0d66593a2417aeaeb325d"
36283638
integrity sha512-N7h4pG+Nnu5BEIzyeaaIYWs0LI5XC40OrRh5L60z0QjFsqGWcHcbkBvpe1WYpcIS9yQ8sOi/vIPt1ejQCrMVrg==
36293639

3630-
postcss@^7.0.27:
3631-
version "7.0.27"
3632-
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.27.tgz#cc67cdc6b0daa375105b7c424a85567345fc54d9"
3633-
integrity sha512-WuQETPMcW9Uf1/22HWUWP9lgsIC+KEHg2kozMflKjbeUtw9ujvFX6QmIfozaErDkmLWS9WEnEdEe6Uo9/BNTdQ==
3640+
postcss@^8.2.2:
3641+
version "8.2.2"
3642+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.2.tgz#60613b62297005084fd21024a68637798864fe26"
3643+
integrity sha512-HM1NDNWLgglJPQQMNwvLxgH2KcrKZklKLi/xXYIOaqQB57p/pDWEJNS83PVICYsn1Dg/9C26TiejNr422/ePaQ==
36343644
dependencies:
3635-
chalk "^2.4.2"
3645+
colorette "^1.2.1"
3646+
nanoid "^3.1.20"
36363647
source-map "^0.6.1"
3637-
supports-color "^6.1.0"
36383648

36393649
prelude-ls@~1.1.2:
36403650
version "1.1.2"

0 commit comments

Comments
 (0)