npm outdated should have an option to have non-zero exit code

What I Wanted to Do

I want npm outdated to NOT exit with non-zero status code even with outdated libraries or at least have an option to configure this behavior (–silent ?).
I found this issues in old npm repository which seems to tell that --silent flag should do that but it’s not working on my npm version:


What Happened Instead

npm outdated always return non-zero exit code (1) if there are outdated libraries with or without silent flag

Reproduction Steps

npm outdated > /dev/null; echo $? --> return “1”, this may stay the default behavior to have non breaking change

npm outdated --silent > /dev/null; echo $? --> return “1” and should return "0"

Details

The current behavior is really painful for any integration with build or CI system as non-zero exit code are understand as a failure/error of the command and break build (which is the common accepted meaning of it).

Having outdated libraries IS NOT a failure, it can happen for many (very good) reasons and you may have no choice to stick to old versions (breaking changes, cross versions constraints between libraries, old versions to maintains, etc …)

Platform Info

$ npm --versions
{ 'my-project': '1.0.0',
  npm: '6.9.0',
  ares: '1.15.0',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.0.1',
  modules: '67',
  napi: '3',
  nghttp2: '1.34.0',
  node: '11.6.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.24.1',
  v8: '7.0.276.38-node.13',
  zlib: '1.2.11' }

$ node -p process.platform
linux

I think the current default behaviour is as intended (i.e. exit with non-zero status code when outdated). I see that PR did say that --silent changed the behaviour, but the comments suggest that is a confusion from naming in the code and never the case (and I do not think it would be the right flag to do that).

Are you mostly asking for a new feature? (From the title it sounds like you are. In which case filing this under #ideas might be more appropriate.)

Are you interested in work-arounds? (Do you know you could modify the exit code with logical operator?)

(And nice work tracking down the issue/PR where the change occurred.)

Thanks for your answer.
I change the category from bugs to ideas as you suggest.
I know that I can modify the exit code with a logical operator but it may not be consistent across operating systems.
If you have other workarounds I’m interested.

Anyway I think this should still be a feature inside “npm outdated” method because it doesn’t make sense in a lot of case to consider presence of outdated libraries as an error as I explained previously.

If “–silent” is not the right flag to do that (I agree with your point on that) maybe we can decide which flag name or option may be appropriate to add this feature on outdated command.

It could be a flag like “–no-error-on-outdated” which is disabled by default to not break current behavior.

If we agreed on something like that I’ll be pleased to implement it and submit a pull request.

PR created https://github.com/npm/cli/pull/258

1 Like