Skip to content

build(ui-scripts): fix changed token/theme parsing to follow the new design token structure#2561

Open
HerrTopi wants to merge 4 commits into
masterfrom
change-to-semantic
Open

build(ui-scripts): fix changed token/theme parsing to follow the new design token structure#2561
HerrTopi wants to merge 4 commits into
masterfrom
change-to-semantic

Conversation

@HerrTopi
Copy link
Copy Markdown
Contributor

@HerrTopi HerrTopi commented May 18, 2026

Summary

Brings InstUI's token build in line with the new design-token structure and adds runtime support for color modifiers.

Token parsing fixes (ui-scripts)

  • Token references in the new structure already carry the semantic. prefix, so formatReference no longer prepends semantics.. Param name in generated component files renamed semantics → semantic to match.
  • Multi-file semantic token sets now merge via mergeDeep instead of shallow spread, so nested keys from different files no longer clobber each other. mergeDeep is inlined into generateSemantics.ts rather than imported from @instructure/ui-utils, because build scripts need to run before workspace packages are compiled.

Bootstrap design-token refresh

  • scripts/bootstrap.js now refreshes @instructure/instructure-design-tokens from its GitHub source before building themes, so a clean bootstrap doesn't reuse a stale tarball.
  • Scoped via pnpm --filter @instructure/ui-scripts update … (only ui-scripts declares the dep) to avoid the workspace-wide lockfile churn that pnpm update -r was causing.

Color modifiers (emotion, ui-scripts)

  • New applyColorModifiers util in packages/emotion resolves Tokens Studio darken / lighten modifiers in HSL space, matching Studio's space: "hsl" math (each step is a fraction of the remaining distance to black/white, so it never overshoots).
  • Wired into both useStyleNew and withStyleNew so any component theme entry shaped as { value, modify: { type, value } } is collapsed to a final color string before reaching the component.
  • generateComponents.js now preserves the $extensions["studio.tokens"].modify payload through the token build instead of dropping it, so the modifier metadata actually reaches the runtime.

Theme type generation refactor

  • Generated per-component theme files no longer carry an explicit return type or import their type from componentTypes/; the function is emitted untyped and consumers rely on the aggregate ComponentTypes shape. Reduces cross-file coupling in the generated output.

Test plan

  • pnpm run bootstrap succeeds end-to-end on a clean checkout; only ui-scripts-related entries change in pnpm-lock.yaml.
  • Spot-check a generated component file under packages/ui-themes/src/themes/*/components/ — signature is (semantic: Semantics) and body references resolve against semantic.*, not semantics.*.
  • Spot-check a generated semantics.ts for at least one theme — values that come from multiple token files are all present (verifies the deep-merge fix).
  • Spot-check a component whose theme uses a darken / lighten modifier (e.g. a hover/active state) — at runtime, the resolved CSS shows an hsl(…) / hsla(…) color rather than a { value, modify } object, and the shade matches what Tokens Studio renders for the same token.
  • pnpm run ts:check passes.
  • pnpm run dev boots the docs app and components using semantic tokens (e.g. Button) render with correct theming, including any states that rely on color modifiers.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://instructure.design/pr-preview/pr-2561/

Built to branch gh-pages at 2026-05-21 17:35 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

github-actions Bot pushed a commit that referenced this pull request May 18, 2026
@github-actions
Copy link
Copy Markdown

Visual regression report

No changes.

Status Count
Unchanged 32
Changed 0
New 0
Removed 0

📊 View full report

Baselines come from the visual-baselines branch. They refresh on every merge to master.

Comment thread scripts/bootstrap.js Outdated
function buildProject() {
console.info('Fetching design tokens...')
try {
execSync('pnpm update @instructure/instructure-design-tokens -r', opts)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has an unintended side effect of updating all peer dependencies too, this takes a long time and results in unrelated pnpm-lock.yaml changes. AI recommends to use pnpm --filter @instructure/ui-scripts add @instructure/instructure-design-tokens@github:instructure/instructure-design-tokens, but please double check

@HerrTopi HerrTopi force-pushed the change-to-semantic branch from 8e354cf to d196368 Compare May 21, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants