Skip to content

Commit 3f824bb

Browse files
committed
fix(plugin-js-packages-e2e): npm outdated fallback to "wanted" if "current" is missing
happens when package not installed
1 parent 5ef0906 commit 3f824bb

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { objectToEntries } from '@code-pushup/utils';
22
import type { OutdatedResult } from '../../runner/outdated/types.js';
3-
import type { NpmNormalizedOverview, NpmOutdatedResultJson } from './types.js';
3+
import type { NpmOutdatedResultJson } from './types.js';
44

55
export function npmToOutdatedResult(output: string): OutdatedResult {
66
const npmOutdated = JSON.parse(output) as NpmOutdatedResultJson;
7-
// current might be missing in some cases
7+
// "current" might be missing in some cases, usually it is missing if the dependency is not installed, fallback to "wanted" should avoid this problem
88
// https://stackoverflow.com/questions/42267101/npm-outdated-command-shows-missing-in-current-version
9-
return objectToEntries(npmOutdated)
10-
.filter(
11-
(entry): entry is [string, NpmNormalizedOverview] =>
12-
entry[1].current != null,
13-
)
14-
.map(([name, overview]) => ({
15-
name,
16-
current: overview.current,
17-
latest: overview.latest,
18-
type: overview.type,
19-
...(overview.homepage != null && { url: overview.homepage }),
20-
}));
9+
return objectToEntries(npmOutdated).map(([name, overview]) => ({
10+
name,
11+
current: overview.current || overview.wanted,
12+
latest: overview.latest,
13+
type: overview.type,
14+
...(overview.homepage != null && { url: overview.homepage }),
15+
}));
2116
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@ export type NpmAuditResultJson = {
3636
// Subset of NPM outdated JSON type
3737
export type NpmVersionOverview = {
3838
current?: string;
39+
wanted: string;
3940
latest: string;
4041
type: DependencyGroupLong;
4142
homepage?: string;
4243
};
4344

44-
export type NpmNormalizedOverview = Omit<NpmVersionOverview, 'current'> & {
45-
current: string;
46-
};
47-
4845
export type NpmOutdatedResultJson = Record<string, NpmVersionOverview>;

0 commit comments

Comments
 (0)