fix: resolve mode-specific baseFontSize for rem scaling in variable e…#3836
fix: resolve mode-specific baseFontSize for rem scaling in variable e…#3836akshay-gupta7 wants to merge 4 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: e19baf1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
|
Commit SHA:2fa1b4cf4417baf2d38ba09a8d277fbb32165bf5 Test coverage results 🧪
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
There was a problem hiding this comment.
Pull request overview
This PR updates the Figma plugin variable export flow to correctly resolve a theme/mode-specific baseFontSize (including when alias resolution yields a numeric result) so rem/em scaling is computed correctly per mode.
Changes:
- Allow
settings.aliasBaseFontSizeto overridebaseFontSizewhengetAliasValuereturns either a string or a number. - Adjust variable setters to allow writing values when a mode has no existing value (instead of returning early).
- Add/extend Jest tests for numeric alias results and per-mode base font size behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/tokens-studio-for-figma/src/plugin/updateVariables.ts | Accept numeric alias-resolved base font sizes and apply per-theme base font size during variable mapping/export. |
| packages/tokens-studio-for-figma/src/plugin/updateVariables.test.ts | Adds tests for numeric baseFontSize alias results and mode-specific baseFontSize handling. |
| packages/tokens-studio-for-figma/src/plugin/setStringValuesOnVariable.ts | Updates early-return logic so unset modes can be written to. |
| packages/tokens-studio-for-figma/src/plugin/setNumberValuesOnVariable.ts | Updates early-return logic so unset modes can be written to. |
| packages/tokens-studio-for-figma/src/plugin/setColorValuesOnVariable.ts | Updates early-return logic so unset modes can be written to. |
| packages/tokens-studio-for-figma/src/plugin/setBooleanValuesOnVariable.ts | Updates early-return logic so unset modes can be written to. |
…xport
Why does this PR exist?
Closes #3800
This PR addresses issues with
baseFontSizeresolution when exporting variables to Figma. Previously, numeric or aliased font sizes (especially those involving math evaluation) were not correctly handled during per-mode exports, leading to inconsistent scaling across different modes in the same collection.What does this pull request do?
baseFontSizeResolution: UpdatedupdateVariables.tsto correctly handlenumbertypes and evaluate aliases forbaseFontSize, ensuring consistent string conversion.setStringValuesOnVariable.tsthat was preventing some existing variable values from being updated correctly.updateVariables.test.tsto use isolated variable mocks, ensuring that scaling validation is accurate and free from side effects of shared mocks.Testing this change
baseFontSizeis set (either as a numeric value or an alias like{typography.baseline}).remvalues (e.g.,1remspacing) are correctly translated to pixels based on the specificbaseFontSizedefined for each theme/mode.Automated Tests:
Run the updated test suite:
yarn test src/plugin/updateVariables.test.tsAdditional Notes (if any)
The test mock isolation was necessary because
base/font-sizeand other variables were sharing the samesetValueForModemock, which could hide bugs where specific variables weren't being updated.