From 22731831e22011e32fa0ca12178e242c2ee2b33d Mon Sep 17 00:00:00 2001 From: milaninfy <111582375+milaninfy@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:54:54 -0400 Subject: [PATCH] fix(outdated): fixed wanted range for alias with version range (#7595) Fix: #7573 --- lib/commands/outdated.js | 4 +-- .../test/lib/commands/outdated.js.test.cjs | 5 +++ test/lib/commands/outdated.js | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/commands/outdated.js b/lib/commands/outdated.js index e8bba47cc213f..c401c0d50a5cd 100644 --- a/lib/commands/outdated.js +++ b/lib/commands/outdated.js @@ -153,8 +153,8 @@ class Outdated extends ArboristWorkspaceCmd { } async #getOutdatedInfo (edge) { - const alias = safeNpa(edge.spec)?.subSpec?.name - const spec = npa(alias ?? edge.name) + const alias = safeNpa(edge.spec)?.subSpec + const spec = npa(alias ? alias.name : edge.name) const node = edge.to || edge const { path, location, package: { version: current } = {} } = node diff --git a/tap-snapshots/test/lib/commands/outdated.js.test.cjs b/tap-snapshots/test/lib/commands/outdated.js.test.cjs index 943f1ef074e68..d15bbfc815e17 100644 --- a/tap-snapshots/test/lib/commands/outdated.js.test.cjs +++ b/tap-snapshots/test/lib/commands/outdated.js.test.cjs @@ -10,6 +10,11 @@ Package Current Wanted Latest Location Depended by cat:dog@latest 1.0.0 2.0.0 2.0.0 node_modules/cat prefix ` +exports[`test/lib/commands/outdated.js TAP aliases with version range > should display aliased outdated dep output with correct wanted values 1`] = ` +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 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 diff --git a/test/lib/commands/outdated.js b/test/lib/commands/outdated.js index 27e674c76470a..34e60d911bff4 100644 --- a/test/lib/commands/outdated.js +++ b/test/lib/commands/outdated.js @@ -631,3 +631,34 @@ t.test('aliases', async t => { t.matchSnapshot(joinedOutput(), 'should display aliased outdated dep output') t.equal(process.exitCode, 1) }) + +t.test('aliases with version range', async t => { + const testDir = { + 'package.json': JSON.stringify({ + name: 'display-aliases', + version: '1.0.0', + dependencies: { + cat: 'npm:dog@^1.0.0', + }, + }), + node_modules: { + cat: { + 'package.json': JSON.stringify({ + name: 'dog', + version: '1.0.0', + }), + }, + }, + } + + const { outdated, joinedOutput } = await mockNpm(t, { + prefixDir: testDir, + }) + await outdated.exec([]) + + t.matchSnapshot( + joinedOutput(), + 'should display aliased outdated dep output with correct wanted values' + ) + t.equal(process.exitCode, 1) +})