From c8f6a866c09ae6539d3dd636873e53d8d84f267e Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Mon, 18 Nov 2024 15:44:13 +0900 Subject: [PATCH] chore: enable formatting `perf-measures` (#3683) --- package.json | 6 ++--- .../bundle-check/scripts/process-results.ts | 16 ++++++------ .../type-check/scripts/generate-app.ts | 4 ++- .../type-check/scripts/process-results.ts | 25 +++++++++++-------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 4e9d3d94..553d5e2a 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "test:all": "bun run test && bun test:deno && bun test:bun && bun test:fastly && bun test:node && bun test:workerd && bun test:lambda && bun test:lambda-edge", "lint": "eslint src runtime-tests", "lint:fix": "eslint src runtime-tests --fix", - "format": "prettier --check --cache \"src/**/*.{js,ts,tsx}\" \"runtime-tests/**/*.{js,ts,tsx}\" \"build/**/*.{js,ts,tsx}\"", - "format:fix": "prettier --write --cache --cache-strategy metadata \"src/**/*.{js,ts,tsx}\" \"runtime-tests/**/*.{js,ts,tsx}\" \"build/**/*.{js,ts,tsx}\"", + "format": "prettier --check --cache \"src/**/*.{js,ts,tsx}\" \"runtime-tests/**/*.{js,ts,tsx}\" \"build/**/*.{js,ts,tsx}\" \"perf-measures/**/*.{js,ts,tsx}\"", + "format:fix": "prettier --write --cache --cache-strategy metadata \"src/**/*.{js,ts,tsx}\" \"runtime-tests/**/*.{js,ts,tsx}\" \"build/**/*.{js,ts,tsx}\" \"perf-measures/**/*.{js,ts,tsx}\"", "copy:package.cjs.json": "cp ./package.cjs.json ./dist/cjs/package.json && cp ./package.cjs.json ./dist/types/package.json", "build": "bun run --shell bun remove-dist && bun ./build/build.ts && bun run copy:package.cjs.json", "postbuild": "publint", @@ -654,4 +654,4 @@ "engines": { "node": ">=16.9.0" } -} +} \ No newline at end of file diff --git a/perf-measures/bundle-check/scripts/process-results.ts b/perf-measures/bundle-check/scripts/process-results.ts index e570a188..0dc3b216 100644 --- a/perf-measures/bundle-check/scripts/process-results.ts +++ b/perf-measures/bundle-check/scripts/process-results.ts @@ -1,14 +1,14 @@ import * as fs from 'node:fs/promises' async function main() { - const currentResult = (await fs.readFile('./generated/after.js')).byteLength - let previousResult: number | null = null - try { - previousResult = (await fs.readFile('./generated/before.js')).byteLength - } catch (e) {} - const table = ['| | Current | Previous |', '| --- | --- | --- |'] - table.push(`| Bundle Size | ${currentResult} | ${previousResult || 'N/A'} |`) - console.log(table.join('\n')) + const currentResult = (await fs.readFile('./generated/after.js')).byteLength + let previousResult: number | null = null + try { + previousResult = (await fs.readFile('./generated/before.js')).byteLength + } catch (e) {} + const table = ['| | Current | Previous |', '| --- | --- | --- |'] + table.push(`| Bundle Size | ${currentResult} | ${previousResult || 'N/A'} |`) + console.log(table.join('\n')) } main() diff --git a/perf-measures/type-check/scripts/generate-app.ts b/perf-measures/type-check/scripts/generate-app.ts index 669601df..d792fe7e 100644 --- a/perf-measures/type-check/scripts/generate-app.ts +++ b/perf-measures/type-check/scripts/generate-app.ts @@ -20,6 +20,8 @@ export const app = new Hono()` const routes = generateRoutes(count) writeFile(path.join(import.meta.dirname, '../generated/app.ts'), routes, (err) => { - if (err) { throw err } + if (err) { + throw err + } console.log(`${count} routes have been written to app.ts`) }) diff --git a/perf-measures/type-check/scripts/process-results.ts b/perf-measures/type-check/scripts/process-results.ts index 4e85e495..99f56d0e 100644 --- a/perf-measures/type-check/scripts/process-results.ts +++ b/perf-measures/type-check/scripts/process-results.ts @@ -1,18 +1,21 @@ import * as fs from 'node:fs/promises' async function main() { - const currentResult = (await fs.readFile('./result.txt')).toString().split('\n') - const previousResult = await fs.readFile('./previous-result.txt') - .then((data) => data.toString().split('\n')) - .catch(() => null) - const table = ['| | Current | Previous |', '| --- | --- | --- |'] - for (const [i, line] of currentResult.entries()) { - if (line === '') {continue} - const [name, value] = line.split(':') - const mainValue = previousResult?.[i]?.split(':')?.[1] - table.push(`| ${name?.trim()} | ${value?.trim()} | ${mainValue ? mainValue.trim() : 'N/A'} |`) + const currentResult = (await fs.readFile('./result.txt')).toString().split('\n') + const previousResult = await fs + .readFile('./previous-result.txt') + .then((data) => data.toString().split('\n')) + .catch(() => null) + const table = ['| | Current | Previous |', '| --- | --- | --- |'] + for (const [i, line] of currentResult.entries()) { + if (line === '') { + continue } - console.log(table.join('\n')) + const [name, value] = line.split(':') + const mainValue = previousResult?.[i]?.split(':')?.[1] + table.push(`| ${name?.trim()} | ${value?.trim()} | ${mainValue ? mainValue.trim() : 'N/A'} |`) + } + console.log(table.join('\n')) } main()