Skip to content

Commit 026e426

Browse files
committed
feat(optimize): add stat to output
1 parent dba02c6 commit 026e426

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/commands/optimize/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as esbuild from 'esbuild'
33
import type { Hono } from 'hono'
44
import { buildInitParams, serializeInitParams } from 'hono/router/reg-exp-router'
55
import { execFile } from 'node:child_process'
6-
import { existsSync, realpathSync } from 'node:fs'
6+
import { existsSync, realpathSync, statSync } from 'node:fs'
77
import { dirname, join, resolve } from 'node:path'
88
import { buildAndImportApp } from '../../utils/build.js'
99

@@ -33,6 +33,7 @@ export function optimizeCommand(program: Command) {
3333
external: ['@hono/node-server'],
3434
})
3535

36+
let routerName
3637
let importStatement
3738
let assignRouterStatement
3839
try {
@@ -54,22 +55,28 @@ export function optimizeCommand(program: Command) {
5455
})
5556

5657
if (hasPreparedRegExpRouter) {
58+
routerName = 'PreparedRegExpRouter'
5759
importStatement = "import { PreparedRegExpRouter } from 'hono/router/reg-exp-router'"
5860
assignRouterStatement = `const routerParams = ${serialized}
5961
this.router = new PreparedRegExpRouter(...routerParams)`
6062
} else {
63+
routerName = 'RegExpRouter'
6164
importStatement = "import { RegExpRouter } from 'hono/router/reg-exp-router'"
6265
assignRouterStatement = 'this.router = new RegExpRouter()'
6366
}
6467
} catch {
6568
// fallback to default router
69+
routerName = 'TrieRouter'
6670
importStatement = "import { TrieRouter } from 'hono/router/trie-router'"
6771
assignRouterStatement = 'this.router = new TrieRouter()'
6872
}
6973

74+
console.log(`Router: ${routerName}`)
75+
76+
const outfile = resolve(process.cwd(), options.outfile)
7077
await esbuild.build({
7178
entryPoints: [appFilePath],
72-
outfile: resolve(process.cwd(), options.outfile),
79+
outfile,
7380
bundle: true,
7481
minify: options.minify,
7582
format: 'esm',
@@ -118,5 +125,8 @@ export class Hono extends HonoBase {
118125
},
119126
],
120127
})
128+
129+
const outfileStat = statSync(outfile)
130+
console.log(`App: ${options.outfile} (${(outfileStat.size / 1024).toFixed(2)} KB)`)
121131
})
122132
}

0 commit comments

Comments
 (0)