In order to easily parse the output of npm outdated --json
, this command should always exit cleanly (unless of course an actual error occurs).
The reason for this is that because --json
exits if there are outdated dependencies, using something like exec
/execFile
to get the stdout fails to work as expected and you instead have to parse error output and remove the first line of the output before parsing the JSON response body.
Unless I'm mistake, then JSON output is mean to be parsed, so having a failure output for the perfectly valid scenario of having out of date packages, seems problematic to me.
I suggest that if a users passes --json
to npm outdated
, the command always exits cleanly unless an actual error occurs.
Example of the output of running npm outdated --json
in node and getting an error instead of JSON output:
n/a
CLI
npm: 6.13.7
node: v13.10.1
See description
Run npm outdated --json
on a project without out of date dependencies and check error code.
Don't return an error code if packages are out of date if --json
flag is provided.
All CLI users
n/a
Are you sure the json isn鈥檛 on stdout, and the error on stderr, which would enable you to easily pipe or separate the json output?
I logged out stdout
from the execFile
output, so yeah I'm pretty sure it is not coming out on stdout. You can also run npm outdated --json
on the console and check output to verify my above assertion is true 馃憤
It seems reasonable to me that, unrelated to exit code, a command with --json
should only ever output json on stdout.
@ljharb sweet, I'm glad you agree 馃槃
I assume this is considered a breaking change tho?
Seems like a patch to me, but I don't make those decisions here :-)
Well technically it is a breaking change right? Like if people expected the default output to have exit 1 it would break for them right? Not that I really care, it would just be cool if it was fixed 馃槃
Same thing happens in the case of a Makefile.
I understand that at some point that was the desired functionality, but npm outdated
should not return an error.
A new package version being available is not an error.
Or at least it should respect the --silent
flag.
So now it outputs everything to stdout, but still returns code 1, preventing a sub-process in node from being able to parse the result.
Most helpful comment
It seems reasonable to me that, unrelated to exit code, a command with
--json
should only ever output json on stdout.