fix(core): call process.exit(0) after successful build and index commands#34453
fix(core): call process.exit(0) after successful build and index commands#34453mixelburg wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdded explicit Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/core/src/bin/core.ts`:
- Line 192: The build and index command action handlers currently call
process.exit(0) which kills the process before the postAction hook (postAction)
can persist logs; remove those direct process.exit(0) calls and replace them by
invoking a centralized success handler (e.g., handleSuccess or finalizeAndExit)
that runs the same log-writing/persistence logic currently in postAction (ensure
it triggers or awaits postAction's file-write code) and only then calls
process.exit(0); update the build and index action handlers to call this success
handler instead of exiting directly so logfile writing completes on successful
runs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d030d5d-5e52-49a2-a429-bed155e2e567
📒 Files selected for processing (1)
code/core/src/bin/core.ts
| }); | ||
|
|
||
| logger.outro('Storybook build completed successfully'); | ||
| process.exit(0); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify the lifecycle conflict and affected paths in the reviewed file.
rg -n -C3 "hook\\('postAction'|writeToFile\\(|command\\('build'\\)|command\\('index'\\)|process\\.exit\\(0\\)" code/core/src/bin/core.tsRepository: storybookjs/storybook
Length of output: 1625
process.exit(0) inside action handlers prevents postAction hook from writing debug logs
At Line 192 (build command) and Line 220 (index command), process.exit(0) terminates the process before the postAction hook (Line 73) can execute. This prevents the log file persistence logic at Line 76 from running on successful completion, causing debug logs to be lost for users with --logfile enabled.
Move log writing and exit handling into a dedicated success handler:
Suggested fix
const handleCommandFailure = async (logFilePath: string | boolean): Promise<never> => {
try {
const logFile = await logTracker.writeToFile(logFilePath);
logger.log(`Debug logs are written to: ${logFile}`);
} catch {}
logger.outro('Storybook exited with an error');
process.exit(1);
};
+
+const handleCommandSuccess = async (logFilePath: string | boolean): Promise<never> => {
+ if (logTracker.shouldWriteLogsToFile) {
+ try {
+ const logFile = await logTracker.writeToFile(logFilePath);
+ logger.outro(`Debug logs are written to: ${logFile}`);
+ } catch {}
+ }
+ process.exit(0);
+};
@@
logger.outro('Storybook build completed successfully');
- process.exit(0);
+ await handleCommandSuccess(options.logfile);
});
@@
- process.exit(0);
+ await handleCommandSuccess(options.logfile);
});Also applies to: Line 220
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@code/core/src/bin/core.ts` at line 192, The build and index command action
handlers currently call process.exit(0) which kills the process before the
postAction hook (postAction) can persist logs; remove those direct
process.exit(0) calls and replace them by invoking a centralized success handler
(e.g., handleSuccess or finalizeAndExit) that runs the same
log-writing/persistence logic currently in postAction (ensure it triggers or
awaits postAction's file-write code) and only then calls process.exit(0); update
the build and index action handlers to call this success handler instead of
exiting directly so logfile writing completes on successful runs.
|
Hi @mixelburg, Thank you for your contribution so far. Your contributions so far seem purely AI-driven without any manual verification. I've gently asked for verification in some of your recent PRs. Please don't create new PRs while the old ones are still open. The Storybook team accepts PRs that are AI-generated, but only if the work is well understood and verified by the PR creator. If these requirements aren't met, I will start auto-closing PRs that don't have a human contribution, such as at least manual validation of the work. Also, please use your PR template in the future when creating PRs. I'll close this and any future PRs unless the requested validation for the recent ones is provided. I'll also autoclose the older PRs soon, if I don't hear back from you within the next couple of working days, assuming that I'm not talking to a human. Thank you for your understanding! |
Summary
Fixes #34446
The
buildandindexcommands incode/core/src/bin/core.tslog success but never callprocess.exit(0). With Vite/chokidar and other tools that register file watchers or keep-alive handles, the Node.js process hangs indefinitely after the build completes—it only exits when those handles eventually time out or are garbage collected.The error path already calls
process.exit(1), so addingprocess.exit(0)to the success path is the consistent fix. This matches the pattern used by the CLI'sdevwrapper (which also exits with 0 on success).Changes
command('build'): addprocess.exit(0)afterlogger.outro('Storybook build completed successfully')command('index'): addprocess.exit(0)after the awaited index callSummary by CodeRabbit
buildandindexcommands now properly terminate upon successful completion.