Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Fix for #16083, add support for --silent flag with npm outdated.#16703

Closed
wwalser wants to merge 1 commit intonpm:latestfrom
wwalser:silentoutdated
Closed

Fix for #16083, add support for --silent flag with npm outdated.#16703
wwalser wants to merge 1 commit intonpm:latestfrom
wwalser:silentoutdated

Conversation

@wwalser
Copy link

@wwalser wwalser commented May 24, 2017

Fix for #16083 which is a bug introduced in #14013.

This PR is a strict fix for what was said to be the intended behavior introduced in #14013. npm outdated --silent was suppose to maintain the old behavior of returning a success status code even if wanted or latest were out of date.

As an aside, this seems to me like the wrong implementation. It introduces a second meaning of the word "silent" and it may even clash with existing behavior, though I couldn't find an invocation where this was the case.

It seems to me that reusing silent is problematic. The real desire, I believe, is to be able to use npm outdated with some nuance. For example see facebook/fbjs/issues/213, where an out of date "wanted" may be a reasonable case for an error but "latest" may not be.

Edit: As @kenany correctly points out, the collision of a command config option and loglevel shorthand causes problems. I suggest either dumping this feature and letting downstream consumers sort out the exit code for themselves or creating a new option to npm outdated with name other than --silent. I would prefer the later and I'm willing to change the PR to make that happen. Open to suggestions for what the config option should be called, ---quiet?

@isaacs isaacs added the review label May 24, 2017
@watilde
Copy link
Contributor

watilde commented May 24, 2017

+1 on this. This is what I expected, but I missed it at the last PR. We need to update test/tap/outdated-json.js to fix the ci error.

https://github.com/npm/npm/blob/latest/test/tap/outdated-json.js#L83

@kenany
Copy link
Contributor

kenany commented May 24, 2017

As it stands, this breaks the --silent => --loglevel silent alias. Perhaps https://github.com/npm/npm/pull/16703/files#diff-3d20499d58f14c6f1edfe93d8ba8a8a2R115 should just check if loglevel === 'silent'?

@wwalser
Copy link
Author

wwalser commented May 24, 2017

@kenany Perhaps I'm misunderstanding the use of --silent? This change doesn't appear to break the --silent alias, it only changes the exit status code.

Before opening the PR, I checked to be sure that --silent didn't squelch output from npm outdated, because I was worried that this change would break such behavior.

It looks like npm outdated --silent does produce output. In fact, there is a test in outdated-json.js which checks exactly this. My change did have a test failure but it was just a place where I had missed updating the expected error code. I've since fixed this test.

Here is an example run of npm outdated --silent with my system installed NPM:
screen shot 2017-05-24 at 10 38 04 am

@kenany
Copy link
Contributor

kenany commented May 24, 2017

Sorry, I should've provided an example. Let's say I've configured my global .npmrc to have:

loglevel=http

Without this patch:

$ npm install object-assign
# get `loglevel=http` output

$ npm install --silent object-assign
# get `loglevel=silent` output

With this patch:

$ npm install object-assign
# get `loglevel=http` output

$ npm install --silent object-assign
# still get `loglevel=http` output, instead of `loglevel=silent` output

@wwalser
Copy link
Author

wwalser commented May 24, 2017

Thanks for those details but what you're describing is not the case, see the gif below.

This doesn't actually break that feature. It just changes the return code to match what was described in #14013. I mentioned my hesitation with the overlapping flag in my OP. Is that what you're describing?

Here I show a run with an .npmrc containing loglevel=http:

example-with-silent

Checking the log level would work from a code perspective but since loglevel is an orthogonal feature, checking the config makes more sense. It makes what is happening, a configuration parameter specific to outdated has been passed, and enforces documentation requirements for the flag via testing.

My recommendation, from the OP, is that we change the config parameter's name. This avoids the confusion caused by using --silent as a config for both loglevel and outdated.

@kenany
Copy link
Contributor

kenany commented May 24, 2017

Okay, so oddly enough, this doesn't break the feature I mentioned for npm outdated specifically. I'm not sure yet why there's a difference, but my example above does demonstrate the issue I'm talking about (at least on my machine 😄).

@wwalser
Copy link
Author

wwalser commented May 24, 2017

@kenany You're right. I'm not sure why the same doesn't happen for outdated, but this does cause issues for other commands.

I haven't read enough of the code to tell why exactly. It makes sense that having something that is both a parameter and a shorthand causes a collision but why it functions properly for outdated is a mystery to me.

@iarna
Copy link
Contributor

iarna commented Jun 29, 2017

@wwalser This patch is breaking things because --silent is already an option, see the shorthands in lib/config/defaults.js.

@wwalser
Copy link
Author

wwalser commented Jun 30, 2017

@iarna Yes, that's discussed in the comments here, in the bug, and in the original change that introduced the bug. My proposed solution is to rename the flag or drop this fix and accept the knock on regressions. I'm happy with any decision. The bug this caused for me has been fixed down stream by ignoring the exit code.

@zkat
Copy link
Contributor

zkat commented Jul 10, 2018

Hi! We're moving repos to https://github.com/npm/cli/pulls! See our blog post about the migration to npm.community for details. As such, we're closing all active PRs on this repo.

Could you please re-open this PR against npm/cli instead? We're still interested in this patch so we hope you will! We'll continue discussion over there once it's moved. 💚

@zkat zkat closed this Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants