1
1
mirror of https://github.com/primer/css.git synced 2024-12-23 06:01:54 +03:00

Properly calculating the variables computed value for dist

This commit is contained in:
Jon Rohan 2021-05-25 14:29:18 -07:00
parent e02694d1ba
commit 93b40e7b7d
No known key found for this signature in database
GPG Key ID: B0BBE304A9A0AECB
3 changed files with 18 additions and 1 deletions

View File

@ -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",

View File

@ -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']}),
@ -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
}
}

View File

@ -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=
postcss-calc@8.0.0:
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"