Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(outdated): add dependent location in long output #8110

Merged
merged 2 commits into from
Apr 11, 2025
Merged
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
1 change: 1 addition & 0 deletions docs/lib/content/commands/npm-outdated.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ In the output:
included in `package.json` are always marked `dependencies`.
* `homepage` (when using `--long` / `-l`) is the `homepage` value contained
in the package's packument
* `depended by location` (when using `--long` / `-l`) shows location of the package that depends on the displayed dependency
* Red means there's a newer version matching your semver requirements, so
you should update now.
* Yellow indicates that there's a newer version _above_ your semver
Expand Down
14 changes: 10 additions & 4 deletions lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class Outdated extends ArboristWorkspaceCmd {
wanted: wanted.version,
latest: latest.version,
workspaceDependent: edge.from?.isWorkspace ? edge.from.pkgid : null,
dependedByLocation: edge.from?.name
? edge.from?.location
: 'global',
dependent: edge.from?.name ?? 'global',
homepage: packument.homepage,
})
Expand Down Expand Up @@ -226,7 +229,7 @@ class Outdated extends ArboristWorkspaceCmd {
'Latest',
'Location',
'Depended by',
...long ? ['Package Type', 'Homepage'] : [],
...long ? ['Package Type', 'Homepage', 'Depended By Location'] : [],
].map(h => bold.underline(h)),
...list.map((d) => [
d.current === d.wanted ? yellow(d.name) : red(d.name),
Expand All @@ -235,7 +238,7 @@ class Outdated extends ArboristWorkspaceCmd {
blue(d.latest),
d.location ?? '-',
d.workspaceDependent ? blue(d.workspaceDependent) : d.dependent,
...long ? [d.type, blue(d.homepage ?? '')] : [],
...long ? [d.type, blue(d.homepage ?? ''), d.dependedByLocation] : [],
]),
], {
align: ['l', 'r', 'r', 'r', 'l'],
Expand All @@ -252,7 +255,7 @@ class Outdated extends ArboristWorkspaceCmd {
d.current ? `${d.name}@${d.current}` : 'MISSING',
`${d.name}@${d.latest}`,
d.dependent,
...this.npm.config.get('long') ? [d.type, d.homepage] : [],
...this.npm.config.get('long') ? [d.type, d.homepage, d.dependedByLocation] : [],
].join(':')).join('\n')
}

