Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(storybook): resolve @astryxdesign/richtext from source in dev (#5100)

Jiun Shin7c8623154c48
diff --git a/apps/storybook/.storybook/main.test.ts b/apps/storybook/.storybook/main.test.ts
new file mode 100644
index 0000000000..5425eddfb2
--- /dev/null
+++ b/apps/storybook/.storybook/main.test.ts
@@ -0,0 +1,45 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file main.test.ts
+ * @description Guards the workspace source-alias invariant in Storybook's
+ * Vite config. Every `@astryxdesign/*` dependency of this app must be
+ * aliased to package source in `.storybook/main.ts`. Without an alias,
+ * Vite resolves the workspace link through the package's export map,
+ * which points at `dist/` build output that does not exist in a fresh
+ * worktree — `storybook dev` then fails its dependency scan (#5092:
+ * `@astryxdesign/richtext`).
+ */
+
+import {describe, it, expect} from 'vitest';
+import {readFileSync} from 'node:fs';
+import path from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+
+const mainTs = readFileSync(path.join(__dirname, 'main.ts'), 'utf8');
+const pkg = JSON.parse(
+ readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'),
+) as {dependencies?: Record<string, string>};
+
+// The Vite `resolve.alias` block only — the StyleX `aliases` block above it
+// carries the same keys but does not drive Vite's dev-mode resolution.
+const viteAliasBlock = mainTs.slice(mainTs.indexOf('alias: {'));
+
+const workspaceDeps = Object.keys(pkg.dependencies ?? {}).filter(name =>
+ name.startsWith('@astryxdesign/'),
+);
+
+describe('storybook main.ts workspace source aliases', () => {
+ it('sees the @astryxdesign workspace dependencies', () => {
+ expect(workspaceDeps).not.toHaveLength(0);
+ });
+
+ it.each(workspaceDeps)('aliases %s to source', dep => {
+ // Each workspace dependency must appear as a bare alias key in Vite's
+ // `resolve.alias` so dev-mode resolution never falls back to the export
+ // map's dist/ entry point, which is missing until the package is built.
+ expect(viteAliasBlock).toContain(`'${dep}':`);
+ });
+});
diff --git a/apps/storybook/.storybook/main.ts b/apps/storybook/.storybook/main.ts
index fdc0e8bcc8..0b03da91fe 100644
--- a/apps/storybook/.storybook/main.ts
+++ b/apps/storybook/.storybook/main.ts
@@ -92,6 +92,12 @@ const config: StorybookConfig = {
'@astryxdesign/charts': [
path.join(rootDir, 'packages/charts/src'),
],
+ '@astryxdesign/richtext/*': [
+ path.join(rootDir, 'packages/richtext/src/*'),
+ ],
+ '@astryxdesign/richtext': [
+ path.join(rootDir, 'packages/richtext/src'),
+ ],
'@astryxdesign/theme-neutral/*': [
path.join(rootDir, 'packages/themes/neutral/src/*'),
],
@@ -120,6 +126,10 @@ const config: StorybookConfig = {
'@astryxdesign/core': path.resolve(rootDir, 'packages/core/src'),
'@astryxdesign/lab': path.resolve(rootDir, 'packages/lab/src'),
'@astryxdesign/charts': path.resolve(rootDir, 'packages/charts/src'),
+ '@astryxdesign/richtext': path.resolve(
+ rootDir,
+ 'packages/richtext/src',
+ ),
'@astryxdesign/theme-neutral': path.resolve(
rootDir,
'packages/themes/neutral/src/source.ts',
diff --git a/vitest.config.ts b/vitest.config.ts
index b570cf55dd..a4bae7c583 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -142,6 +142,9 @@ export default defineConfig({
'internal/**/*.test.{ts,tsx,mjs}',
'scripts/**/*.test.{ts,tsx,mjs}',
'.github/scripts/**/*.test.{ts,tsx,mjs}',
+ // Storybook config invariants (no DOM needed) — e.g. the
+ // workspace source-alias guard in .storybook/main.test.ts.
+ 'apps/storybook/.storybook/**/*.test.{ts,tsx,mjs}',
],
exclude: [
...configDefaults.exclude,