refactor: modernize code to ES2020 (#220)
This commit is contained in:
58
src/audit.ts
58
src/audit.ts
@@ -12,40 +12,36 @@ export class Audit {
|
||||
productionFlag: string,
|
||||
jsonFlag: string
|
||||
): void {
|
||||
try {
|
||||
const auditOptions: Array<string> = ['audit', '--audit-level', auditLevel]
|
||||
const auditOptions: string[] = ['audit', '--audit-level', auditLevel]
|
||||
|
||||
const isWindowsEnvironment: boolean = process.platform == 'win32'
|
||||
const cmd: string = isWindowsEnvironment ? 'npm.cmd' : 'npm'
|
||||
const isWindowsEnvironment: boolean = process.platform === 'win32'
|
||||
const cmd: string = isWindowsEnvironment ? 'npm.cmd' : 'npm'
|
||||
|
||||
if (productionFlag === 'true') {
|
||||
auditOptions.push('--omit=dev')
|
||||
}
|
||||
|
||||
if (jsonFlag === 'true') {
|
||||
auditOptions.push('--json')
|
||||
}
|
||||
|
||||
const result: SpawnSyncReturns<string> = spawnSync(cmd, auditOptions, {
|
||||
encoding: 'utf-8',
|
||||
maxBuffer: SPAWN_PROCESS_BUFFER_SIZE
|
||||
})
|
||||
|
||||
if (result.error) {
|
||||
throw result.error
|
||||
}
|
||||
if (result.status === null) {
|
||||
throw new Error('the subprocess terminated due to a signal.')
|
||||
}
|
||||
if (result.stderr && result.stderr.length > 0) {
|
||||
throw new Error(result.stderr)
|
||||
}
|
||||
|
||||
this.status = result.status
|
||||
this.stdout = result.stdout
|
||||
} catch (error) {
|
||||
throw error
|
||||
if (productionFlag === 'true') {
|
||||
auditOptions.push('--omit=dev')
|
||||
}
|
||||
|
||||
if (jsonFlag === 'true') {
|
||||
auditOptions.push('--json')
|
||||
}
|
||||
|
||||
const result: SpawnSyncReturns<string> = spawnSync(cmd, auditOptions, {
|
||||
encoding: 'utf-8',
|
||||
maxBuffer: SPAWN_PROCESS_BUFFER_SIZE
|
||||
})
|
||||
|
||||
if (result.error) {
|
||||
throw result.error
|
||||
}
|
||||
if (result.status === null) {
|
||||
throw new Error('the subprocess terminated due to a signal.')
|
||||
}
|
||||
if (result.stderr?.length > 0) {
|
||||
throw new Error(result.stderr)
|
||||
}
|
||||
|
||||
this.status = result.status
|
||||
this.stdout = result.stdout
|
||||
}
|
||||
|
||||
public foundVulnerability(): boolean {
|
||||
|
||||
@@ -47,5 +47,5 @@ export async function getExistingIssueNumber(
|
||||
.filter(i => i.title === core.getInput('issue_title'))
|
||||
.shift()
|
||||
|
||||
return iss === undefined ? null : iss.number
|
||||
return iss?.number ?? null
|
||||
}
|
||||
|
||||
@@ -114,9 +114,7 @@ export async function run(): Promise<void> {
|
||||
}
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
core.setFailed(e.message)
|
||||
}
|
||||
core.setFailed((e as Error)?.message ?? 'Unknown error occurred')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user