fix(windows): use script_cmd() for all Node.js tool spawning#398
Open
ThomasHoussin wants to merge 4 commits intortk-ai:developfrom
Open
fix(windows): use script_cmd() for all Node.js tool spawning#398ThomasHoussin wants to merge 4 commits intortk-ai:developfrom
ThomasHoussin wants to merge 4 commits intortk-ai:developfrom
Conversation
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>
b7feebc to
96fd940
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows,
Command::new("yarn")fails because the actual binary isyarn.cmd. The same issue affects npm, pnpm, npx, tsc, next, prisma,playwright, and ccusage.
Root cause: Rust's
CreateProcessWdoesn't resolve PATHEXT extensions(
.cmd,.bat), so it finds the POSIX shell shim instead of the batchwrapper.
Additionally, several modules use
Command::new("which")to detecttools, but
whichdoesn't exist on Windows.Solution
Two new helpers in
utils.rs:script_cmd(program)— appends.cmdon Windows (compile-timecfg!, zero runtime cost)has_program(program)— useswhere.exeon Windows,whichon UnixAll Node.js tool modules are migrated to
script_cmd(), and threeduplicate local
which_command()functions are replaced by thecentralized
has_program().Files changed (13)
src/utils.rsscript_cmd,has_program, fixpackage_manager_execsrc/npm_cmd.rsscript_cmd("npm")src/pnpm_cmd.rsscript_cmd("pnpm")(4 sites)src/tsc_cmd.rsscript_cmd("tsc"/"npx")+has_programsrc/next_cmd.rsscript_cmd("next"/"npx")+has_programsrc/prisma_cmd.rsscript_cmd("prisma"/"npx")+has_programsrc/playwright_cmd.rsscript_cmd("pnpm"/"yarn"/"npx")src/ccusage.rsscript_cmd("ccusage"/"npx")+has_programsrc/main.rsscript_cmd("npx")(prisma passthrough)src/pip_cmd.rshas_program, delete localwhich_commandsrc/mypy_cmd.rshas_program, delete localwhich_commandsrc/pytest_cmd.rshas_program, delete localwhich_commandsrc/tree.rshas_programTest plan
cargo fmt --all --check && cargo clippy --all-targets && cargo test— 713 passed, 0 failedscript_cmd()(cfg(windows)/cfg(not(windows)))has_program()positive/negative/cross-platform testsrtk npm,rtk tsc,rtk mypy,rtk uvall resolve correctly.cmdsuffix)Ref:
spec/TODO-windows-script-cmd.md