[BUG] npm run <script name> --if-present silently ignores missing scripts in subcommands #3352
Closed
1 task done
Labels
Bug
thing that needs fixing
cmd:run-script
related to `npm run-script`
Priority 2
secondary priority issue
Release 7.x
work is associated with a specific npm 7 release
Release 8.x
work is associated with a specific npm 8 release
Milestone
Is there an existing issue for this?
Current Behavior
The
--if-present
switch thatnpm run
supports also cascades into othernpm 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-levelbuild
script.The problem can be illustrated with a simple
package.json
:To reproduce:
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 othernpm 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
The text was updated successfully, but these errors were encountered: