Skip to content

fix(windows): use script_cmd() for all Node.js tool spawning#398

Open
ThomasHoussin wants to merge 4 commits intortk-ai:developfrom
ThomasHoussin:fix/windows-cmd-compat
Open

fix(windows): use script_cmd() for all Node.js tool spawning#398
ThomasHoussin wants to merge 4 commits intortk-ai:developfrom
ThomasHoussin:fix/windows-cmd-compat

Conversation

@ThomasHoussin
Copy link

@ThomasHoussin ThomasHoussin commented Mar 7, 2026

On Windows, Command::new("yarn") fails because the actual binary is
yarn.cmd. The same issue affects npm, pnpm, npx, tsc, next, prisma,
playwright, and ccusage.

Root cause: Rust's CreateProcessW doesn't resolve PATHEXT extensions
(.cmd, .bat), so it finds the POSIX shell shim instead of the batch
wrapper.

Additionally, several modules use Command::new("which") to detect
tools, but which doesn't exist on Windows.

Solution

Two new helpers in utils.rs:

  • script_cmd(program) — appends .cmd on Windows (compile-time cfg!, zero runtime cost)
  • has_program(program) — uses where.exe on Windows, which on Unix

All Node.js tool modules are migrated to script_cmd(), and three
duplicate local which_command() functions are replaced by the
centralized has_program().

Files changed (13)

File Change
src/utils.rs Add script_cmd, has_program, fix package_manager_exec
src/npm_cmd.rs script_cmd("npm")
src/pnpm_cmd.rs script_cmd("pnpm") (4 sites)
src/tsc_cmd.rs script_cmd("tsc"/"npx") + has_program
src/next_cmd.rs script_cmd("next"/"npx") + has_program
src/prisma_cmd.rs script_cmd("prisma"/"npx") + has_program
src/playwright_cmd.rs script_cmd("pnpm"/"yarn"/"npx")
src/ccusage.rs script_cmd("ccusage"/"npx") + has_program
src/main.rs script_cmd("npx") (prisma passthrough)
src/pip_cmd.rs has_program, delete local which_command
src/mypy_cmd.rs has_program, delete local which_command
src/pytest_cmd.rs has_program, delete local which_command
src/tree.rs has_program

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — 713 passed, 0 failed
  • Platform-specific unit tests for script_cmd() (cfg(windows) / cfg(not(windows)))
  • has_program() positive/negative/cross-platform tests
  • Manual smoke tests on Windows 11: rtk npm, rtk tsc, rtk mypy, rtk uv all resolve correctly
  • CI validation on Linux/macOS (Unix path unchanged, no .cmd suffix)

Ref: spec/TODO-windows-script-cmd.md

aeppling added 3 commits March 7, 2026 11:23
add security check cicd on dev branch PR

Signed-off-by: aesoft <43991222+aeppling@users.noreply.github.com>
fix(cicd): Add security check on dev branch PR
Add `script_cmd()` and `has_program()` helpers to utils.rs, then
migrate all bare `Command::new` calls for Node.js CLI tools to use
`.cmd` wrappers on Windows, and replace all `Command::new("which")`
probes with a cross-platform `where.exe`/`which` helper.

- Add `script_cmd(program)`: appends `.cmd` on Windows (compile-time cfg)
- Add `has_program(program)`: uses `where.exe` on Windows, `which` on Unix
- Fix `package_manager_exec()` to use both helpers
- Migrate 8 Node.js modules: npm, pnpm, tsc, next, prisma, playwright,
  ccusage, main.rs prisma passthrough
- Remove 3 duplicate local `which_command()` fns from pip, mypy, pytest
- Fix `tree.rs` inline `which` probe
- Add platform-specific tests for both helpers

13 files changed, 167 insertions(+), 108 deletions(-)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ThomasHoussin ThomasHoussin force-pushed the fix/windows-cmd-compat branch from b7feebc to 96fd940 Compare March 7, 2026 18:20
@ThomasHoussin ThomasHoussin changed the base branch from master to develop March 7, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants