-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnpm.ts
More file actions
55 lines (52 loc) · 1.83 KB
/
Copy pathnpm.ts
File metadata and controls
55 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { objectToKeys } from '@code-pushup/utils';
import type { DependencyGroup } from '../../config.js';
import { filterAuditResult } from '../../runner/utils.js';
import type { AuditResults, PackageManager } from '../types.js';
import { npmToAuditResult } from './audit-result.js';
import { npmToOutdatedResult } from './outdated-result.js';
const npmDependencyOptions: Record<DependencyGroup, string[]> = {
prod: ['--omit=dev', '--omit=optional'],
dev: ['--include=dev', '--omit=optional'],
optional: ['--include=optional', '--omit=dev'],
};
export const npmPackageManager: PackageManager = {
slug: 'npm',
name: 'NPM',
command: 'npm',
icon: 'npm',
docs: {
homepage: 'https://docs.npmjs.com/',
audit: 'https://docs.npmjs.com/cli/commands/npm-audit',
outdated: 'https://docs.npmjs.com/cli/commands/npm-outdated',
},
audit: {
getCommandArgs: groupDep => [
'audit',
...npmDependencyOptions[groupDep],
'--audit-level=none',
'--json',
],
unifyResult: npmToAuditResult,
// prod dependencies need to be filtered out manually since v10
postProcessResult: (results: AuditResults) => {
const depGroups = objectToKeys(results);
const devFilter =
results.dev && results.prod
? filterAuditResult(results.dev, 'name', results.prod)
: results.dev;
const optionalFilter =
results.optional && results.prod
? filterAuditResult(results.optional, 'name', results.prod)
: results.optional;
return {
...(depGroups.includes('prod') && { prod: results.prod }),
...(depGroups.includes('dev') && { dev: devFilter }),
...(depGroups.includes('optional') && { optional: optionalFilter }),
};
},
},
outdated: {
commandArgs: ['outdated', '--long', '--json'],
unifyResult: npmToOutdatedResult,
},
};