Skip to content

feat(gamut-codemods): add a color-roles preset - #53

Open
dreamwasp wants to merge 86 commits into
mainfrom
cass-gmt-1825-color-codemod
Open

dreamwasp wants to merge 86 commits into
mainfrom
cass-gmt-1825-color-codemod

Conversation

@dreamwasp

@dreamwasp dreamwasp commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Adds a color-roles preset that moves Gamut color names onto the generated system's roles, using design's migration map. Presets can now have their own manifest, pre-filter and leftovers report; scope-swap's behavior is unchanged.

Framework

  • lib/types.ts, lib/run-source.ts, presets/index.ts — Preset<M> and the migration types are generic over their manifest, defaulting to scope-swap's. A preset brings its own mentions pre-filter and an optional leftovers report.
  • cli.ts, transform.ts, presets/scope-swap — call those hooks; scope-swap passes the pre-filter and leftovers report the CLI used to call directly.
  • __tests__/manifest.test.ts, fixtures.test.ts — the export check covers manifests that promise exports; end-to-end fixtures for other presets live in __tests__/__testfixtures__/<preset>/.

color-roles

  • migrations/color-roles — one splice migration. Rename and merge rows are applied. Split, retired and pending names stay (they still fail the type check), with a /* color-roles: … */ comment carrying design's rule and a warning. Old palette names and runtime-built names (${variant}-hover) only warn.
  • Positions: the ten color props in JSX and style objects (ternaries, &&, responsive values), theme.colors.x / ['x'], themed('colors.x'). variant="primary" and other look-alike strings are left alone.
  • presets/color-roles — the manifest (32 aliases, 45 roles, 104 old palette names), a leftovers report of unresolved color-roles: comments, the checklist. aliases.ts is generated from gamut-styles colorSystem/migration.ts.

Tests and docs

  • Three fixture cases (JSX, style objects, manual kinds), each checked for idempotence, and color-roles-manifest.test.ts: every applied row names exactly one real role.
  • README.md — running color-roles, what it changes, its limits.

PR Checklist

  • Related to designs: gamut-sandbox PR #34 (migration map at c363244)
  • Related to JIRA ticket: GMT-1825
  • Changeset added (or empty changeset if no release)
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions for the code change
  • Package previews from this PR are passing end-to-end tests in all relevant consuming repositories

Testing Instructions

  1. yarn nx test gamut-codemods → 136 tests pass.

  2. yarn nx build gamut-codemods, then node packages/gamut-codemods/dist/bin.js list → color-roles is listed.

  3. Dry run over gamut: node packages/gamut-codemods/dist/bin.js color-roles packages/gamut/src --dry. On feat(gamut-styles)!: brands, overrides and Original Codecademy on the color system #52's branch: 60 files, 171 warnings, 0 errors.

  4. For real, on a scratch copy: run it twice. The second run changes nothing. On feat(gamut-styles)!: brands, overrides and Original Codecademy on the color system #52's branch, gamut's type errors go from 284 to 145.

  5. Check out https://github.skillsoft.com/skillsoft-common/gamut-sandbox/pull/53 which combines all of the current PRs and runs this codemod

  6. Dry run over a real app with build output: node packages/gamut-codemods/dist/bin.js color-roles <app> --dry on cc/mono → no hits under .next/, and no errors.

Fixes from the mono dry run

A dry run of color-roles on cc/mono reported 7 errors, and its hits included build output. Before this commit, the source run skipped only node_modules, dist and build.

  • Build output. Six of the seven errors were parse failures on .next/ chunks, and the scan read minified bundles. The source run now uses the same skip list as the file walk (node_modules, dist, build, coverage, .next, .nx, tmp, .git). Result on mono: no hits under .next/; ok files 833 → 635.
  • The seventh error. apps/reverse-proxy-worker/worker-configuration.d.ts is a tracked, generated Cloudflare types file. Its quoted 'text' (a KV type argument) passed the pre-filter, and Babel rejects export { _EmailMessage as EmailMessage } inside declare module. Generated files are now skipped by name (GENERATED_FILES: worker-configuration.d.ts, next-env.d.ts) in the source run and the file walk. Result on mono: 0 errors, 635 ok.
  • tsconfig-dom warnings now fire only for a tsconfig whose directory imports gamut. Three of the five it reported (enterprise-data-worker, reverse-proxy-worker, le-container-scripts) import no gamut.
  • Left as they were: next-config (its four apps import gamut, so the flag is real); the four stylesheet hits under libs/le-shared (tracked source); and scope-swap (no-op on mono). No resolutions block is added: the README's preview step stays the user's job.
  • Not done: the [color-roles] warnings are still one per occurrence (1,738 on mono). Grouping them is a follow-up.

