nodejs / nodejs/node

`node --run` should find a way to avoid keeping a shell around and properly forward signals

Open
#65,712 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

Node has gained node --run as a way to directly execute a package.json script, but this has a glaring subtle limitation currently that has bitten me and likely others, and is also recurring in the existing package managers: It doesn't forward signals properly to the subprocess, and the shell in the middle can even end up swallowing those signals and lingering when invoked node --run is invoked as PID 1 in Docker.

What is the feature you are proposing to solve the problem?

It would be much nicer to have a variant that can function identically to just a direct node script.js invocation, but with the arguments and command line in the package.json for DRY reasons. This can be problematic though, as package.json scripts are currently arbitrary shell scripts, and Node.js likely just uses sh to execute them rather then any JS shell-emulator (Pnpm, Yarn), which can limit it's ability to directly exec the final ran command so the shell in the middle doesn't swallow signals.

What alternatives have you considered?

Don't use node --run or the package mangers, just direct node script.js duplicating the start command.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the node --run entry point and trace how package.json scripts are launched, paying particular attention to the shell process and PID 1 behavior in Docker. Reproduce the signal-handling case described in the issue; done means the proposed invocation avoids an unwanted lingering shell and forwards signals correctly without losing existing script behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, nodejs, shell
Domain
cli, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.