node
node copied to clipboard
Task runner (node --run) should set lifecycle_event environment variable
What is the problem this feature will solve?
Some npm scripts delegate to another task runner (like Wireit) and require the environment variable npm_lifecycle_event
to be set in order to tell which script to run. Yarn and pnpm both set this variable.
The way a Wireit package.json is configured is like this:
{
"scripts": {
"build": "wireit",
},
"wireit": {
"build": {
"command": "tsc"
}
}
}
and it's run with npm run build
, yarn run build
, etc. So Wireit needs npm_lifecycle_event
to find the script to run.
Supporting task runner like Wireit would be great because Wireit caches script results, so some invocations don't perform any work after checking the cache and the npm
overhead could be noticeable.
Downstream issue: https://github.com/google/wireit/issues/1094
What is the feature you are proposing to solve the problem?
node --run
set the npm_lifecycle_event
environment variable to the current script.
What alternatives have you considered?
Node could set a different variable and task runners like Wireit could detect that also.