From 748ad2f86364a25d55b5f42987a696a1b52156c1 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 25 Sep 2025 11:30:05 +0800 Subject: [PATCH] chore(task): exit process in Node.js For debugging purpose --- packages/cli/binding/index.d.ts | 2 +- packages/cli/binding/src/lib.rs | 6 +++--- packages/cli/src/bin.ts | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/cli/binding/index.d.ts b/packages/cli/binding/index.d.ts index 9a3d31674b..9a94ee6b33 100644 --- a/packages/cli/binding/index.d.ts +++ b/packages/cli/binding/index.d.ts @@ -63,4 +63,4 @@ export interface JsCommandResolvedResult { * Errors from JavaScript resolvers are converted to specific error types * (e.g., `LintFailed`, `ViteError`) to provide better error messages. */ -export declare function run(options: CliOptions): Promise +export declare function run(options: CliOptions): Promise diff --git a/packages/cli/binding/src/lib.rs b/packages/cli/binding/src/lib.rs index 59fa957b36..97b3bc86d5 100644 --- a/packages/cli/binding/src/lib.rs +++ b/packages/cli/binding/src/lib.rs @@ -97,7 +97,7 @@ static BUILTIN_COMMANDS: &[&str] = &["lint", "fmt", "build", "test", "doc", "lib /// Errors from JavaScript resolvers are converted to specific error types /// (e.g., `LintFailed`, `ViteError`) to provide better error messages. #[napi] -pub async fn run(options: CliOptions) -> Result<()> { +pub async fn run(options: CliOptions) -> Result { let args = parse_args(); // Use provided cwd or current directory let mut cwd = current_dir()?; @@ -198,11 +198,11 @@ pub async fn run(options: CliOptions) -> Result<()> { .await; match result { - Ok(exit_status) => std::process::exit(exit_status.code().unwrap_or(1)), + Ok(exit_status) => Ok(exit_status.code().unwrap_or(1)), Err(e) => { match e { // Standard exit code for Ctrl+C - Error::UserCancelled => std::process::exit(130), + Error::UserCancelled => Ok(130), _ => { // Convert Rust errors to NAPI errors for JavaScript tracing::error!("Rust error: {:?}", e); diff --git a/packages/cli/src/bin.ts b/packages/cli/src/bin.ts index 8bc14a0432..0db16a4396 100644 --- a/packages/cli/src/bin.ts +++ b/packages/cli/src/bin.ts @@ -40,7 +40,10 @@ run({ test, // Resolves vitest binary for test commands doc, // Resolves vitepress binary for doc commands resolveUniversalViteConfig, -}).catch((err) => { - console.error('[vite+] run error:', err); - process.exit(1); -}); +}).then((exitCode) => { + process.exit(exitCode); +}) + .catch((err) => { + console.error('[vite+] run error:', err); + process.exit(1); + });