Skip to content

Commit db8f5da

Browse files
milaninfywraithgar
andauthoredApr 11, 2025··
fix(outdated): add dependent location in long output (#8110)
Add dependent location details when using `--long` version of the output to identify who is the dependent of the outdated dependencies. Fixes: #7736 Test output <img width="1443" alt="Screenshot 2025-04-02 at 1 27 02 PM" src="https://github.com/user-attachments/assets/cf9cd91e-06c1-403b-a57e-53fa9d80ef01" /> --------- Co-authored-by: Gar <wraithgar@github.com>
1 parent 0886e7a commit db8f5da

File tree

4 files changed

+124
-13
lines changed

4 files changed

+124
-13
lines changed
 

‎docs/lib/content/commands/npm-outdated.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ In the output:
3737
included in `package.json` are always marked `dependencies`.
3838
* `homepage` (when using `--long` / `-l`) is the `homepage` value contained
3939
in the package's packument
40+
* `depended by location` (when using `--long` / `-l`) shows location of the package that depends on the displayed dependency
4041
* Red means there's a newer version matching your semver requirements, so
4142
you should update now.
4243
* Yellow indicates that there's a newer version _above_ your semver

‎lib/commands/outdated.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class Outdated extends ArboristWorkspaceCmd {
195195
wanted: wanted.version,
196196
latest: latest.version,
197197
workspaceDependent: edge.from?.isWorkspace ? edge.from.pkgid : null,
198+
dependedByLocation: edge.from?.name
199+
? edge.from?.location
200+
: 'global',
198201
dependent: edge.from?.name ?? 'global',
199202
homepage: packument.homepage,
200203
})
@@ -226,7 +229,7 @@ class Outdated extends ArboristWorkspaceCmd {
226229
'Latest',
227230
'Location',
228231
'Depended by',
229-
...long ? ['Package Type', 'Homepage'] : [],
232+
...long ? ['Package Type', 'Homepage', 'Depended By Location'] : [],
230233
].map(h => bold.underline(h)),
231234
...list.map((d) => [
232235
d.current === d.wanted ? yellow(d.name) : red(d.name),
@@ -235,7 +238,7 @@ class Outdated extends ArboristWorkspaceCmd {
235238
blue(d.latest),
236239
d.location ?? '-',
237240
d.workspaceDependent ? blue(d.workspaceDependent) : d.dependent,
238-
...long ? [d.type, blue(d.homepage ?? '')] : [],
241+
...long ? [d.type, blue(d.homepage ?? ''), d.dependedByLocation] : [],
239242
]),
240243
], {
241244
align: ['l', 'r', 'r', 'r', 'l'],
@@ -252,7 +255,7 @@ class Outdated extends ArboristWorkspaceCmd {
252255
d.current ? `${d.name}@${d.current}` : 'MISSING',
253256
`${d.name}@${d.latest}`,
254257
d.dependent,
255-
...this.npm.config.get('long') ? [d.type, d.homepage] : [],
258+
...this.npm.config.get('long') ? [d.type, d.homepage, d.dependedByLocation] : [],
256259
].join(':')).join('\n')
257260
}
258261

@@ -268,7 +271,10 @@ class Outdated extends ArboristWorkspaceCmd {
268271
latest: d.latest,
269272
dependent: d.dependent,
270273
location: d.path,
271-
...this.npm.config.get('long') ? { type: d.type, homepage: d.homepage } : {},
274+
...this.npm.config.get('long') ? {
275+
type: d.type,
276+
homepage: d.homepage,
277+
dependedByLocation: d.dependedByLocation } : {},
272278
}
273279
acc[d.name] = acc[d.name]
274280
// If this item alread has an outdated dep then we turn it into an array

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

