Skip to content

Commit

Permalink
fix(outdated): parse aliased modules
Browse files Browse the repository at this point in the history
Fixes `npm outdated` to properly parse and display info on aliased
packages.

Fixes: #2800
  • Loading branch information
ruyadorno committed Feb 3, 2022
1 parent c0519ed commit ebb4283
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ class Outdated extends ArboristWorkspaceCmd {
}

async getOutdatedInfo (edge) {
const spec = npa(edge.name)
let alias = false
try {
alias = npa(edge.spec).subSpec
} catch (err) {
}
const spec = npa(alias ? alias.name : edge.name)
const node = edge.to || edge
const { path, location } = node
const { version: current } = node.package || {}
Expand All @@ -217,7 +222,7 @@ class Outdated extends ArboristWorkspaceCmd {

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

this.list.push({
name: edge.name,
name: alias ? edge.spec.replace('npm', edge.name) : edge.name,
path,
type,
current,
Expand Down
6 changes: 6 additions & 0 deletions tap-snapshots/test/lib/commands/outdated.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/commands/outdated.js TAP aliases > should display aliased outdated dep output 1`] = `
Package Current Wanted Latest Location Depended by
cat:dog@latest 1.0.0 2.0.0 2.0.0 node_modules/cat tap-testdir-outdated-aliases
`

exports[`test/lib/commands/outdated.js TAP should display outdated deps outdated --all > must match snapshot 1`] = `
Package Current Wanted Latest Location Depended by
Expand Down
25 changes: 25 additions & 0 deletions test/lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,28 @@ t.test('workspaces', async t => {
t.matchSnapshot(logs,
'should display missing deps when filtering by ws')
})

t.test('aliases', async t => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'display-aliases',
version: '1.0.0',
dependencies: {
cat: 'npm:dog@latest',
},
}),
node_modules: {
cat: {
'package.json': JSON.stringify({
name: 'dog',
version: '1.0.0',
}),
},
},
})

await outdated(testDir, {}).exec([])

t.matchSnapshot(logs, 'should display aliased outdated dep output')
t.equal(process.exitCode, 1)
})

0 comments on commit ebb4283

Please sign in to comment.