feat: add the ability to run with '--json' and output the result (#78)
* addition-of-json-flag * Set output of npn audit
This commit is contained in:
@@ -7,7 +7,7 @@ export class Audit {
|
||||
stdout = ''
|
||||
private status: number | null = null
|
||||
|
||||
public run(auditLevel: string, productionFlag: string): void {
|
||||
public run(auditLevel: string, productionFlag: string, jsonFlag: string): void {
|
||||
try {
|
||||
const auditOptions: Array<string> = ['audit', '--audit-level', auditLevel]
|
||||
|
||||
@@ -15,6 +15,10 @@ export class Audit {
|
||||
auditOptions.push('--production')
|
||||
}
|
||||
|
||||
if (jsonFlag === 'true') {
|
||||
auditOptions.push('--json')
|
||||
}
|
||||
|
||||
const result: SpawnSyncReturns<string> = spawnSync('npm', auditOptions, {
|
||||
encoding: 'utf-8',
|
||||
maxBuffer: SPAWN_PROCESS_BUFFER_SIZE
|
||||
|
||||
@@ -30,10 +30,17 @@ export async function run(): Promise<void> {
|
||||
throw new Error('Invalid input: production_flag')
|
||||
}
|
||||
|
||||
const jsonFlag = core.getInput('json_flag', {required: false})
|
||||
if (!['true', 'false'].includes(jsonFlag)) {
|
||||
throw new Error('Invalid input: json_flag')
|
||||
}
|
||||
|
||||
|
||||
// run `npm audit`
|
||||
const audit = new Audit()
|
||||
audit.run(auditLevel, productionFlag)
|
||||
audit.run(auditLevel, productionFlag, jsonFlag)
|
||||
core.info(audit.stdout)
|
||||
core.setOutput('npm_audit', audit.stdout);
|
||||
|
||||
if (audit.foundVulnerability()) {
|
||||
// vulnerabilities are found
|
||||
|
||||
Reference in New Issue
Block a user