Skip to content

Commit

Permalink
update: use PostCSS 8 API. (#125)
Browse files Browse the repository at this point in the history
* BREAKING CHANGE: require PostCSS 8 and Node >= 10..
* Move postcss to peer dependencies.
  • Loading branch information
ludofischer authored Jan 3, 2021
1 parent f16d55c commit 6826ba5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ language: node_js
cache: yarn
node_js:
- node
- "12"
- "10"
- "8"
- "6"
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@
"eslint-config-i-am-meticulous": "^11.0.0",
"eslint-plugin-babel": "^5.2.1",
"eslint-plugin-import": "^2.14.0",
"jison-gho": "^0.6.1-215"
"jison-gho": "^0.6.1-215",
"postcss": "^8.2.2"
},
"dependencies": {
"postcss": "^7.0.27",
"postcss-selector-parser": "^6.0.2",
"postcss-value-parser": "^4.0.2"
},
"peerDependencies": {
"postcss": "^8.2.2"
},
"ava": {
"require": [
"@babel/register",
Expand Down
41 changes: 23 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {plugin} from 'postcss';

import transform from './lib/transform';

export default plugin('postcss-calc', (opts) => {
function pluginCreator(opts) {
const options = Object.assign({
precision: 5,
preserve: false,
Expand All @@ -11,21 +9,28 @@ export default plugin('postcss-calc', (opts) => {
selectors: false
}, opts);

return (css, result) => {
css.walk(node => {
const { type } = node;
return {
postcssPlugin: 'postcss-calc',
OnceExit(css, { result }) {
css.walk(node => {
const { type } = node;

if (type === 'decl') {
transform(node, "value", options, result);
}

if (type === 'atrule' && options.mediaQueries) {
transform(node, "params", options, result);
}

if (type === 'decl') {
transform(node, "value", options, result);
}
if (type === 'rule' && options.selectors) {
transform(node, "selector", options, result);
}
});
}
}
}

if (type === 'atrule' && options.mediaQueries) {
transform(node, "params", options, result);
}
pluginCreator.postcss = true;

if (type === 'rule' && options.selectors) {
transform(node, "selector", options, result);
}
});
};
});
export default pluginCreator;
22 changes: 16 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=

colorette@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==

commander@^2.8.1:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
Expand Down Expand Up @@ -3141,6 +3146,11 @@ nan@^2.9.2:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7"
integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==

nanoid@^3.1.20:
version "3.1.20"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==

nanomatch@^1.2.9:
version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
Expand Down Expand Up @@ -3627,14 +3637,14 @@ postcss-value-parser@^4.0.2:
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.0.3.tgz#651ff4593aa9eda8d5d0d66593a2417aeaeb325d"
integrity sha512-N7h4pG+Nnu5BEIzyeaaIYWs0LI5XC40OrRh5L60z0QjFsqGWcHcbkBvpe1WYpcIS9yQ8sOi/vIPt1ejQCrMVrg==

postcss@^7.0.27:
version "7.0.27"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.27.tgz#cc67cdc6b0daa375105b7c424a85567345fc54d9"
integrity sha512-WuQETPMcW9Uf1/22HWUWP9lgsIC+KEHg2kozMflKjbeUtw9ujvFX6QmIfozaErDkmLWS9WEnEdEe6Uo9/BNTdQ==
postcss@^8.2.2:
version "8.2.2"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.2.tgz#60613b62297005084fd21024a68637798864fe26"
integrity sha512-HM1NDNWLgglJPQQMNwvLxgH2KcrKZklKLi/xXYIOaqQB57p/pDWEJNS83PVICYsn1Dg/9C26TiejNr422/ePaQ==
dependencies:
chalk "^2.4.2"
colorette "^1.2.1"
nanoid "^3.1.20"
source-map "^0.6.1"
supports-color "^6.1.0"

prelude-ls@~1.1.2:
version "1.1.2"
Expand Down

0 comments on commit 6826ba5

Please sign in to comment.