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,

View File

@@ -1,12 +1,16 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020' or 'ESNEXT'. */
"module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts"]
"exclude": [
"node_modules",
"**/*.test.ts",
"vitest.config.ts"
]
}