Skip to content

fix: use 'exec' in binstub#53

Open
Mortal wants to merge 1 commit intopnpm:mainfrom
Mortal:binstub-exec
Open

fix: use 'exec' in binstub#53
Mortal wants to merge 1 commit intopnpm:mainfrom
Mortal:binstub-exec

Conversation

@Mortal
Copy link
Copy Markdown

@Mortal Mortal commented Apr 1, 2026

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.

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 exec to the non-shLongProg branch in generateShShim() 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.

Comment on lines 485 to 496
if (shLongProg) {
sh += `\
if [ -x ${shLongProg} ]; then
exec ${shLongProg} ${args} ${shTarget} ${progArgs}"$@"
else
exec ${shProg} ${args} ${shTarget} ${progArgs}"$@"
fi
`
} else {
sh += `\
${shProg} ${args} ${shTarget} ${progArgs}"$@"
exec ${shProg} ${args} ${shTarget} ${progArgs}"$@"
exit $?
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says the missing exec is in the "shLongProg" code path, but this change actually adds exec to the non-shLongProg (else) branch. Consider updating the PR description to match the implementation so future readers understand which path was fixed.

Copilot uses AI. Check for mistakes.
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