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

feat(config): add in-range #3397

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/content/commands/npm-outdated.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ description: Check for outdated packages
```bash
npm outdated [[<@scope>/]<pkg> ...]
```

### Description

This command will check the registry to see if any (or, specific) installed
Expand Down Expand Up @@ -97,6 +96,16 @@ When running `npm outdated` and `npm ls`, setting `--all` will show all
outdated or installed packages, rather than only those directly depended
upon by the current project.

#### `in-range`

* Default: null
* Type: null or Boolean

When running `npm outdated` setting `--in-range` will limit output to only
those packages with existing versions in range of the current project's
dependencies. `--no-in-range` will limit output to only those packages with
updates that are out of range of the current project's dependencies.

Comment on lines +104 to +108
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so with these options, how do i override NPM_CONFIG_IN_RANGE=false npm outdated (or true)? do i have to do --in-range=null?

Generally a boolean isn't a great choice when there's three options, so perhaps an enum would be clearer here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb see the discussion on the if statements above, it is as you say checking for the default null vs an explicit true or false. I agree it's not ideal and that discussion is why this PR went back to draft status to be discussed and solved as part of a better solution that lets npm update --dry-run solve the "What can be updated problem" first.

#### `json`

* Default: false
Expand Down Expand Up @@ -162,6 +171,7 @@ This value is not exported to the environment for child processes.
### See Also

* [npm update](/commands/npm-update)
* [npm explain](/commmands/explain)
* [npm dist-tag](/commands/npm-dist-tag)
* [npm registry](/using-npm/registry)
* [npm folders](/configuring-npm/folders)
Expand Down
10 changes: 10 additions & 0 deletions docs/content/using-npm/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@ Note that commands explicitly intended to run a particular script, such as
will still run their intended script if `ignore-scripts` is set, but they
will *not* run any pre- or post-scripts.

#### `in-range`

* Default: null
* Type: null or Boolean

When running `npm outdated` setting `--in-range` will limit output to only
those packages with existing versions in range of the current project's
dependencies. `--no-in-range` will limit output to only those packages with
updates that are out of range of the current project's dependencies.

#### `include`