Known gap: aliases.ts is a generated copy of design's map, and the generator (gen-manifest.ts) still lives outside the repo, because this branch and #50 don't share gamut-styles yet. It should move in and read the workspace package once they do.

🤖 Generated with Claude Code

dreamwasp and others added 30 commits October 20, 2026 10:07
…eset

Adds @skillsoft/gamut-codemods: the CLI (clean-tree guard, --dry, --only,
--no-report, --force), the runner for ast, splice, and file migrations,
the shared helpers (module-string finder, leftovers report, version-range
checks, flat ESLint config detection), the preset registry, and the
fixture harness.

The scope-swap preset has its package map but no migrations yet, so a run
only reports the lines that still name an old package. Each breaking
change lands its migration in its own PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…swap

scope-rename swaps @Codecademy/gamut* and eslint-plugin-gamut for their
@SkillSoft names in every module position and in comments. package-json,
mdx-imports, and yarnrc cover dependencies, MDX ESM blocks, and
.yarnrc.yml lists.

@codecademy/gamut-kit has no replacement, so package-json and mf-shared
expand it into the packages it bundled. In Module Federation config that
makes Gamut a real singleton, which the checklist calls out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ides

moved-exports moves Video and VideoProps from the root to
@Codecademy/gamut/Video (scope-rename then swaps the scope).
markdown-video-overrides adds explicit iframeOverride/videoOverride to
each <Markdown>, since it no longer renders video through Video by
default, and drops the removed skipDefaultOverrides keys. tsconfig-dom
warns about tsconfigs without "dom", which Video used to supply.

On the Gamut side, a Video/package.json stub makes the subpath resolve
under node10, MarkdownVideo no longer passes NaN sizes, and a one-line
<video> is no longer wrapped in a <p>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ectDropdown elements

Exports formFieldStyles, formFieldPaddingStyles, conditionalStyles,
ButtonBaseProps, HTMLToReactNode, MenuToolTipWrapper, and Menu's list
elements from the root. The list elements and SelectDropdown's option
component are renamed (MenuList*, MenuListButton, IconOptionComponent) so
they don't collide with the public List component and IconOption type.

The deep-imports codemod rewrites known /dist/ paths to the root, keeps
local names across renames, merges into existing imports, and warns on
paths with no public replacement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eslint-comments rewrites gamut/ directives to @skillsoft/gamut/, and
eslint-config updates the plugin name, plugin: extends, and rule keys in
legacy .eslintrc files. Under a flat config the prefix is the plugins key,
so eslint-comments skips itself and the checklist explains why.

Also types eslint-plugin-gamut's recommended severities as literals, so the
plugin fits ESLint's Plugin type in a typed flat config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@skillsoft/gamut ships strict-ESM .mjs. With experimental.esmExternals
off, Next require()s server externals and default imports from
@emotion/styled and react-select break while it collects page data.
next-config is report-only: dropping the flag can take other config with
it, so it warns and adds a checklist item instead of rewriting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ap-skill

# Conflicts:
#	packages/gamut-codemods/README.md
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
# Conflicts:
#	packages/gamut-codemods/README.md
#	packages/gamut-codemods/src/__tests__/lib.test.ts
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
…p-skill

# Conflicts:
#	packages/gamut-codemods/README.md
#	packages/gamut-codemods/src/__tests__/cli.test.ts
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
The skill works alongside the scope-swap codemod: it reads the warnings,
leftovers, and next steps, and helps with what the codemod can't rewrite.
BREAKING_CHANGES.md lists every change in the move, and
NEXT_EMOTION_INTEROP.md covers the Next.js esmExternals fallback.

