Provide a way to load modules dynamically when npm starts without having to specify `NODE_OPTIONS`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
As of npm 11, it's possible to use the node-options configuration key to specify the content of NODE_OPTIONS for lifecycle scripts (i.e. it wouldn't be picked up, for example, by npm test ... -- but it would be from npm pretest ...).
I'm wondering whether it would be feasible thinking about the idea of allowing users to opt-in into using this configuration key to set NODE_OPTIONS for npm commands as well.
I'm not hard-set on this solution, I'll share some context around why I'm making this proposal.
Context
As a software engineer at Gradle, I'm part of a team which is adding support for npm to our build observability product, Develocity.
We created a module that can be preloaded (NODE_OPTIONS="-r ...") and, when enabled, collects events from the run and sends them to the Develocity server.
We realized that setting NODE_OPTIONS can have ergonomics issues: setting it globally means that the module cannot be found for projects that don't have the package installed (and would be picked up by any Node.js process), and unfortunately using node-options from the npm config would not have an effect when running, for example npm test.
I'm open to discuss other solutions that would fit well with our use case of instrumenting npm.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing npm 11's node-options configuration behavior for lifecycle scripts and how regular commands such as npm test launch Node. A contribution would need an agreed opt-in mechanism for applying the setting to npm commands, with tests covering both lifecycle and direct commands.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100