From 6826ba5c0b03a22f83e177c41ba778735421650c Mon Sep 17 00:00:00 2001 From: Ludovico Fischer <43557+ludofischer@users.noreply.github.com> Date: Sun, 3 Jan 2021 16:54:15 +0100 Subject: [PATCH] update: use PostCSS 8 API. (#125) * BREAKING CHANGE: require PostCSS 8 and Node >= 10.. * Move postcss to peer dependencies. --- .travis.yml | 3 +-- package.json | 7 +++++-- src/index.js | 41 +++++++++++++++++++++++------------------ yarn.lock | 22 ++++++++++++++++------ 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f01dc3..75dad6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,5 @@ language: node_js cache: yarn node_js: - node + - "12" - "10" - - "8" - - "6" diff --git a/package.json b/package.json index 1a8eb63..621c90d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 5be5e32..04be391 100644 --- a/src/index.js +++ b/src/index.js @@ -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, @@ -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; diff --git a/yarn.lock b/yarn.lock index fa0fd2a..547a6f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1349,6 +1349,11 @@ color-name@1.1.3: 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" @@ -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" @@ -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"