Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm run <script name> --if-present silently ignores missing scripts in subcommands #3352

Closed
1 task done
papandreou opened this issue Jun 2, 2021 · 0 comments · Fixed by #4678
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

Comments

@papandreou
Copy link

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
@papandreou papandreou added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Jun 2, 2021
@nlf nlf added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Jun 3, 2021
@darcyclarke darcyclarke added this to the OSS - Sprint 36 milestone Aug 23, 2021
@wraithgar wraithgar removed their assignment Aug 24, 2021
ruyadorno added a commit to ruyadorno/cli that referenced this issue Apr 4, 2022
Do not pass the `if-present` env config value to spawned processes.

Fixes: npm#3352
Close: npm#3589
@ruyadorno ruyadorno added Release 8.x work is associated with a specific npm 8 release cmd:run-script related to `npm run-script` labels Apr 4, 2022
wraithgar pushed a commit that referenced this issue Apr 5, 2022
Do not pass the `if-present` env config value to spawned processes.

Fixes: #3352
Close: #3589
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
5 participants