-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design tokens pipeline - Upgrade StyleDictionary
to version 4.2.0
#2560
base: main
Are you sure you want to change the base?
Conversation
npx codemod styledictionary/4/migration-recipe see: https://styledictionary.com/version-4/migration/
… `tsc` I have seen this used in this way in other StyleDictionary 4 repos: - https://github.com/navikt/aksel/blob/c5f46e60ad20a9b67723ddc930df1b9be8d8d3a6/%40navikt/core/tokens/package.json - https://github.com/digital-go-jp/design-tokens/blob/431d2bacc7f5ca58ce4a456f02137cf87d8d0a11/package.json#L31
…leDictionary APIs and in the process fix all the TS issues raised by the linter
there is a diff in code, but it’s not meaningful because: - the header has changed, now there is no more a “Generated on” date - the hex value of one tokena has been changed from `#fff` to `#ffffff` (probably due to a new version of the `tinycolor` dependency) - the order of some tokens in the generated files has change, but I think it’s because of the async nature of the new StyleDictionary code and/or how the files are read from the filesystem in a recursive way (before child folders were read before child files, now it seems the order is child files and then child folders) (to be 100% sure I compared the old vs the new file with the tokens sorted alphabetically, and the only differences were the one described above, so it should OK as is now too)
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -1,6 +1,5 @@ | |||
/** | |||
* Do not edit directly | |||
* Generated on Fri, 20 Sep 2024 19:02:21 GMT | |||
* Do not edit directly, this file was auto-generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is because in StyleDictionary the header
(this comment at the top of the files) now doesn't contain anymore the date in which it's been generated; this will lead to less noise in the diffs)
.hds-elevation-inset { box-shadow: inset 0px 1px 2px 1px #656a761a); } | ||
.hds-elevation-low { box-shadow: 0px 1px 1px 0px #656a760d, 0px 2px 2px 0px #656a760d); } | ||
.hds-elevation-mid { box-shadow: 0px 2px 3px 0px #656a761a, 0px 8px 16px -10px #656a7633); } | ||
.hds-elevation-high { box-shadow: 0px 2px 3px 0px #656a7626, 0px 16px 16px -10px #656a7633); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reasons, these properties are re-ordered when the new style dictionary package is used.
@@ -195,6 +194,47 @@ | |||
--token-surface-overlay-box-shadow: 0 0 0 1px #3b3d4540, 0px 2px 3px 0px #3b3d4540, 0px 12px 24px 0px #3b3d4559; | |||
--token-focus-ring-action-box-shadow: inset 0 0 0 1px #0c56e9, 0 0 0 3px #5990ff; | |||
--token-focus-ring-critical-box-shadow: inset 0 0 0 1px #c00005, 0 0 0 3px #dd7578; | |||
--token-app-header-height: 60px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reasons, these properties are re-ordered when the new style dictionary package is used.
In any case, to be 100% sure, I've compared the old vs the new version of these files, sorting the tokens alphabetically, and the only difference is the order in which they're declared (no other meaningful differences)
@@ -320,7 +319,7 @@ | |||
--token-side-nav-body-list-item-content-spacing-horizontal: 8px; | |||
--token-side-nav-body-list-item-border-radius: 5px; | |||
--token-side-nav-color-foreground-primary: #dedfe3; | |||
--token-side-nav-color-foreground-strong: #fff; | |||
--token-side-nav-color-foreground-strong: #ffffff; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is due to the new tinycolor
package version.
declarations.push(`font-family: ${valueFontFamily};`); | ||
declarations.push(`font-size: ${valueFontSize};`); | ||
declarations.push(`line-height: ${valueLineHeight};`); | ||
if (outputCssVars) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to make this change to satisfy the TS linter
StyleDictionaryPackage.registerTransform({ | ||
name: 'time/seconds', // notice: the name is an override of an existing predefined method | ||
StyleDictionary.registerTransform({ | ||
name: 'time/sec', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apparently overriding existing/official transform names does not work anymore (the output value was incorrect) so I had to change it to a custom transform name.
@@ -268,13 +276,14 @@ console.log('\n=============================================='); | |||
console.log(`\nCleaning up dist folder`); | |||
fs.emptyDirSync(distFolder); | |||
|
|||
Object.keys(targets).forEach(target => { | |||
const StyleDictionary = StyleDictionaryPackage.extend(getStyleDictionaryConfig({ target })); | |||
for (const target of Object.keys(targets)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that StyleDictionary has become an async method, we can't use anymore the forEach
loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhaulagiri @alex-ju can you check that the changes I made to this file make sense (based on your experience/knowledge)? thanks
@@ -16,26 +16,28 @@ | |||
}, | |||
"license": "MPL-2.0", | |||
"author": "HashiCorp Design Systems <[email protected]>", | |||
"type": "module", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhaulagiri @alex-ju unless I changed this to be a "type": "module"
the script didn't work as expected (it was throwing errors in the compilation/execution of the script)
"scripts": { | ||
"typecheck": "yarn tsc --noEmit", | ||
"lint": "yarn eslint --quiet --ext .js,.ts", | ||
"build": "ts-node --transpile-only ./scripts/build" | ||
"build": "tsx ./scripts/build" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhaulagiri @alex-ju this is the way I managed to get it working (I took "inspiration" from here and here). If you know otherwise or have better idea, please come forward :)
📌 Summary
While working on the exploration of extending coverage of component-level design tokens in our codebase (https://hashicorp.atlassian.net/browse/HDS-3915) and how this effort would connect with the implementation of theming in our system, I have decided that it was time to upgrade
🛠️ Detailed description
In this PR I have:
style-dictionary
dev-dependency to4.2.0
(latest)npx codemod styledictionary/4/migration-recipe
(see: https://styledictionary.com/version-4/migration/)package.json
file to be"type": "module”
per StyleDictionary guide (see: https://styledictionary.com/version-4/migration/#es-modules-instead-of-commonjs)build
script in thepackage.json
file to usetsx
instead oftsc
lodash
dev-dependency withlodash-es
(compatible with ES Modules)tsconfig.json
to make the Node.js application run and build correctlybuild.ts
script and other sub-scripts to follow the new StyleDictionary APIsyarn build
with the new version of StyleDictonary (see below about the changes introduced in this operation)Changes in the generated files:
While there are difference in the generated output files, these are not meaningful because:
#fff
to#ffffff
(probably due to a new version of thetinycolor
dependency)In any case, to be 100% sure I compared the old vs the new files with the tokens sorted alphabetically, and the only differences were the one described above, so I don't see problems with the changes introduced (just a re-ordering)
💻 How to test it
spike-styledictionary-update-v4
yarn install
cd packages/tokens
yarn build
At this point, you should see the script run, execute successfully, but no output files should be changed.
Now try to update one or more token values, run again the
yarn build
script, and you should see the output generated with the new updated values.🤔 Things to discuss
patch
bump, just in case?🔗 External links
Jira ticket: https://hashicorp.atlassian.net/browse/HDS-4170
👀 Component checklist
💬 Please consider using conventional comments when reviewing this PR.