fix(dev): spawn .cmd/.bat shims through cmd.exe on Windows - #579
Open
yzxcj797 wants to merge 1 commit into
Open
Conversation
child_process.spawn cannot run the batch shims npm/tsx install on PATH: the bare name fails with ENOENT and the explicit .cmd fails with EINVAL on current Node (yc-software#551), so scripts/dev (deps.ts npm install/build, the detached supervisor spawn) cannot boot a dev pool on Windows. Resolve the command against PATH at the single spawn choke point in scripts/dev/lib/proc.ts: - PATHEXT extensions are tried before the extensionless name -- Node's install dir ships an extensionless 'npm' sh-script for bash that would otherwise win over npm.cmd; - .cmd/.bat shims run via cmd.exe /d /s /c with one pre-quoted command line (shim paths contain spaces, e.g. C:\Program Files\nodejs\npm.cmd) and windowsVerbatimArguments so Node's backslash quote-escaping does not reach cmd.exe; - .exe resolves to its full path and spawns directly; non-Windows platforms and non-batch commands are untouched. run() and spawnDetached() both route through the resolver. Tests cover batch-shim routing, plain-executable resolution, non-Windows passthrough, a real npm --version round-trip on Windows, and a detached child.
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.
Summary
Fixes #551.
scripts/devcannot boot a dev pool on Windows:child_process.spawncan't execute the batch shims that npm/tsx install on PATH (spawn("npm")→ ENOENT,spawn("npm.cmd")→ EINVAL on current Node), which breaksdeps.ts'snpm install/npm run buildand any other bare-command child spawn.Fix — resolution at the single spawn choke point
scripts/dev/lib/proc.tsnow resolves commands on win32 before spawning (bothrun()andspawnDetached()route through it):npmsh-script for bash environments next tonpm.cmd; trying the extensionless name first hands spawn a non-executable file, so PATHEXT extensions are tried before the bare name (matching cmd.exe semantics)..cmd/.batshims run throughcmd.exe /d /s /cwith one pre-quoted command line ("C:\Program Files\nodejs\npm.cmd" --version) wrapped in an outer quote pair that/sstrips, passed withwindowsVerbatimArguments: true— Node's default backslash-escaping of embedded quotes is something cmd.exe cannot parse, and the shim path almost always contains a space..exeresolves to its full path and spawns directly; non-Windows platforms and non-batch commands are untouched (identity passthrough asserted by tests).Verification (on Windows, Node 24.14)
run("npm", ["--version"])→ exit 0, version printed — the exact call that produceddeps: fail -- npm install failed ... spawn npm ENOENTbefore.spawnDetachedruns a node child through the same choke point and writes its marker file.test/dev-proc-windows-spawn.test.ts: batch-shim routing (asserts the cmd.exe invocation shape), plain-executable resolution, non-Windows passthrough, the realnpm --versionround-trip, and the detached spawn. Windows-only assertions areskip-gated on other platforms; the passthrough test runs everywhere.Notes
portHolders()still useslsofand is a silent no-op on Windows — left out of scope (it fails safe: stale-port cleanup just doesn't free anything).Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.