Also restores the end-to-end and MDX fixtures that run every migration
together, and fixes the cli.test merge between the sibling branches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeQL read `migration.match(file)` in cli.ts as String.prototype.match
on a command-line argument and flagged js/regex-injection. Nothing builds
a regex from the path; the method just had the same name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…migrations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…migrations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…migrations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…migrations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The package-json warning already names each range that's newer than the
fork point, so the extra next step only repeated it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rkdown

# Conflicts:
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
# Conflicts:
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
# Conflicts:
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
…swap-skill

# Conflicts:
#	packages/gamut-codemods/src/presets/scope-swap/index.ts
dreamwasp and others added 17 commits November 18, 2026 14:52
- scope-swap manifest gains requiredPeers: @vidstack/react and react-player for @skillsoft/gamut, stylis for @skillsoft/gamut-styles. package-json adds any that an app needs and doesn't list, at the range the package declares. manifest.test checks each range against the source package.json.
- The CoreTheme comment and warning no longer tell every app to use SkillsoftTheme. It is the type for brand themes; the theme stays a per-app choice because it changes the spacing scale.
- Changeset notes the peers and the spacing-scale difference between themes.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…re used

- Old palette names get a color-roles: comment in front of the site, not only a terminal warning, so the review queue is in the code and the leftovers report lists it. Stylesheet hits and runtime-built names follow the same rule.
- The message names the context: the prop, the style key, a theme.colors or themed() lookup, or a CSS variable. The same palette name is a fill in one place and text in another.
- The comment uses the plain name, not --color-<name>, so a second run doesn't match the marker's own text as an old variable.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…ion skill

- next-config: removing esmExternals: false is necessary but not always enough. Build each app and fix the routes that still fail at prerender.
- CI: the job that runs sync-gamut-deps fails too, so change it with the script.
- resolutions: yarn why can list two lock locators after a pin, with one copy installed. Check node_modules.
- tsconfig-dom: the codemod warns only where gamut is imported.
- Missing peers: @vidstack/react, react-player and stylis, with the range to add by hand.
- color-roles: a palette name can map to different roles by slot, so use the context in the comment. Keep each app's theme, since the choice changes the spacing scale.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit a0f18dc)
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…lette names

- decisions.ts holds the defaults, outside the generated alias table: red becomes an error role and green a success role by use (fill, text, border); white becomes surface-raised, text-inverse or border-subtle; navy takes the nearest role by brightness in each family. Dark navy fills stay warnings for design.
- A default is applied only in a color prop, where the use is known. Theme lookups and CSS variables are still warned.
- Bare white joins the palette list, since it's the most common white use.
- Tests: each default names a role the system has, and unknown uses fall back to a warning.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…gration skill

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit bb684b9)
…igration skill

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit b35dc09)
Hyper is the old primary, so fills, text and borders take action-primary. Yellow stays a warning, since its role depends on the brand.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
blue-500 is admin's light-mode primary. Its text is links and focus, so it takes action-primary. Fills and borders mix interactive and decorative uses, so they stay warnings.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
… skill

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit 552d148)
…ser in the gamut-migration skill

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit 7d92c95)
The greys are neutral, so a brightness match would make mid-grey text light ink. Fills follow lightness, grey text is text-subtle, and borders follow weight. Light grey text stays a warning.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…ate-stylis symptom

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit 0dc47cf)
@emotion/cache brings its own stylis. The root copy the codemod added can sit at a different version from emotion's, and a duplicate is suspected to break style inserts (reading 'push'). The codemod now adds only @vidstack/react and react-player.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…t import Video

