[Infra] Storybook aliases are maintained twice by hand — generate both blocks from one table
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 1.1k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 687
Description
## Problem
`apps/storybook/.storybook/main.ts` maintains the workspace source aliases **twice**, by hand:
- the StyleX `aliases` config (~line 82)
- Vite's `resolve.alias` (~line 124)
Adding a workspace package means remembering both. #5092 was exactly this drift: `@astryxdesign/richtext` was missing from both blocks while `apps/storybook/tsconfig.json` already mapped it to source, so typecheck and dev disagreed and `storybook dev` failed its dependency scan in any worktree without `packages/richtext/dist`.
#5100 fixed the instance and added a guard test. This issue is about removing the class.
## Current state, after #5100
| Package | StyleX `aliases` | Vite `resolve.alias` |
| --- | --- | --- |
| core, lab, charts, richtext | `/*` + bare → `src` | bare → `src` |
| theme-neutral, theme-stone, theme-y2k | `/*` only → `src/*` | bare → `src/source.ts` |
| vega | — | bare → `src` |
The asymmetries are **legitimate, not debt**: themes need a different entry per consumer, and `packages/vega/src` contains zero `@stylexjs/stylex` imports, so it correctly has no StyleX entry. Any dedup has to preserve all three shapes.
## Proposal
Derive both blocks from one declarative table, e.g.:
```ts
const workspaceAliases = [
{pkg: '@astryxdesign/core', src: 'packages/core/src', stylex: 'both'},
{pkg: '@astryxdesign/richtext', src: 'packages/richtext/src', stylex: 'both'},
{pkg: '@astryxdesign/theme-neutral', src: 'packages/themes/neutral/src',
vite: 'packages/themes/neutral/src/source.ts', stylex: 'wildcard'},
{pkg: '@astryxdesign/vega', src: 'packages/vega/src', stylex: 'none'},
// …
];
```
with the two blocks generated from it. A new package becomes one row that cannot be half-added.
## Knock-on: the guard test
`apps/storybook/.storybook/main.test.ts` (added in #5100) asserts alias keys by **string matching** `main.ts`, scoped to the Vite block via `mainTs.slice(mainTs.indexOf('alias: {'))`. Two consequences:
- Generating the blocks would break that slice — the test must be reworked in the same PR.
- It watches the Vite block only, so removing a StyleX alias keeps it green (verified). Deliberate: a symmetric assertion would go red on vega's legitimately-absent entry.
A single table makes both problems moot — the invariant becomes structural instead of asserted, and the table can be exported and asserted against `package.json` directly.
The stronger version (import the config, call `viteFinal`, inspect resolved aliases) is blocked on #5128 — it cannot run in a fresh worktree today.
## Not urgent
Nothing is broken right now. This is drift-proofing the config so the next workspace package can't repeat #5092.
Contributor guide
Assessment
This issue has not been assessed yet.