Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(outdated): parse aliased modules #4365

Merged
merged 1 commit into from
Feb 3, 2022
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
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)
})