Those two peers only load for Video, so package-json adds them when the source imports Video from gamut (through the Video subpath, or a Video name from the root). Apps that don't use Video don't get them. The context is memoized per directory, like usesGamut.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
(cherry picked from commit 53cce61)
Moved tests follow main's colocated layout. The codemod suite passes (151 tests).

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
dreamwasp added a commit that referenced this pull request Nov 20, 2026
Replaces this branch's tree with the color stack as it now stands: the
site branch (#67, which includes #63, #59, #54, #66, #58, #52 and #50,
each merged with main through 45586df), plus the codemod branch (#53).
Static styles (#69) is still out, as before.

The preview's earlier head is the parent. This commit only moves the
tree forward, so nothing is rewritten.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
dreamwasp and others added 8 commits November 20, 2026 11:34
The deep-import checks build a TypeScript program over the built packages.
They take about 1s alone, but ran past the 15s limit in CI, where nx runs the
package tests in parallel on a cold cache.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
yellow-0 fills become surface-warning and bare yellow or yellow-900 text
becomes text-warning, as the old core theme uses them. yellow-400 and
yellow-500 are the accent and stay for a person.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
ColorMode belongs at the top of the app or page. Surfaces that paint their
own color use Background, which picks the mode by contrast. Nested
ColorMode is the exception and needs a reason. Updates the card navy note
to match.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…variables

color-roles applied palette defaults only in color props, because a
theme lookup or CSS variable didn't say what the color was for. It now
reads that from the CSS property or style key the value belongs to:
`background-color: ${theme.colors['navy-100']}` becomes surface-default,
`{ color: 'var(--color-red)' }` becomes text-error, in JS and in
stylesheets. A color inside a function (gradient, rgba) or under a
property that isn't a fill, text or border still gets a comment, which
now names the property.

Theme lookups are also found through useTheme(), a variable holding
theme.colors, `colors` destructured from the theme, and keys
destructured from theme.colors. Bindings are matched by scope, so an
imported `colors` is left alone.

Dark navy fills (navy, navy-700, navy-800) still need a person. Their
comment now gives design's rule: the area becomes dark mode with
<ColorMode mode="dark" bg="surface-default">. The migration skill says
the same, and uses Background only where the color decides the mode.

On mono's pre-color commit, palette theme-lookup warnings drop from 424
to 223 and total warnings from 1,448 to 1,232.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esolves the name

A run with newer defaults rewrites names an older run only marked, but
left the old `color-roles:` comment in front of the new role, where the
leftovers report still listed it. A replacement now removes the comment
for that name at that site: in theme lookups, props, JS strings (once
nothing in the literal is left open) and stylesheets. A comment for a
different name stays.

Reading the CSS property also skips comments now, so an old comment
inside a stylesheet value (`color: /* color-roles: … */ var(…)`) no
longer hides the property.

On mono's color-codemod-tip, migrated with an earlier build, the open
comments drop from 1,214 to 1,030.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd action-disabled

Synced to design's migration map of 2026-12-01. A disabled field drops
to `surface-sunken` with an `action-disabled` outline, label and value,
so `border-disabled` is no longer a plain rewrite to `border-default`:
the codemod leaves a comment naming both targets. The `text-disabled`
comment now says a disabled field's value is `action-disabled`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
to: ['border-subtle', 'border-strong'],
rule: 'A divider or card hairline is `border-subtle`. Where it marks an active field or a selected row, it is `border-strong`. Gamut’s own two usages, the FeatureShimmer edge and the List scroll shadow, are both `border-subtle`. Core resolves it to a light navy and Percipio to a dark one, so check each app usage for which it meant.',
},
'border-disabled': {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Design's sandbox update, 2026-12-01: border-disabled is a split now, not a merge. A disabled field's outline is action-disabled, and a control with a disabled fill keeps border-default. So the codemod no longer rewrites it to border-default; it leaves a comment naming both (new case in the manual fixture). The text-disabled comment changes to match: a disabled field's value is action-disabled.

dreamwasp added a commit that referenced this pull request Dec 2, 2026
…date

Brings in the stack through #67 (2d73ebf) and #53 (a16e5a3):

- Disabled fields fill with surface-sunken and draw their outline,
  label, value and chevron in action-disabled; enabled chevrons are
  text-default (#52 map, #54 components, DatePicker included).
- border-disabled splits between border-default and action-disabled in
  the color-roles codemod (#53).
- The color system page's role table lists disabled fields (#59), and
  the docs site loads the Skillsoft theme fonts (#67).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant