-
Notifications
You must be signed in to change notification settings - Fork 50
[07-C] [Project Solar / Phase 1 / Engineering Follow-ups] Improve validation for $modes
#3397
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
base: project-solar/phase-1/HDS-5202-5203-5204/dry-run-foundations
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import StyleDictionary from 'style-dictionary'; | |
| import type { DesignToken, PlatformConfig } from 'style-dictionary/types'; | ||
|
|
||
| import tinycolor from 'tinycolor2'; | ||
| import chalk from 'chalk'; | ||
|
|
||
| import fs from 'fs-extra'; | ||
| import path from 'path'; | ||
|
|
@@ -42,10 +43,14 @@ for (const mode of modes) { | |
| function replaceModes(slice: DesignToken) { | ||
| if (slice.$modes) { | ||
| if (mode in slice.$modes) { | ||
| // extra validation to catch instances where the `default` mode value is different from the `$value` | ||
| if (mode === 'default' && slice.$modes[mode] !== slice.$value) { | ||
| console.warn(`โ ๏ธ ${chalk.yellow.bold('WARNING')} - Found themed 'default' token with value different than '$value' (\`${slice.$modes[mode]}\` instead of the expected \`${slice.$value}\`) - File: ${slice.filePath}`); | ||
| } | ||
| slice.$value = slice.$modes[mode]; | ||
| } else { | ||
| // TODO! decide if we want to throw here (and test if it works, by removing a value from one of the test files) - see: https://hashicorp.atlassian.net/browse/HDS-5668 | ||
| console.error(`โ ERROR - Found themed token without '${mode}' value:`, JSON.stringify(slice, null, 2)); | ||
| // we want to interrupt the execution of the script if one of the expected modes is missing | ||
| throw new Error(`โ ${chalk.red.bold('ERROR')} - Found themed token without '${mode}' value - ${JSON.stringify(slice, null, 2)}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using file: packages/tokens/src/products/shared/typography.json I tried deleting one of the |
||
| } | ||
| } else { | ||
| Object.values(slice).forEach((value) => { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Using file: packages/tokens/src/products/shared/typography.json
On line 158, I tested changing the font-weight regular $value to "900" so that it no longer matched the $modes default value of "400" then ran
pnpm build.I saw a warning as expected, but it was repeated twice:
I tested again, changing another value and was also seeing a duplicated warning.