fix: use 'exec' in binstub#53
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes POSIX sh binstub generation so the shim uses exec even when the “long program path” (shLongProg) branch is not taken, allowing signals (e.g., kill) to correctly reach the underlying node process.
Changes:
- Add
execto the non-shLongProgbranch ingenerateShShim()so the shim process is replaced by the target process. - Update JS snapshot expectations for generated shims to include
exec.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/index.ts |
Ensures generated sh shim uses exec in the non-shLongProg path so signals propagate correctly. |
test/test.js.snapshot |
Updates snapshots to match the new exec-prefixed sh shim output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When cmd-shim is used in pnpm to create a wrapper for "node", you cannot kill the node process by killing the process spawned by invoking node_modules/.bin/node, because the binstub doesn't use 'exec'. Commit 1033be3 ("fix: improve sh binstubs", 2020-01-16) added 'exec' to the "shLongProg" code path, but for some reason didn't add it to the non-"shLongProg" path. Add it in the "shLongProg" case to fix the issue of killing node.
Adds a POSIX regression test that wraps `process.execPath` (a no-shebang binary, the case that hits the non-shLongProg branch of the sh shim), invokes the shim, and asserts the wrapped binary's `process.pid` equals the shim's spawn pid. That can only hold when the shell `exec`s into the target — without exec the shell wraps the binary in its own process, breaking signal delivery and producing a different PID. Manually verified: 7 tests fail when the `exec` is reverted, 59/59 pass with it. Also updates the `.exe` shim e2e snapshot so the existing Windows test matches the new `exec`-prefixed output. --- Written by an agent (Claude Code, claude-opus-4-7).
📝 WalkthroughWalkthroughPOSIX shell shims are modified to use ChangesPOSIX Shell Shim Exec Replacement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
When cmd-shim is used to create a wrapper for
node(or any other binary with no shebang and no recognized extension), you cannot kill the wrapped process by killing the process spawned by invoking the shim, because the sh binstub doesn't useexec.Commit 1033be3 ("fix: improve sh binstubs", 2020-01-16) added
execto theshLongProgcode path, but for some reason didn't add it to the non-shLongProg(else) path — the one taken whenopts.progis null (e.g. a.exeor other extension-less binary). This PR addsexecto that branch so signal delivery and PID inheritance behave consistently across both paths.Test plan
exec-prefixed output (3 snapshots intest.js.snapshot, 1 ine2e.test.js.snapshot).process.execPath(a no-shebang native binary, exercising the non-shLongProgbranch), spawns the shim, and asserts the wrapped binary'sprocess.pidequals the shim's spawn PID — which is only possible when the shellexecs into the target. Manually verified: 7/59 tests fail when theexecchange is reverted, 59/59 pass with it.Rebased onto current
main(which includes the recently merged MSYS escape fix from #55).