Expand All @@ -268,7 +271,10 @@ class Outdated extends ArboristWorkspaceCmd {
latest: d.latest,
dependent: d.dependent,
location: d.path,
...this.npm.config.get('long') ? { type: d.type, homepage: d.homepage } : {},
...this.npm.config.get('long') ? {
type: d.type,
homepage: d.homepage,
dependedByLocation: d.dependedByLocation } : {},
}
acc[d.name] = acc[d.name]
// If this item alread has an outdated dep then we turn it into an array
Expand Down
53 changes: 44 additions & 9 deletions tap-snapshots/test/lib/commands/outdated.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@ Package Current Wanted Latest Location Depended by
cat:dog@^1.0.0 1.0.0 1.0.1 2.0.0 node_modules/cat prefix
`

exports[`test/lib/commands/outdated.js TAP dependent location --long --json > should display dependent location when using --long and --json 1`] = `
{
"dog": [
{
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "2.0.0",
"dependent": "a",
"location": "{CWD}/prefix/node_modules/dog",
"type": "dependencies",
"dependedByLocation": "a"
},
{
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "2.0.0",
"dependent": "a",
"location": "{CWD}/prefix/node_modules/dog",
"type": "dependencies",
"dependedByLocation": "nest/a"
}
]
}
`

exports[`test/lib/commands/outdated.js TAP dependent location --long > should display dependent location when using --long 1`] = `
Package Current Wanted Latest Location Depended by Package Type Homepage Depended By Location
dog 1.0.0 1.0.1 2.0.0 node_modules/dog a@1.0.0 dependencies a
dog 1.0.0 1.0.1 2.0.0 node_modules/dog a@npm:nest-a@1.0.0 dependencies nest/a
`

exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --all > must match snapshot 1`] = `
Package Current Wanted Latest Location Depended by
cat 1.0.0 1.0.1 1.0.1 node_modules/cat prefix
Expand All @@ -31,29 +62,33 @@ exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated
"latest": "1.0.1",
"dependent": "prefix",
"location": "{CWD}/prefix/node_modules/cat",
"type": "dependencies"
"type": "dependencies",
"dependedByLocation": ""
},
"chai": {
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "prefix",
"location": "{CWD}/prefix/node_modules/chai",
"type": "peerDependencies"
"type": "peerDependencies",
"dependedByLocation": ""
},
"dog": {
"current": "1.0.1",
"wanted": "1.0.1",
"latest": "2.0.0",
"dependent": "prefix",
"location": "{CWD}/prefix/node_modules/dog",
"type": "dependencies"
"type": "dependencies",
"dependedByLocation": ""
},
"theta": {
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "prefix",
"type": "dependencies"
"type": "dependencies",
"dependedByLocation": ""
}
}
`
Expand Down Expand Up @@ -90,7 +125,7 @@ exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated
`

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

exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `
{CWD}/prefix/node_modules/cat:cat@1.0.1:cat@1.0.0:cat@1.0.1:prefix:dependencies:
{CWD}/prefix/node_modules/chai:chai@1.0.1:chai@1.0.0:chai@1.0.1:prefix:peerDependencies:
{CWD}/prefix/node_modules/dog:dog@1.0.1:dog@1.0.1:dog@2.0.0:prefix:dependencies:
:theta@1.0.1:MISSING:theta@1.0.1:prefix:dependencies:
{CWD}/prefix/node_modules/cat:cat@1.0.1:cat@1.0.0:cat@1.0.1:prefix:dependencies::
{CWD}/prefix/node_modules/chai:chai@1.0.1:chai@1.0.0:chai@1.0.1:prefix:peerDependencies::
{CWD}/prefix/node_modules/dog:dog@1.0.1:dog@1.0.1:dog@2.0.0:prefix:dependencies::
:theta@1.0.1:MISSING:theta@1.0.1:prefix:dependencies::
`

exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --parseable > must match snapshot 1`] = `
Expand Down
69 changes: 69 additions & 0 deletions test/lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,72 @@ t.test('aliases with version range', async t => {
)
t.equal(process.exitCode, 1)
})

t.test('dependent location', async t => {
const testDir = {
'package.json': JSON.stringify({
name: 'similer-name',
version: '1.0.0',
workspaces: ['a', 'nest/a'],
}),
a: {
'package.json': JSON.stringify({
name: 'a',
version: '1.0.0',
dependencies: {
dog: '^1.0.0',
},
}),
},
nest: {
a: {
'package.json': JSON.stringify({
name: 'nest-a',
version: '1.0.0',
dependencies: {
dog: '^1.0.0',
},
}),
},
},
node_modules: {
dog: {
'package.json': JSON.stringify({
name: 'dog',
version: '1.0.0',
}),
},
a: t.fixture('symlink', '../a'),
'nest-a': t.fixture('symlink', '../nest/a'),
},

}
t.test(`--long`, async t => {
const { outdated, joinedOutput } = await mockNpm(t, {
prefixDir: testDir,
config: {
long: true,
},
})
await outdated.exec([])
t.matchSnapshot(
joinedOutput(),
'should display dependent location when using --long'
)
})

t.test('--long --json', async t => {
const { outdated, joinedOutput } = await mockNpm(t, {
prefixDir: testDir,
config: {
long: true,
json: true,
},
})
await outdated.exec([])
t.matchSnapshot(
joinedOutput(),
'should display dependent location when using --long and --json'
)
})
})
Loading