Skip to content

Commit 8323be8

Browse files
authored
chore(task): exit process in Node.js (#199)
For debugging purpose
1 parent b8e0dc3 commit 8323be8

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/cli/binding/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ export interface JsCommandResolvedResult {
6363
* Errors from JavaScript resolvers are converted to specific error types
6464
* (e.g., `LintFailed`, `ViteError`) to provide better error messages.
6565
*/
66-
export declare function run(options: CliOptions): Promise<void>
66+
export declare function run(options: CliOptions): Promise<number>

packages/cli/binding/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static BUILTIN_COMMANDS: &[&str] = &["lint", "fmt", "build", "test", "doc", "lib
9797
/// Errors from JavaScript resolvers are converted to specific error types
9898
/// (e.g., `LintFailed`, `ViteError`) to provide better error messages.
9999
#[napi]
100-
pub async fn run(options: CliOptions) -> Result<()> {
100+
pub async fn run(options: CliOptions) -> Result<i32> {
101101
let args = parse_args();
102102
// Use provided cwd or current directory
103103
let mut cwd = current_dir()?;
@@ -198,11 +198,11 @@ pub async fn run(options: CliOptions) -> Result<()> {
198198
.await;
199199

200200
match result {
201-
Ok(exit_status) => std::process::exit(exit_status.code().unwrap_or(1)),
201+
Ok(exit_status) => Ok(exit_status.code().unwrap_or(1)),
202202
Err(e) => {
203203
match e {
204204
// Standard exit code for Ctrl+C
205-
Error::UserCancelled => std::process::exit(130),
205+
Error::UserCancelled => Ok(130),
206206
_ => {
207207
// Convert Rust errors to NAPI errors for JavaScript
208208
tracing::error!("Rust error: {:?}", e);

packages/cli/src/bin.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ run({
4040
test, // Resolves vitest binary for test commands
4141
doc, // Resolves vitepress binary for doc commands
4242
resolveUniversalViteConfig,
43-
}).catch((err) => {
44-
console.error('[vite+] run error:', err);
45-
process.exit(1);
46-
});
43+
}).then((exitCode) => {
44+
process.exit(exitCode);
45+
})
46+
.catch((err) => {
47+
console.error('[vite+] run error:', err);
48+
process.exit(1);
49+
});

0 commit comments

Comments
 (0)