You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
How
Steps to Reproduce
The problem can be illustrated with a simple package.json:
{"scripts": {"foo": "npm run notfound"}}
To reproduce:
npm run --if-present foo
Expected Behavior
I expected it to fail with missing script: notfound, but it exits with 0 and no error message.
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.
Who
n/a
References
n/a
The text was updated successfully, but these errors were encountered:
npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.
If your bug is reproducible on v7, please re-file this issue using our new issue template.
If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo
What / Why
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.How
Steps to Reproduce
The problem can be illustrated with a simple
package.json
:To reproduce:
Expected Behavior
I expected it to fail with
missing script: notfound
, but it exits with 0 and no error message.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.Who
References
The text was updated successfully, but these errors were encountered: