Skip to content

Commit 35a35db

Browse files
committed
feat(config): add in-range
This adds a flag for `npm outdated` to use to limit output either to packages that have updates in-range of the current package's requirements, or those that have no updates in-range of the current package's requirements. It also adds to the normal (i.e. non JSON or parseable) output directing folks to use `npm explain` for more info. This is because the output of `npm outdated` is misleading, sometimes saying an available version is present when there is another package in the tree responsible for keeping the version where it is.
1 parent 26c77f3 commit 35a35db

File tree

11 files changed

+151
-17
lines changed

11 files changed

+151
-17
lines changed

docs/content/commands/npm-outdated.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ description: Check for outdated packages
99
```bash
1010
npm outdated [[<@scope>/]<pkg> ...]
1111
```
12-
1312
### Description
1413

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

99+
#### `in-range`
100+
101+
* Default: null
102+
* Type: null or Boolean
103+
104+
When running `npm outdated` setting `--in-range` will limit output to only
105+
those packages with existing versions in range of the current project's
106+
dependencies. `--no-in-range` will limit output to only those packages with
107+
updates that are out of range of the current project's dependencies.
108+
100109
#### `json`
101110

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

164173
* [npm update](/commands/npm-update)
174+
* [npm explain](/using-npm/explain)
165175
* [npm dist-tag](/commands/npm-dist-tag)
166176
* [npm registry](/using-npm/registry)
167177
* [npm folders](/configuring-npm/folders)

docs/content/using-npm/config.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,16 @@ Note that commands explicitly intended to run a particular script, such as
618618
will still run their intended script if `ignore-scripts` is set, but they
619619
will *not* run any pre- or post-scripts.
620620

621+
#### `in-range`
622+
623+
* Default: null
624+
* Type: null or Boolean
625+
626+
When running `npm outdated` setting `--in-range` will limit output to only
627+
those packages with existing versions in range of the current project's
628+
dependencies. `--no-in-range` will limit output to only those packages with
629+
updates that are out of range of the current project's dependencies.
630+
621631
#### `include`
622632

623633
* Default:

lib/explain.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ class Explain extends ArboristWorkspaceCmd {
1919

2020
/* istanbul ignore next - see test/lib/load-all-commands.js */
2121
static get usage () {
22-
return ['<folder | specifier>']
22+
return [
23+
'<folder>',
24+
'[<@scope>/]<pkg>',
25+
'[<@scope>/]<pkg>@<tag>',
26+
'[<@scope>/]<pkg>@<version>',
27+
'[<@scope>/]<pkg>@<version range>',
28+
]
2329
}
2430

2531
/* istanbul ignore next - see test/lib/load-all-commands.js */

lib/outdated.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Outdated extends ArboristWorkspaceCmd {
3232
static get params () {
3333
return [
3434
'all',
35+
'in-range',
3536
'json',
3637
'long',
3738
'parseable',
@@ -116,6 +117,7 @@ class Outdated extends ArboristWorkspaceCmd {
116117
stringLength: s => ansiTrim(s).length,
117118
}
118119
this.npm.output(table(outTable, tableOpts))
120+
this.npm.output('\nFor more info on why dependencies have been installed at their given versions, see `npm explain <pkg>`.')
119121
}
120122
}
121123

@@ -231,17 +233,23 @@ class Outdated extends ArboristWorkspaceCmd {
231233
this.maybeWorkspaceName(edge.from)
232234
: 'global'
233235

234-
this.list.push({
235-
name: edge.name,
236-
path,
237-
type,
238-
current,
239-
location,
240-
wanted: wanted.version,
241-
latest: latest.version,
242-
dependent,
243-
homepage: packument.homepage,
244-
})
236+
const include =
237+
this.npm.config.get('in-range') === null ||
238+
(this.npm.config.get('in-range') === true && wanted === latest) ||
239+
(this.npm.config.get('in-range') === false && wanted !== latest)
240+
241+
if (include)
242+
this.list.push({
243+
name: edge.name,
244+
path,
245+
type,
246+
current,
247+
location,
248+
wanted: wanted.version,
249+
latest: latest.version,
250+
dependent,
251+
homepage: packument.homepage,
252+
})
245253
}
246254
} catch (err) {
247255
// silently catch and ignore ETARGET, E403 &

lib/utils/config/definitions.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,19 @@ define('init.version', {
10221022
`,
10231023
})
10241024

1025+
define('in-range', {
1026+
default: null,
1027+
type: [null, Boolean],
1028+
description: `
1029+
When running \`npm outdated\` setting \`--in-range\` will limit output to
1030+
only those packages with existing versions in range of the current
1031+
project's dependencies. \`--no-in-range\` will limit output to only those
1032+
packages with updates that are out of range of the current project's
1033+
dependencies.
1034+
`,
1035+
flatten,
1036+
})
1037+
10251038
define('json', {
10261039
default: false,
10271040
type: Boolean,

tap-snapshots/test/lib/load-all-commands.js.test.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ npm explain
304304
Explain installed packages
305305
306306
Usage:
307-
npm explain <folder | specifier>
307+
npm explain <folder>
308+
npm explain [<@scope>/]<pkg>
309+
npm explain [<@scope>/]<pkg>@<tag>
310+
npm explain [<@scope>/]<pkg>@<version>
311+
npm explain [<@scope>/]<pkg>@<version range>
308312
309313
Options:
310314
[--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
@@ -624,7 +628,7 @@ Usage:
624628
npm outdated [[<@scope>/]<pkg> ...]
625629
626630
Options:
627-
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global]
631+
[-a|--all] [--in-range] [--json] [-l|--long] [-p|--parseable] [-g|--global]
628632
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
629633
630634
Run "npm help outdated" for more info

tap-snapshots/test/lib/outdated.js.test.cjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should
1212
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
1313
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
1414
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps
15+
16+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
17+
`
18+
19+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --in-range > must match snapshot 1`] = `
20+
21+
Package Current Wanted Latest Location Depended by
22+
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
23+
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
24+
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps
25+
26+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
1527
`
1628

1729
exports[`test/lib/outdated.js TAP should display outdated deps outdated --json --long > must match snapshot 1`] = `
@@ -89,6 +101,16 @@ cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should
89101
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps peerDependencies
90102
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps dependencies
91103
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps dependencies
104+
105+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
106+
`
107+
108+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --no-in-range > must match snapshot 1`] = `
109+
110+
Package Current Wanted Latest Location Depended by
111+
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
112+
113+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
92114
`
93115

94116
exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=dev --omit=peer > must match snapshot 1`] = `
@@ -97,6 +119,8 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=d
97119
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
98120
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
99121
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps
122+
123+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
100124
`
101125

102126
exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=dev > must match snapshot 1`] = `
@@ -106,6 +130,8 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=d
106130
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
107131
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
108132
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps
133+
134+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
109135
`
110136

111137
exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=prod > must match snapshot 1`] = `
@@ -114,6 +140,8 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=p
114140
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
115141
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
116142
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
143+
144+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
117145
`
118146

119147
exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `
@@ -139,18 +167,24 @@ exports[`test/lib/outdated.js TAP should display outdated deps outdated > must m
139167
chai 1.0.0 1.0.1 1.0.1 node_modules/chai tap-testdir-outdated-should-display-outdated-deps
140168
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-should-display-outdated-deps
141169
theta MISSING 1.0.1 1.0.1 - tap-testdir-outdated-should-display-outdated-deps
170+
171+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
142172
`
143173

144174
exports[`test/lib/outdated.js TAP should display outdated deps outdated global > must match snapshot 1`] = `
145175
146176
Package Current Wanted Latest Location Depended by
147177
cat 1.0.0 1.0.1 1.0.1 node_modules/cat global
178+
179+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
148180
`
149181

150182
exports[`test/lib/outdated.js TAP should display outdated deps outdated specific dep > must match snapshot 1`] = `
151183
152184
Package Current Wanted Latest Location Depended by
153185
cat 1.0.0 1.0.1 1.0.1 node_modules/cat tap-testdir-outdated-should-display-outdated-deps
186+
187+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
154188
`
155189

156190
exports[`test/lib/outdated.js TAP workspaces > should display all dependencies 1`] = `
@@ -160,6 +194,8 @@ cat 1.0.0 1.0.1 1.0.1 node_modules/cat [email protected]
160194
chai 1.0.0 1.0.1 1.0.1 node_modules/chai foo
161195
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-workspaces
162196
theta MISSING 1.0.1 1.0.1 - [email protected]
197+
198+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
163199
`
164200

165201
exports[`test/lib/outdated.js TAP workspaces > should display json results filtered by ws 1`] = `
@@ -179,13 +215,17 @@ exports[`test/lib/outdated.js TAP workspaces > should display missing deps when
179215
180216
Package Current Wanted Latest Location Depended by
181217
theta MISSING 1.0.1 1.0.1 - [email protected]
218+
219+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
182220
`
183221

184222
exports[`test/lib/outdated.js TAP workspaces > should display nested deps when filtering by ws and using --all 1`] = `
185223
186224
Package Current Wanted Latest Location Depended by
187225
cat 1.0.0 1.0.1 1.0.1 node_modules/cat [email protected]
188226
chai 1.0.0 1.0.1 1.0.1 node_modules/chai foo
227+
228+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
189229
`
190230

191231
exports[`test/lib/outdated.js TAP workspaces > should display no results if ws has no deps to display 1`] = `
@@ -201,6 +241,8 @@ exports[`test/lib/outdated.js TAP workspaces > should display results filtered b
201241
202242
Package Current Wanted Latest Location Depended by
203243
cat 1.0.0 1.0.1 1.0.1 node_modules/cat [email protected]
244+
245+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
204246
`
205247

206248
exports[`test/lib/outdated.js TAP workspaces > should display ws outdated deps human output 1`] = `
@@ -209,6 +251,8 @@ Package Current Wanted Latest Location Depended by
209251
cat 1.0.0 1.0.1 1.0.1 node_modules/cat [email protected]
210252
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-workspaces
211253
theta MISSING 1.0.1 1.0.1 - [email protected]
254+
255+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
212256
`
213257

214258
exports[`test/lib/outdated.js TAP workspaces > should display ws outdated deps json output 1`] = `
@@ -249,4 +293,6 @@ exports[`test/lib/outdated.js TAP workspaces > should highlight ws in dependend
249293
cat 1.0.0 1.0.1 1.0.1 node_modules/cat [[email protected]
250294
dog 1.0.1 1.0.1 2.0.0 node_modules/dog tap-testdir-outdated-workspaces
251295
theta MISSING 1.0.1 1.0.1 - [[email protected]
296+
297+
For more info on why dependencies have been installed at their given versions, see \`npm explain <pkg>\`.
252298
`

tap-snapshots/test/lib/utils/config/definitions.js.test.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Array [
7575
"init.license",
7676
"init.module",
7777
"init.version",
78+
"in-range",
7879
"json",
7980
"key",
8081
"legacy-bundling",

tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,16 @@ Note that commands explicitly intended to run a particular script, such as
497497
will still run their intended script if \`ignore-scripts\` is set, but they
498498
will *not* run any pre- or post-scripts.
499499
500+
#### \`in-range\`
501+
502+
* Default: null
503+
* Type: null or Boolean
504+
505+
When running \`npm outdated\` setting \`--in-range\` will limit output to only
506+
those packages with existing versions in range of the current project's
507+
dependencies. \`--no-in-range\` will limit output to only those packages with
508+
updates that are out of range of the current project's dependencies.
509+
500510
#### \`include\`
501511
502512
* Default:

tap-snapshots/test/lib/utils/npm-usage.js.test.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ All commands:
429429
Explain installed packages
430430
431431
Usage:
432-
npm explain <folder | specifier>
432+
npm explain <folder>
433+
npm explain [<@scope>/]<pkg>
434+
npm explain [<@scope>/]<pkg>@<tag>
435+
npm explain [<@scope>/]<pkg>@<version>
436+
npm explain [<@scope>/]<pkg>@<version range>
433437
434438
Options:
435439
[--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
@@ -715,7 +719,7 @@ All commands:
715719
npm outdated [[<@scope>/]<pkg> ...]
716720
717721
Options:
718-
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global]
722+
[-a|--all] [--in-range] [--json] [-l|--long] [-p|--parseable] [-g|--global]
719723
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
720724
721725
Run "npm help outdated" for more info

0 commit comments

Comments
 (0)