From eeca787c81ac92e46a9375a0b1ce8baa29852b1a Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 7 Dec 2025 15:15:35 -0800 Subject: Lazily load hono --- lib/server/hono/proxy.ts | 24 ++++++++++++++++++------ package.json | 6 +++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/server/hono/proxy.ts b/lib/server/hono/proxy.ts index f729819..7f93804 100644 --- a/lib/server/hono/proxy.ts +++ b/lib/server/hono/proxy.ts @@ -10,21 +10,33 @@ import { TraceUtil, } from '@emprespresso/pengueno'; -import { serve, ServerType } from '@hono/node-server'; -import { Hono } from 'hono'; +import type { ServerType } from '@hono/node-server'; +import type { Hono } from 'hono'; const AppLifetimeMetric = Metric.fromName('HonoAppLifetime').asResult(); const AppRequestMetric = Metric.fromName('HonoAppRequest'); export class HonoProxy { - private readonly app = LogMetricTraceable.of(new Hono()) - .flatMap(TraceUtil.withTrace(`AppId = ${crypto.randomUUID()}`)) - .flatMap(TraceUtil.withMetricTrace(AppLifetimeMetric)); + private app?: LogMetricTraceable; constructor(private readonly server: Server) {} + private async initializeApp() { + if (this.app) return this.app; + + const { Hono } = await import('hono'); + this.app = LogMetricTraceable.of(new Hono()) + .flatMap(TraceUtil.withTrace(`AppId = ${crypto.randomUUID()}`)) + .flatMap(TraceUtil.withMetricTrace(AppLifetimeMetric)) as LogMetricTraceable; + + return this.app; + } + public async serve(port: number, hostname: string): Promise> { - return this.app + const { serve } = await import('@hono/node-server'); + + const app = await this.initializeApp(); + return app .map((tApp) => Either.fromFailable(() => { const app = tApp.get(); diff --git a/package.json b/package.json index 6686eef..3355d62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@emprespresso/pengueno", - "version": "0.0.16", + "version": "0.0.17", "description": "emprespresso pengueno utils", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -20,6 +20,10 @@ "format": "prettier --write .", "format:check": "prettier --check ." }, + "optionalDependencies": { + "@hono/node-server": "^1.18.2", + "hono": "^4.8.0" + }, "devDependencies": { "@hono/node-server": "^1.18.2", "@types/jest": "^30.0.0", -- cgit v1.2.3-70-g09d2