import { AuditLevel } from 'src/types' ; import { printSecurityReport } from '../utils/print' ; import { processAuditJson } from '../utils/vulnerability' ; param { String } jsonBuffer param { Number } auditLevel param { Array } exceptionIds return { undefined } export default function handleFinish ( jsonBuffer , auditLevel , exceptionIds ) { const { unhandledIds , vulnerabilityIds , report , failed } = processAuditJson ( jsonBuffer , auditLevel , exceptionIds ) ; if ( failed ) { console . error ( 'Unable to process the JSON buffer string.' ) ; process . exit ( 1 ) ; return ; } if ( report . length ) { printSecurityReport ( report ) ; } const unusedExceptionIds = exceptionIds . filter ( ( id ) => ! vulnerabilityIds . includes ( id ) ) ; if ( unusedExceptionIds . length ) { const messages = [ `${ unusedExceptionIds . length } of the excluded vulnerabilities did not match any of the found vulnerabilities: ${ unusedExceptionIds . join ( ', ' ) }.` , `${ unusedExceptionIds . length > 1 ? 'They' : 'It' } can be removed from the .nsprc file or --exclude -x flags.` , ] ; console . warn ( messages . join ( ' ' ) ) ; } if ( unhandledIds . length ) { console . error ( `${ unhandledIds . length } vulnerabilities found. Node security advisories: ${ unhandledIds . join ( ', ' ) }` ) ; process . exit ( 1 ) ; } else { console . info ( '🤝  All good!' ) ; process . exit ( 0 ) ; } }