refactor: modernize code to ES2020 (#220)

This commit is contained in:
Naoki Oketani
2025-05-03 04:08:29 +00:00
parent a08099359e
commit 2af7795f4f
5 changed files with 42 additions and 44 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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')
}
}

View File

@@ -7,7 +7,7 @@ export async function createComment(
prNumber: number,
body: string
): Promise<void> {
octokit.issues.createComment({
await octokit.issues.createComment({
owner,
repo,
issue_number: prNumber,