Skip to content

Commit ebb4283

Browse files
committed
fix(outdated): parse aliased modules
Fixes `npm outdated` to properly parse and display info on aliased packages. Fixes: #2800
1 parent c0519ed commit ebb4283

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

lib/commands/outdated.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ class Outdated extends ArboristWorkspaceCmd {
193193
}
194194

195195
async getOutdatedInfo (edge) {
196-
const spec = npa(edge.name)
196+
let alias = false
197+
try {
198+
alias = npa(edge.spec).subSpec
199+
} catch (err) {
200+
}
201+
const spec = npa(alias ? alias.name : edge.name)
197202
const node = edge.to || edge
198203
const { path, location } = node
199204
const { version: current } = node.package || {}
@@ -217,7 +222,7 @@ class Outdated extends ArboristWorkspaceCmd {
217222

218223
try {
219224
const packument = await this.getPackument(spec)
220-
const expected = edge.spec
225+
const expected = alias ? alias.fetchSpec : edge.spec
221226
// if it's not a range, version, or tag, skip it
222227
try {
223228
if (!npa(`${edge.name}@${edge.spec}`).registry) {
@@ -239,7 +244,7 @@ class Outdated extends ArboristWorkspaceCmd {
239244
: 'global'
240245

241246
this.list.push({
242-
name: edge.name,
247+
name: alias ? edge.spec.replace('npm', edge.name) : edge.name,
243248
path,
244249
type,
245250
current,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8+
exports[`test/lib/commands/outdated.js TAP aliases > should display aliased outdated dep output 1`] = `
9+
10+
Package Current Wanted Latest Location Depended by
11+
cat:dog@latest 1.0.0 2.0.0 2.0.0 node_modules/cat tap-testdir-outdated-aliases
12+
`
13+
814
exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --all > must match snapshot 1`] = `
915
1016
Package Current Wanted Latest Location Depended by

test/lib/commands/outdated.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,28 @@ t.test('workspaces', async t => {
609609
t.matchSnapshot(logs,
610610
'should display missing deps when filtering by ws')
611611
})
612+
613+
t.test('aliases', async t => {
614+
const testDir = t.testdir({
615+
'package.json': JSON.stringify({
616+
name: 'display-aliases',
617+
version: '1.0.0',
618+
dependencies: {
619+
cat: 'npm:dog@latest',
620+
},
621+
}),
622+
node_modules: {
623+
cat: {
624+
'package.json': JSON.stringify({
625+
name: 'dog',
626+
version: '1.0.0',
627+
}),
628+
},
629+
},
630+
})
631+
632+
await outdated(testDir, {}).exec([])
633+
634+
t.matchSnapshot(logs, 'should display aliased outdated dep output')
635+
t.equal(process.exitCode, 1)
636+
})

0 commit comments

Comments
 (0)