From ca10be754ce88d8662a161f0c09480f0221b1a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20Ho=C3=A0ng=20T=C3=BA?= Date: Sun, 29 Mar 2026 08:35:49 +0700 Subject: [PATCH] fix(cli): remove @o2s/framework references from .storybook/main.ts during scaffold --- .../create-o2s-app/src/scaffold/cleanup.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/cli/create-o2s-app/src/scaffold/cleanup.ts b/packages/cli/create-o2s-app/src/scaffold/cleanup.ts index 4d0649aa8..a11da95c7 100644 --- a/packages/cli/create-o2s-app/src/scaffold/cleanup.ts +++ b/packages/cli/create-o2s-app/src/scaffold/cleanup.ts @@ -2,6 +2,28 @@ import { ALWAYS_REMOVE_DIRS, ALWAYS_REMOVE_FILES } from '../constants'; import * as fs from 'fs-extra'; import * as path from 'path'; +/** + * Removes @o2s/framework references from .storybook/main.ts after scaffolding. + * The packages/framework directory is always removed, so these aliases and + * optimizeDeps entries would cause Storybook to fail. + */ +const cleanStorybookConfig = async (projectDir: string): Promise => { + const configPath = path.join(projectDir, '.storybook', 'main.ts'); + if (!(await fs.pathExists(configPath))) return; + + let content = await fs.readFile(configPath, 'utf-8'); + + // Remove @o2s/framework lines from optimizeDeps.include + content = content.replace(/\s*'@o2s\/framework\/modules',?\n?/g, ''); + content = content.replace(/\s*'@o2s\/framework\/sdk',?\n?/g, ''); + + // Remove @o2s/framework alias lines from resolve.alias + content = content.replace(/\s*'@o2s\/framework\/sdk':.*\n/g, ''); + content = content.replace(/\s*'@o2s\/framework\/modules':.*\n/g, ''); + + await fs.writeFile(configPath, content, 'utf-8'); +}; + export const cleanupProject = async (projectDir: string): Promise => { console.log('Organizing project structure...'); @@ -18,4 +40,7 @@ export const cleanupProject = async (projectDir: string): Promise => { await fs.remove(fullPath); } } + + // Clean storybook config after removing framework directory + await cleanStorybookConfig(projectDir); };