-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
The --if-present
switch that npm run
supports also cascades into other npm run
commands executed by the script at all levels. It makes the --if-present
switch a bit of a footgun, so I hope that's a bug :)
Background: I spent some time figuring out why a missing script referenced by an npm run ...
inside another npm script didn't cause my Heroku deploy to fail. It turns out that it's because they use the --if-present
flag when executing the top-level build
script.
The problem can be illustrated with a simple package.json
:
{
"scripts": {
"foo": "npm run notfound"
}
}
To reproduce:
npm run --if-present foo
This command exists with 0 and no error message.
Expected Behavior
I expected it to fail with missing script: notfound
.
I would expect npm run --if-present <script name>
to only apply its "silently ignore missing script" behavior wrt. the exact script I tell it to run. I don't want the behavior to cascade into other npm run ...
commands that might be found in the script itself. If I wanted that, I would pass --if-present
there explicitly also.
Steps To Reproduce
See "Current Behavior"
Environment
- OS: OSX 10.15.7 (19H1217)
- Node: 16.2.0
- npm: 7.15.1