+44-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@ Package Current Wanted Latest Location Depended by
1515
cat:dog@^1.0.0 1.0.0 1.0.1 2.0.0 node_modules/cat prefix
1616
`
1717

18+
exports[`test/lib/commands/outdated.js TAP dependent location --long --json > should display dependent location when using --long and --json 1`] = `
19+
{
20+
"dog": [
21+
{
22+
"current": "1.0.0",
23+
"wanted": "1.0.1",
24+
"latest": "2.0.0",
25+
"dependent": "a",
26+
"location": "{CWD}/prefix/node_modules/dog",
27+
"type": "dependencies",
28+
"dependedByLocation": "a"
29+
},
30+
{
31+
"current": "1.0.0",
32+
"wanted": "1.0.1",
33+
"latest": "2.0.0",
34+
"dependent": "a",
35+
"location": "{CWD}/prefix/node_modules/dog",
36+
"type": "dependencies",
37+
"dependedByLocation": "nest/a"
38+
}
39+
]
40+
}
41+
`
42+
43+
exports[`test/lib/commands/outdated.js TAP dependent location --long > should display dependent location when using --long 1`] = `
44+
Package Current Wanted Latest Location Depended by Package Type Homepage Depended By Location
45+
dog 1.0.0 1.0.1 2.0.0 node_modules/dog a@1.0.0 dependencies a
46+
dog 1.0.0 1.0.1 2.0.0 node_modules/dog a@npm:nest-a@1.0.0 dependencies nest/a
47+
`
48+
1849
exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --all > must match snapshot 1`] = `
1950
Package Current Wanted Latest Location Depended by
2051
cat 1.0.0 1.0.1 1.0.1 node_modules/cat prefix
@@ -31,29 +62,33 @@ exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated
3162
"latest": "1.0.1",
3263
"dependent": "prefix",
3364
"location": "{CWD}/prefix/node_modules/cat",
34-
"type": "dependencies"
65+
"type": "dependencies",
66+
"dependedByLocation": ""
3567
},
3668
"chai": {
3769
"current": "1.0.0",
3870
"wanted": "1.0.1",
3971
"latest": "1.0.1",
4072
"dependent": "prefix",
4173
"location": "{CWD}/prefix/node_modules/chai",
42-
"type": "peerDependencies"
74+
"type": "peerDependencies",
75+
"dependedByLocation": ""
4376
},
4477
"dog": {
4578
"current": "1.0.1",
4679
"wanted": "1.0.1",
4780
"latest": "2.0.0",
4881
"dependent": "prefix",
4982
"location": "{CWD}/prefix/node_modules/dog",
50-
"type": "dependencies"
83+
"type": "dependencies",
84+
"dependedByLocation": ""
5185
},
5286
"theta": {
5387
"wanted": "1.0.1",
5488
"latest": "1.0.1",
5589
"dependent": "prefix",
56-
"type": "dependencies"
90+
"type": "dependencies",
91+
"dependedByLocation": ""
5792
}
5893
}
5994
`
@@ -90,7 +125,7 @@ exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated
90125
`
91126

92127
exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --long > must match snapshot 1`] = `
93-
Package Current Wanted Latest Location Depended by Package Type Homepage
128+
Package Current Wanted Latest Location Depended by Package Type Homepage Depended By Location
94129
cat 1.0.0 1.0.1 1.0.1 node_modules/cat prefix dependencies
95130
chai 1.0.0 1.0.1 1.0.1 node_modules/chai prefix peerDependencies
96131
dog 1.0.1 1.0.1 2.0.0 node_modules/dog prefix dependencies
@@ -120,10 +155,10 @@ exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated
120155
`
121156

122157
exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `
123-
{CWD}/prefix/node_modules/cat:cat@1.0.1:cat@1.0.0:cat@1.0.1:prefix:dependencies:
124-
{CWD}/prefix/node_modules/chai:chai@1.0.1:chai@1.0.0:chai@1.0.1:prefix:peerDependencies:
125-
{CWD}/prefix/node_modules/dog:dog@1.0.1:dog@1.0.1:dog@2.0.0:prefix:dependencies:
126-
:theta@1.0.1:MISSING:theta@1.0.1:prefix:dependencies:
158+
{CWD}/prefix/node_modules/cat:cat@1.0.1:cat@1.0.0:cat@1.0.1:prefix:dependencies::
159+
{CWD}/prefix/node_modules/chai:chai@1.0.1:chai@1.0.0:chai@1.0.1:prefix:peerDependencies::
160+
{CWD}/prefix/node_modules/dog:dog@1.0.1:dog@1.0.1:dog@2.0.0:prefix:dependencies::
161+
:theta@1.0.1:MISSING:theta@1.0.1:prefix:dependencies::
127162
`
128163

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

‎test/lib/commands/outdated.js

+69
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,72 @@ t.test('aliases with version range', async t => {
662662
)
663663
t.equal(process.exitCode, 1)
664664
})
665+
666+
t.test('dependent location', async t => {
667+
const testDir = {
668+
'package.json': JSON.stringify({
669+
name: 'similer-name',
670+
version: '1.0.0',
671+
workspaces: ['a', 'nest/a'],
672+
}),
673+
a: {
674+
'package.json': JSON.stringify({
675+
name: 'a',
676+
version: '1.0.0',
677+
dependencies: {
678+
dog: '^1.0.0',
679+
},
680+
}),
681+
},
682+
nest: {
683+
a: {
684+
'package.json': JSON.stringify({
685+
name: 'nest-a',
686+
version: '1.0.0',
687+
dependencies: {
688+
dog: '^1.0.0',
689+
},
690+
}),
691+
},
692+
},
693+
node_modules: {
694+
dog: {
695+
'package.json': JSON.stringify({
696+
name: 'dog',
697+
version: '1.0.0',
698+
}),
699+
},
700+
a: t.fixture('symlink', '../a'),
701+
'nest-a': t.fixture('symlink', '../nest/a'),
702+
},
703+
704+
}
705+
t.test(`--long`, async t => {
706+
const { outdated, joinedOutput } = await mockNpm(t, {
707+
prefixDir: testDir,
708+
config: {
709+
long: true,
710+
},
711+
})
712+
await outdated.exec([])
713+
t.matchSnapshot(
714+
joinedOutput(),
715+
'should display dependent location when using --long'
716+
)
717+
})
718+
719+
t.test('--long --json', async t => {
720+
const { outdated, joinedOutput } = await mockNpm(t, {
721+
prefixDir: testDir,
722+
config: {
723+
long: true,
724+
json: true,
725+
},
726+
})
727+
await outdated.exec([])
728+
t.matchSnapshot(
729+
joinedOutput(),
730+
'should display dependent location when using --long and --json'
731+
)
732+
})
733+
})

0 commit comments

Comments
 (0)
Please sign in to comment.