|
1 | 1 | import { objectToEntries } from '@code-pushup/utils';
|
2 | 2 | import type { OutdatedResult } from '../../runner/outdated/types.js';
|
3 |
| -import type { NpmNormalizedOverview, NpmOutdatedResultJson } from './types.js'; |
| 3 | +import type { NpmOutdatedResultJson } from './types.js'; |
4 | 4 |
|
5 | 5 | export function npmToOutdatedResult(output: string): OutdatedResult {
|
6 | 6 | 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 |
8 | 8 | // 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 | + })); |
21 | 16 | }
|
0 commit comments