Skip to content

Commit d893cb2

Browse files
committed
fix(plugin-js-packages): pnpm outdated fallback
1 parent e1152f2 commit d893cb2

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

packages/plugin-js-packages/src/lib/package-managers/pnpm/outdated-result.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export function pnpmToOutdatedResult(output: string): OutdatedResult {
88
filterOutWarnings(output),
99
) as PnpmOutdatedResultJson;
1010

11+
// "current" may be missing if package is not installed
12+
// Fallback to "wanted" - same approach as npm
1113
return objectToEntries(pnpmOutdated).map(
12-
([name, { current, latest, dependencyType: type }]) => ({
14+
([name, { current, latest, wanted, dependencyType: type }]) => ({
1315
name,
14-
current,
16+
current: current || wanted,
1517
latest,
1618
type,
1719
}),

packages/plugin-js-packages/src/lib/package-managers/pnpm/outdated-result.unit.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ describe('pnpmToOutdatedResult', () => {
1111
cypress: {
1212
current: '8.5.0',
1313
latest: '13.6.0',
14+
wanted: '8.5.0',
1415
dependencyType: 'devDependencies',
1516
},
1617
'@cypress/request': {
1718
current: '2.88.10',
1819
latest: '3.0.0',
20+
wanted: '2.88.10',
1921
dependencyType: 'devDependencies',
2022
},
2123
} satisfies PnpmOutdatedResultJson),
@@ -49,11 +51,13 @@ describe('pnpmToOutdatedResult', () => {
4951
"cypress": {
5052
"current": "8.5.0",
5153
"latest": "13.6.0",
54+
"wanted": "8.5.0",
5255
"dependencyType": "devDependencies"
5356
},
5457
"@cypress/request": {
5558
"current": "2.88.10",
5659
"latest": "3.0.0",
60+
"wanted": "2.88.10",
5761
"dependencyType": "devDependencies"
5862
}
5963
}
@@ -74,4 +78,35 @@ describe('pnpmToOutdatedResult', () => {
7478
},
7579
]);
7680
});
81+
82+
it('should handle dependencies with missing current version by falling back to wanted', () => {
83+
const output = JSON.stringify({
84+
'@angular/animations': {
85+
latest: '21.0.1',
86+
wanted: '20.3.12',
87+
dependencyType: 'dependencies',
88+
},
89+
rxjs: {
90+
current: '7.8.0',
91+
latest: '7.8.1',
92+
wanted: '7.8.0',
93+
dependencyType: 'dependencies',
94+
},
95+
});
96+
97+
expect(pnpmToOutdatedResult(output)).toEqual([
98+
{
99+
name: '@angular/animations',
100+
current: '20.3.12',
101+
latest: '21.0.1',
102+
type: 'dependencies',
103+
},
104+
{
105+
name: 'rxjs',
106+
current: '7.8.0',
107+
latest: '7.8.1',
108+
type: 'dependencies',
109+
},
110+
]);
111+
});
77112
});

packages/plugin-js-packages/src/lib/package-managers/pnpm/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export type PnpmAuditResultJson = {
2020

2121
// Subset of PNPM outdated JSON type
2222
export type PnpmVersionOverview = {
23-
current: string;
23+
current?: string;
2424
latest: string;
25+
wanted: string;
2526
dependencyType: DependencyGroupLong;
2627
};
2728
export type PnpmOutdatedResultJson = Record<string, PnpmVersionOverview>;

0 commit comments

Comments
 (0)