Catch errors thrown by Audit.run and increase child process buffer size (#67)

* Audit.run does not need to be async

* Set max buffer size for npm audit subprocess to 10MiB
This commit is contained in:
Spencer Small
2020-07-14 02:59:28 -07:00
committed by GitHub
parent 4adc177da9
commit b0bc596f8e
3 changed files with 31 additions and 40 deletions

View File

@@ -1,17 +1,20 @@
import {spawnSync, SpawnSyncReturns} from 'child_process'
import stripAnsi from 'strip-ansi'
const SPAWN_PROCESS_BUFFER_SIZE = 10485760 // 10MiB
export class Audit {
stdout = ''
private status: number | null = null
public async run(auditLevel: string): Promise<void> {
public run(auditLevel: string): void {
try {
const result: SpawnSyncReturns<string> = spawnSync(
'npm',
['audit', '--audit-level', auditLevel],
{
encoding: 'utf-8'
encoding: 'utf-8',
maxBuffer: SPAWN_PROCESS_BUFFER_SIZE
}
)