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:
9
dist/index.js
vendored
9
dist/index.js
vendored
@@ -556,12 +556,15 @@ class Audit {
|
||||
this.stdout = '';
|
||||
this.status = null;
|
||||
}
|
||||
run(auditLevel, productionFlag) {
|
||||
run(auditLevel, productionFlag, jsonFlag) {
|
||||
try {
|
||||
const auditOptions = ['audit', '--audit-level', auditLevel];
|
||||
if (productionFlag === 'true') {
|
||||
auditOptions.push('--production');
|
||||
}
|
||||
if (jsonFlag === 'true') {
|
||||
auditOptions.push('--json');
|
||||
}
|
||||
const result = child_process_1.spawnSync('npm', auditOptions, {
|
||||
encoding: 'utf-8',
|
||||
maxBuffer: SPAWN_PROCESS_BUFFER_SIZE
|
||||
@@ -1435,6 +1438,10 @@ function run() {
|
||||
if (!['true', 'false'].includes(productionFlag)) {
|
||||
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_1.Audit();
|
||||
audit.run(auditLevel, productionFlag);
|
||||
|
||||
Reference in New Issue
Block a user