-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathhandleFinish.ts
54 lines (49 loc) · 1.71 KB
/
handleFinish.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
53
54
import { AuditLevel } from 'src/types';
import { printSecurityReport } from '../utils/print';
import { processAuditJson, handleUnusedExceptions } from '../utils/vulnerability';
/**
* Process and analyze the NPM audit JSON
* @param {String} jsonBuffer NPM audit stringified JSON payload
* @param {Number} auditLevel The level of vulnerabilities we care about
* @param {Array} exceptionIds List of vulnerability IDs to exclude
* @param {Array} exceptionModules List of vulnerable modules to ignore in audit results
* @param {Array} columnsToInclude List of columns to include in audit results
*/
export default function handleFinish(
jsonBuffer: string,
auditLevel: AuditLevel,
exceptionIds: string[],
exceptionModules: string[],
columnsToInclude: string[],
): void {
const { unhandledIds, report, failed, unusedExceptionIds, unusedExceptionModules } = processAuditJson(
jsonBuffer,
auditLevel,
exceptionIds,
exceptionModules,
columnsToInclude,
);
// If unable to process the audit JSON
if (failed) {
console.error('Unable to process the JSON buffer string.');
// Exit failed
process.exit(1);
return;
}
// Print the security report
if (report.length) {
printSecurityReport(report, columnsToInclude);
}
// Handle unused exceptions
handleUnusedExceptions(unusedExceptionIds, unusedExceptionModules);
// Display the found unhandled vulnerabilities
if (unhandledIds.length) {
console.error(`${unhandledIds.length} vulnerabilities found. Node security advisories: ${unhandledIds.join(', ')}`);
// Exit failed
process.exit(1);
} else {
// Happy happy, joy joy
console.info('🤝 All good!');
process.exit(0);
}
}