-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhandle-package-info.ts
52 lines (45 loc) · 1.23 KB
/
handle-package-info.ts
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
import process from 'node:process'
import { hasKeys } from '@socketsecurity/registry/lib/objects'
import { fetchPackageInfo } from './fetch-package-info'
import { outputPackageInfo } from './output-package-info'
import type { SocketSdkAlert } from '../../utils/alert/severity'
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
export interface PackageData {
data: SocketSdkReturnType<'getIssuesByNPMPackage'>['data']
severityCount: Record<SocketSdkAlert['severity'], number>
score: SocketSdkReturnType<'getScoreByNPMPackage'>['data']
}
export async function handlePackageInfo({
commandName,
includeAllIssues,
outputKind,
pkgName,
pkgVersion,
strict
}: {
commandName: string
includeAllIssues: boolean
outputKind: 'json' | 'markdown' | 'print'
pkgName: string
pkgVersion: string
strict: boolean
}) {
const packageData = await fetchPackageInfo(
pkgName,
pkgVersion,
includeAllIssues
)
if (packageData) {
outputPackageInfo(packageData, {
name: commandName,
includeAllIssues,
outputKind,
pkgName,
pkgVersion
})
if (strict && hasKeys(packageData.severityCount)) {
// Let NodeJS exit gracefully but with exit(1)
process.exitCode = 1
}
}
}