-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
CLI: Fix issue with running Storybook after being initialized #32929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,8 @@ import { telemetry } from 'storybook/internal/telemetry'; | |||||||||||||
|
|
||||||||||||||
| import boxen from 'boxen'; | ||||||||||||||
| import * as find from 'empathic/find'; | ||||||||||||||
| // eslint-disable-next-line depend/ban-dependencies | ||||||||||||||
| import execa from 'execa'; | ||||||||||||||
| import picocolors from 'picocolors'; | ||||||||||||||
| import { getProcessAncestry } from 'process-ancestry'; | ||||||||||||||
| import prompts from 'prompts'; | ||||||||||||||
|
|
@@ -807,45 +809,56 @@ export async function initiate(options: CommandOptions): Promise<void> { | |||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| if (initiateResult?.shouldRunDev) { | ||||||||||||||
| const { projectType, packageManager, storybookCommand } = initiateResult; | ||||||||||||||
| logger.log('\nRunning Storybook'); | ||||||||||||||
| await runStorybookDev(initiateResult); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| const supportsOnboarding = [ | ||||||||||||||
| ProjectType.REACT_SCRIPTS, | ||||||||||||||
| ProjectType.REACT, | ||||||||||||||
| ProjectType.WEBPACK_REACT, | ||||||||||||||
| ProjectType.REACT_PROJECT, | ||||||||||||||
| ProjectType.NEXTJS, | ||||||||||||||
| ProjectType.VUE3, | ||||||||||||||
| ProjectType.ANGULAR, | ||||||||||||||
| ].includes(projectType); | ||||||||||||||
|
|
||||||||||||||
| const flags = []; | ||||||||||||||
|
|
||||||||||||||
| // npm needs extra -- to pass flags to the command | ||||||||||||||
| // in the case of Angular, we are calling `ng run` which doesn't need the extra `--` | ||||||||||||||
| if (packageManager.type === 'npm' && projectType !== ProjectType.ANGULAR) { | ||||||||||||||
| flags.push('--'); | ||||||||||||||
| } | ||||||||||||||
| /** Run Storybook dev server after installation */ | ||||||||||||||
| async function runStorybookDev(result: { | ||||||||||||||
| projectType: ProjectType; | ||||||||||||||
| packageManager: JsPackageManager; | ||||||||||||||
| storybookCommand?: string; | ||||||||||||||
| shouldOnboard: boolean; | ||||||||||||||
| }): Promise<void> { | ||||||||||||||
| const { projectType, packageManager, storybookCommand, shouldOnboard } = result; | ||||||||||||||
|
|
||||||||||||||
| if (!storybookCommand) { | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (supportsOnboarding && initiateResult.shouldOnboard) { | ||||||||||||||
| flags.push('--initial-path=/onboarding'); | ||||||||||||||
| } | ||||||||||||||
| try { | ||||||||||||||
| const supportsOnboarding = [ | ||||||||||||||
| ProjectType.REACT_SCRIPTS, | ||||||||||||||
| ProjectType.REACT, | ||||||||||||||
| ProjectType.WEBPACK_REACT, | ||||||||||||||
| ProjectType.REACT_PROJECT, | ||||||||||||||
| ProjectType.NEXTJS, | ||||||||||||||
| ProjectType.VUE3, | ||||||||||||||
| ProjectType.ANGULAR, | ||||||||||||||
| ].includes(projectType); | ||||||||||||||
|
|
||||||||||||||
| const flags = []; | ||||||||||||||
|
|
||||||||||||||
| // npm needs extra -- to pass flags to the command | ||||||||||||||
| // in the case of Angular, we are calling `ng run` which doesn't need the extra `--` | ||||||||||||||
| if (packageManager.type === 'npm' && projectType !== ProjectType.ANGULAR) { | ||||||||||||||
| flags.push('--'); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| flags.push('--quiet'); | ||||||||||||||
|
|
||||||||||||||
| // instead of calling 'dev' automatically, we spawn a subprocess so that it gets | ||||||||||||||
| // executed directly in the user's project directory. This avoid potential issues | ||||||||||||||
| // with packages running in npxs' node_modules | ||||||||||||||
| packageManager.runPackageCommandSync( | ||||||||||||||
| storybookCommand.replace(/^yarn /, ''), | ||||||||||||||
| flags, | ||||||||||||||
| undefined, | ||||||||||||||
| 'inherit' | ||||||||||||||
| ); | ||||||||||||||
| } catch (e) { | ||||||||||||||
| // Do nothing here, as the command above will spawn a `storybook dev` process which does the error handling already. Else, the error will get bubbled up and sent to crash reports twice | ||||||||||||||
| if (supportsOnboarding && shouldOnboard) { | ||||||||||||||
| flags.push('--initial-path=/onboarding'); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| flags.push('--quiet'); | ||||||||||||||
|
|
||||||||||||||
| // instead of calling 'dev' automatically, we spawn a subprocess so that it gets | ||||||||||||||
| // executed directly in the user's project directory. This avoid potential issues | ||||||||||||||
| // with packages running in npxs' node_modules | ||||||||||||||
| logger.log('\nRunning Storybook'); | ||||||||||||||
| execa.command(`${storybookCommand} ${flags.join(' ')}`, { | ||||||||||||||
| stdio: 'inherit', | ||||||||||||||
| }); | ||||||||||||||
|
Comment on lines
+858
to
+860
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainMissing The If the intent is to spawn a long-running dev server and return immediately (fire-and-forget), consider:
If the process should be awaited, apply this diff: - execa.command(`${storybookCommand} ${flags.join(' ')}`, {
+ await execa.command(`${storybookCommand} ${flags.join(' ')}`, {
stdio: 'inherit',
});🏁 Script executed: #!/bin/bash
# View the file context around lines 858-860 with surrounding code and try-catch wrapper
sed -n '820,900p' code/lib/create-storybook/src/initiate.tsLength of output: 1375 🏁 Script executed: #!/bin/bash
# Search for similar execa patterns with fire-and-forget or .catch() usage
rg -n -B2 -A2 'execa\.(command|.*)\(' code/ --type ts --type tsx | head -100Length of output: 27 🏁 Script executed: #!/bin/bash
# Search for execa patterns in TypeScript files to find similar patterns
rg -n 'execa\.' code/ -g '*.ts' -A3 | head -150Length of output: 626 🏁 Script executed: #!/bin/bash
# View context around the awaited execa call for comparison
sed -n '180,210p' code/lib/create-storybook/src/scaffold-new-project.tsLength of output: 796 🏁 Script executed: #!/bin/bash
# Search for .catch() patterns on execa or similar async calls
rg -n '\.catch\(' code/lib/create-storybook/ -g '*.ts' -B2 -A2Length of output: 744 Await the The review comment is correct. The Apply this fix: - execa.command(`${storybookCommand} ${flags.join(' ')}`, {
+ await execa.command(`${storybookCommand} ${flags.join(' ')}`, {
stdio: 'inherit',
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } catch { | ||||||||||||||
| // Do nothing here, as the command above will spawn a `storybook dev` process which does the error handling already | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Use the existing
ONBOARDING_PROJECT_TYPESconstant.The
supportsOnboardingcheck duplicates theONBOARDING_PROJECT_TYPESconstant defined at lines 66-75. This creates a maintenance burden if the list changes.Apply this diff to use the existing constant:
📝 Committable suggestion
🤖 Prompt for AI Agents