fix font export#3928
Conversation
🦋 Changeset detectedLatest commit: 440b886 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 |
|
|
There was a problem hiding this comment.
Pull request overview
This PR aims to fix font-related exports by improving how font-family/font-weight token values are normalized when they arrive in “array-shaped string” formats (e.g. ["Arial","Helvetica"]) so that Figma variables receive a single usable string value.
Changes:
- Update
setValuesOnVariableto detect font family/weight “array-shaped string” values and extract the first entry before setting string variables. - Update
convertFontFamilyToFigmato strip surrounding brackets from array-shaped font-family strings before splitting and selecting the first family.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/tokens-studio-for-figma/src/plugin/setValuesOnVariable.ts | Extract first entry from array-shaped font family/weight values before writing to STRING variables. |
| packages/tokens-studio-for-figma/src/plugin/figmaTransforms/convertFontFamilyToFigma.ts | Strip [/] from bracketed font-family strings before splitting to avoid returning "[Arial"-style results. |
|
Commit SHA:885e339cb9dde1424b49721ce135a2aa0dffb309 Test coverage results 🧪
|
|
Commit SHA:885e339cb9dde1424b49721ce135a2aa0dffb309 |
Code Review: PR-3928Effort: max · Scope: 1. FONT_WEIGHTS parity gap — same bug still present
|
| # | Severity | Action |
|---|---|---|
| 1 | High — real user-visible bug on the sibling code path | Fix before merge |
| 2 | Medium — dead code + false-signal test | Fix before merge, or file follow-up |
| 3 | Low — narrow edge case | Fix in this PR (one-liner) |
| 4 | Low — behavior change, undocumented | Decide + add test |
| 5 | Low — pre-existing, but PR's context makes it newly relevant | Follow-up PR OK |
Code Review: PR-3928Effort: max · Scope: 1. FONT_WEIGHTS parity gap — same bug still present
|
| # | Severity | Action |
|---|---|---|
| 1 | High — real user-visible bug on the sibling code path | Fix before merge |
| 2 | Medium — dead code + false-signal test | Fix before merge, or file follow-up |
| 3 | Low — narrow edge case | Fix in this PR (one-liner) |
| 4 | Low — behavior change, undocumented | Decide + add test |
| 5 | Low — pre-existing, but PR's context makes it newly relevant | Follow-up PR OK |
|
🛡️ Hyma Compliance Check ✅ No compliance-relevant changes detected 7 file(s) scanned · 0 findings
|
|
🛡️ Hyma Compliance Check ✅ No compliance-relevant changes detected 3 file(s) scanned · 0 findings
|
|
🛡️ Hyma Compliance Check ✅ No compliance-relevant changes detected 7 file(s) scanned · 0 findings
|
Why does this PR exist?
Font-family tokens resolved by the Tokens Studio server (Rails/gRPC path) come through as an array-shaped string — e.g.
'["Arial","Helvetica","sans-serif"]'. On Export to Variables, that string was being written to the Figma variable as the literal[Arial, becauseconvertFontFamilyToFigmasplit by,and stripped quotes without ever removing the surrounding brackets. Font-weights had the same latent issue viaconvertFontWeightToFigma.What does this pull request do?
convertFontFamilyToFigma— strips surrounding[...]before splitting. For JSON-shaped arrays (["A","B"]) triesJSON.parsefirst so quoted family names containing commas (["Font, Name","Arial"]→Font, Name) survive; falls back to a split for single-quoted / unquoted bracket lists.convertFontWeightToFigma— mirrors the bracket-strip so server-form'["Bold","Regular"]'no longer flows through untouched.setValuesOnVariable— STRING case simplified. Normalization now lives in the transform functions (right altitude), so the switch only needs a plain-string branch plus the array branch. Numeric-array coercion viaString()is kept as a belt-and-suspenders safety net.Testing this change
["Arial","Helvetica","sans-serif"]-shaped value).Arial(previously[Arial).yarn jest --testPathPattern="convertFontFamilyToFigma|fontWeight\.test|setValuesOnVariable"— 40 tests across 4 suites pass, including new coverage for JSON, single-quoted, and unquoted bracket forms plus the comma-in-quoted-name case.Additional Notes (if any)
Addresses Copilot review comments (silent JSON parse, added tests for both transforms) and follow-up ultra-review findings (fontWeights parity gap, dead JSON-string branch in
setValuesOnVariable,"[]"literal write, comma-in-quoted-name).