* Default:
Expand Down
8 changes: 7 additions & 1 deletion lib/explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ class Explain extends ArboristWorkspaceCmd {

/* istanbul ignore next - see test/lib/load-all-commands.js */
static get usage () {
return ['<folder | specifier>']
return [
'<folder>',
'[<@scope>/]<pkg>',
'[<@scope>/]<pkg>@<tag>',
'[<@scope>/]<pkg>@<version>',
'[<@scope>/]<pkg>@<version range>',
]
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
Expand Down
31 changes: 20 additions & 11 deletions lib/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Outdated extends ArboristWorkspaceCmd {
static get params () {
return [
'all',
'in-range',
'json',
'long',
'parseable',
Expand Down Expand Up @@ -116,6 +117,7 @@ class Outdated extends ArboristWorkspaceCmd {
stringLength: s => ansiTrim(s).length,
}
this.npm.output(table(outTable, tableOpts))
this.npm.output('\nFor more info on why dependencies have been installed at their current version, see:\n npm explain <pkg>')
}
}

Expand Down Expand Up @@ -231,17 +233,24 @@ class Outdated extends ArboristWorkspaceCmd {
this.maybeWorkspaceName(edge.from)
: 'global'

this.list.push({
name: edge.name,
path,
type,
current,
location,
wanted: wanted.version,
latest: latest.version,
dependent,
homepage: packument.homepage,
})
const include =
this.npm.config.get('in-range') === null ||
(this.npm.config.get('in-range') === true && wanted.version === latest.version) ||
(this.npm.config.get('in-range') === false && wanted.version !== latest.version)

if (include) {
this.list.push({
name: edge.name,
path,
type,
current,
location,
wanted: wanted.version,
latest: latest.version,
dependent,
homepage: packument.homepage,
})
}
}
} catch (err) {
// silently catch and ignore ETARGET, E403 &
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,19 @@ define('init.version', {
`,
})

define('in-range', {
default: null,
type: [null, Boolean],
description: `
When running \`npm outdated\` setting \`--in-range\` will limit output to
only those packages with existing versions in range of the current
project's dependencies. \`--no-in-range\` will limit output to only those
packages with updates that are out of range of the current project's
dependencies.
`,
flatten,
})

define('json', {
default: false,
type: Boolean,
Expand Down
3 changes: 3 additions & 0 deletions tap-snapshots/smoke-tests/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ exports[`smoke-tests/index.js TAP npm outdated > should have expected outdated o
Package Current Wanted Latest Location Depended by
abbrev 1.0.4 1.1.1 1.1.1 node_modules/abbrev project

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>

`

exports[`smoke-tests/index.js TAP npm prefix > should have expected prefix output 1`] = `
Expand Down
8 changes: 6 additions & 2 deletions tap-snapshots/test/lib/load-all-commands.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ npm explain
Explain installed packages

Usage:
npm explain <folder | specifier>
npm explain <folder>
npm explain [<@scope>/]<pkg>
npm explain [<@scope>/]<pkg>@<tag>
npm explain [<@scope>/]<pkg>@<version>
npm explain [<@scope>/]<pkg>@<version range>

Options:
[--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
Expand Down Expand Up @@ -624,7 +628,7 @@ Usage:
npm outdated [[<@scope>/]<pkg> ...]

Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global]
[-a|--all] [--in-range] [--json] [-l|--long] [-p|--parseable] [-g|--global]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]

Run "npm help outdated" for more info
Expand Down
62 changes: 62 additions & 0 deletions tap-snapshots/test/lib/outdated.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --in-range > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --json --long > must match snapshot 1`] = `
Expand Down Expand Up @@ -89,6 +103,18 @@ cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps peerDependencies
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps dependencies
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps dependencies

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --no-in-range > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=dev --omit=peer > must match snapshot 1`] = `
Expand All @@ -97,6 +123,9 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=d
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=dev > must match snapshot 1`] = `
Expand All @@ -106,6 +135,9 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=d
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=prod > must match snapshot 1`] = `
Expand All @@ -114,6 +146,9 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=p
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `
Expand All @@ -139,18 +174,27 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated > must m
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated global > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat global

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated specific dep > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP workspaces > should display all dependencies 1`] = `
Expand All @@ -160,6 +204,9 @@ cat 1.0.0 1.0.1 1.0.1 node_modules/cat a@1.0.0
chai 1.0.0 1.0.1 1.0.1 node_modules/chai foo
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-workspaces
theta MISSING 1.0.1 1.0.1 - c@1.0.0

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP workspaces > should display json results filtered by ws 1`] = `
Expand All @@ -179,13 +226,19 @@ exports[`test/lib/outdated.js TAP workspaces > should display missing deps when

Package Current Wanted Latest Location Depended by
theta MISSING 1.0.1 1.0.1 - c@1.0.0

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP workspaces > should display nested deps when filtering by ws and using --all 1`] = `

Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat a@1.0.0
chai 1.0.0 1.0.1 1.0.1 node_modules/chai foo

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP workspaces > should display no results if ws has no deps to display 1`] = `
Expand All @@ -201,6 +254,9 @@ exports[`test/lib/outdated.js TAP workspaces > should display results filtered b

Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat a@1.0.0

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP workspaces > should display ws outdated deps human output 1`] = `
Expand All @@ -209,6 +265,9 @@ Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat a@1.0.0
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-workspaces
theta MISSING 1.0.1 1.0.1 - c@1.0.0

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`

exports[`test/lib/outdated.js TAP workspaces > should display ws outdated deps json output 1`] = `
Expand Down Expand Up @@ -249,4 +308,7 @@ exports[`test/lib/outdated.js TAP workspaces > should highlight ws in dependend
cat 1.0.0 1.0.1 1.0.1 node_modules/cat a@1.0.0
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-workspaces
theta MISSING 1.0.1 1.0.1 - c@1.0.0

For more info on why dependencies have been installed at their current version, see:
npm explain <pkg>
`
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Array [
"init.license",
"init.module",
"init.version",
"in-range",
"json",
"key",
"legacy-bundling",
Expand Down
10 changes: 10 additions & 0 deletions tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,16 @@ Note that commands explicitly intended to run a particular script, such as
will still run their intended script if \`ignore-scripts\` is set, but they
will *not* run any pre- or post-scripts.

#### \`in-range\`

* Default: null
* Type: null or Boolean

When running \`npm outdated\` setting \`--in-range\` will limit output to only
those packages with existing versions in range of the current project's
dependencies. \`--no-in-range\` will limit output to only those packages with
updates that are out of range of the current project's dependencies.

#### \`include\`

* Default:
Expand Down
8 changes: 6 additions & 2 deletions tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ All commands:
Explain installed packages

Usage:
npm explain <folder | specifier>
npm explain <folder>
npm explain [<@scope>/]<pkg>
npm explain [<@scope>/]<pkg>@<tag>
npm explain [<@scope>/]<pkg>@<version>
npm explain [<@scope>/]<pkg>@<version range>

Options:
[--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
Expand Down Expand Up @@ -715,7 +719,7 @@ All commands:
npm outdated [[<@scope>/]<pkg> ...]

Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global]
[-a|--all] [--in-range] [--json] [-l|--long] [-p|--parseable] [-g|--global]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]

Run "npm help outdated" for more info
Expand Down
Loading