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 outdated exit code should not be set with json output #3844

Closed
1 task done
wraithgar opened this issue Oct 6, 2021 · 12 comments
Closed
1 task done

[BUG] npm outdated exit code should not be set with json output #3844

wraithgar opened this issue Oct 6, 2021 · 12 comments
Assignees
Labels
Bug thing that needs fixing Needs Discussion is pending a discussion Release 7.x work is associated with a specific npm 7 release

Comments

@wraithgar
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

See #1109

Fix will be.

diff --git a/lib/outdated.js b/lib/outdated.js
index b3b630421..68002bf19 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -88,13 +88,14 @@ class Outdated extends ArboristWorkspaceCmd {
     // sorts list alphabetically
     const outdated = this.list.sort((a, b) => localeCompare(a.name, b.name))
 
-    if (outdated.length > 0)
-      process.exitCode = 1
-
     // return if no outdated packages
     if (outdated.length === 0 && !this.npm.config.get('json'))
       return
 
+    if (!this.npm.config.get('json'))
+      process.exitCode = 1
+
+

Expected Behavior

No response

Steps To Reproduce

No response

Environment

  • npm: 7.24.2
@wraithgar wraithgar added Release 7.x work is associated with a specific npm 7 release Bug thing that needs fixing Needs Triage needs review for next steps labels Oct 6, 2021
@wraithgar wraithgar mentioned this issue Oct 6, 2021
@ljharb
Copy link
Collaborator

ljharb commented Oct 6, 2021

Why not?

@wraithgar
Copy link
Member Author

See #1109

@wraithgar
Copy link
Member Author

I did try to replicate this and npm outdated --json > output piped the outdated content to stdout.

@wraithgar
Copy link
Member Author

This may not be a problem, this PR is where we can find out

@ljharb
Copy link
Collaborator

ljharb commented Oct 6, 2021

To me it seems identically a problem - or not a problem - regardless of the output format.

It will be very surprising to me if changing the output format has ANY impact on the exit code; the two are not semantically related.

@wraithgar
Copy link
Member Author

Perhaps @boostvolt can elaborate on how what is in place is broken?

@wraithgar wraithgar added Needs Discussion is pending a discussion and removed Needs Triage needs review for next steps labels Oct 6, 2021
@wraithgar wraithgar self-assigned this Oct 6, 2021
@lukekarrys
Copy link
Member

It will be very surprising to me if changing the output format has ANY impact on the exit code; the two are not semantically related.

I can confirm that this is not the current behavior, and I agree it shouldn't be. It might have been in the past, if I'm reading #1109 correctly? I would consider #1109 still resolved, since we now output npm outdated --json to stdout.

I think it's worth noting that there were other requests in #1109 to never have npm outdated set the exit code, regardless of --json. That's directly opposed to #2556 which was fixed in #3799. So I think that is what needs discussion here.

@ljharb
Copy link
Collaborator

ljharb commented Oct 7, 2021

I have no opinion on whether outdated sets the exit code or not, altho i can see the argument for both.

I have a strong opinion that the output format should never dictate the exit code.

@boostvolt
Copy link

When I use npm outdated --json with npm 7.24.2 I get: Command failed with exit code 1: npm outdated --json and the generated json is printed as error to the console. But if I use npm outdated everything works fine. On npm 7.24.1 npm outdated --json as well as npm outdated worked without problems.

@lukekarrys
Copy link
Member

When I use npm outdated --json with npm 7.24.2 I get: Command failed with exit code 1: npm outdated --json and the generated json is printed as error to the console. But if I use npm outdated everything works fine. On npm 7.24.1 npm outdated --json as well as npm outdated worked without problems.

I'm not able to reproduce that behavior. I see the only output printed to stdout and the only difference being the exit code set by the command. Here's what I'm getting in 7.24.1 vs 7.24.2:

7.24.1

$ npm --version
7.24.1

$ npm outdated --json 2> /dev/null; echo "code: $?"
{
  "@npmcli/arborist": {
    "current": "3.0.0",
    "wanted": "2.10.0",
    "latest": "3.0.0",
    "dependent": "3844",
    "location": "/Users/lukekarrys/Desktop/npm-sandbox/3844/node_modules/@npmcli/arborist"
  }
}
code: 0

$ npm outdated 2> /dev/null; echo "code: $?"
Package           Current  Wanted  Latest  Location                       Depended by
@npmcli/arborist    3.0.0  2.10.0   3.0.0  node_modules/@npmcli/arborist  3844
code: 0

7.24.2

$ npm --version
7.24.2

$ npm outdated --json 2> /dev/null; echo "code: $?"
{
  "@npmcli/arborist": {
    "current": "3.0.0",
    "wanted": "2.10.0",
    "latest": "3.0.0",
    "dependent": "3844",
    "location": "/Users/lukekarrys/Desktop/npm-sandbox/3844/node_modules/@npmcli/arborist"
  }
}
code: 1

$ npm outdated 2> /dev/null; echo "code: $?"
Package           Current  Wanted  Latest  Location                       Depended by
@npmcli/arborist    3.0.0  2.10.0   3.0.0  node_modules/@npmcli/arborist  3844
code: 1

@boostvolt
Copy link

boostvolt commented Oct 8, 2021

I just tried this out as well. If I run the command in the terminal everything works. As soon as I call it as Node.js child process I get the exit code 1 error message.

@lukekarrys
Copy link
Member

@boostvolt thanks for the follow up information. As I mentioned in #3871 (comment), this is working as intended right now, so an RFC issue with some details on how this should be changed is the best way forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Discussion is pending a discussion Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

4 participants