Skip to content

Commit

Permalink
Properly calculating the variables computed value for dist
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrohan committed May 25, 2021
1 parent e02694d commit 93b40e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"jest": "26.6.3",
"js-yaml": "4.1.0",
"postcss": "8.3.0",
"postcss-calc": "8.0.0",
"postcss-import": "14.0.2",
"postcss-load-config": "3.0.1",
"postcss-node-sass": "3.1.0",
Expand Down
10 changes: 9 additions & 1 deletion script/analyze-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {join} = require('path')
const fs = require('fs')
const atImport = require('postcss-import')
const syntax = require('postcss-scss')
const calc = require('postcss-calc')

const processor = postcss([
atImport({path: ['src']}),
Expand All @@ -20,7 +21,14 @@ async function analyzeVariables(fileName) {
if (!result.variables[`$${message.name}`].values.includes(message.value)) {
result.variables[`$${message.name}`].values.push(message.value)
}
const computed = message.value
let computed = message.value
try {
const c = `--temp-property: calc(${message.value})`.replace('round(', '(')
computed = postcss().use(calc()).process(c).css
computed = computed.replace('--temp-property: ', '')
} catch (e) {
// Couldn't calculate because value might not be a number
}
result.variables[`$${message.name}`].computed = computed
}
}
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5337,6 +5337,14 @@ posix-character-classes@^0.1.0:
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=

[email protected]:
version "8.0.0"
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-8.0.0.tgz#a05b87aacd132740a5db09462a3612453e5df90a"
integrity sha512-5NglwDrcbiy8XXfPM11F3HeC6hoT9W7GUH/Zi5U/p7u3Irv4rHhdDcIZwG0llHXV4ftsBjpfWMXAnXNl4lnt8g==
dependencies:
postcss-selector-parser "^6.0.2"
postcss-value-parser "^4.0.2"

postcss-custom-properties@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/postcss-custom-properties/-/postcss-custom-properties-10.0.0.tgz#5cb31afc530f58ad241f1e836dd5f5f7065334df"
Expand Down

0 comments on commit 93b40e7

Please sign in to comment.