From 1c1da220ee24261bc28d0ccebb196e97f4124076 Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Wed, 14 Jan 2026 05:10:28 +0000 Subject: [PATCH] refactor(oxfmt): Minimize `setBlocking(true)` workaround scope (#17974) Follow up #17950 --- apps/oxfmt/src-js/cli.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/oxfmt/src-js/cli.ts b/apps/oxfmt/src-js/cli.ts index 32cc69e18a98e..975aa8d814f34 100644 --- a/apps/oxfmt/src-js/cli.ts +++ b/apps/oxfmt/src-js/cli.ts @@ -12,16 +12,14 @@ import { void (async () => { const args = process.argv.slice(2); - // Node.js sets `stdio` to non-blocking mode, + // Node.js sets non-TTY `stdio` to non-blocking mode, // which causes `WouldBlock` errors in Rust when writing large output with `--stdin-filepath`. - // Set blocking mode before calling NAPI bindings. - // See: https://github.com/napi-rs/napi-rs/issues/1630 + // https://github.com/oxc-project/oxc/issues/17939 (issue was on macOS) // - // NOTE: Unlike `yargs/set-blocking` which recommends calling just before `process.exit()`, - // we must set blocking mode here because Rust outputs during `runCli()` execution. - // See also: https://github.com/yargs/set-blocking - (process.stdout as any)._handle?.setBlocking?.(true); - (process.stderr as any)._handle?.setBlocking?.(true); + // As a workaround, if used with pipe, set blocking mode before calling NAPI bindings. + // See: https://github.com/napi-rs/napi-rs/issues/1630 + // @ts-expect-error: `_handle` is an internal API + if (!process.stdout.isTTY) process.stdout._handle?.setBlocking?.(true); // Call the Rust CLI first, to parse args and determine mode // NOTE: If the mode is formatter CLI, it will also perform formatting and return an exit code