From a7b60bcfc8a231656c31dad3316a3b59dfac5cae Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 22:11:28 +0900 Subject: [PATCH 1/7] fix(hono): import hono/context-storage directly --- .../src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 11 ++++++++--- .../src/lib/plugins/vite-plugin-deploy-netlify.ts | 11 ++++++++--- .../waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 11 ++++++++--- packages/waku/src/unstable_hono.ts | 1 - 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts index 64ecb137d..3914d9bb4 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -17,16 +17,21 @@ import { DIST_ENTRIES_JS, DIST_PUBLIC } from '../builder/constants.js'; const SERVE_JS = 'serve-cloudflare.js'; const getServeJsContent = (srcEntriesFile: string) => ` -import { runner, importHono, importHonoContextStorage } from 'waku/unstable_hono'; +import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const { contextStorage } = await importHonoContextStorage(); +let contextStorage; +try { + ({ contextStorage } = await import('hono/context-storage')); +} catch () {} const loadEntries = () => import('${srcEntriesFile}'); let serveWaku; const app = new Hono(); -app.use(contextStorage()); +if (contextStorage) { + app.use(contextStorage()); +} app.use('*', (c, next) => serveWaku(c, next)); app.notFound(async (c) => { const assetsFetcher = c.env.ASSETS; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts index c915ee701..3f3cad5c4 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -9,15 +9,20 @@ import { DIST_PUBLIC } from '../builder/constants.js'; const SERVE_JS = 'serve-netlify.js'; const getServeJsContent = (srcEntriesFile: string) => ` -import { runner, importHono, importHonoContextStorage } from 'waku/unstable_hono'; +import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const { contextStorage } = await importHonoContextStorage(); +let contextStorage; +try { + ({ contextStorage } = await import('hono/context-storage')); +} catch () {} const loadEntries = () => import('${srcEntriesFile}'); const app = new Hono(); -app.use(contextStorage()); +if (contextStorage) { + app.use(contextStorage()); +} app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound((c) => { const notFoundHtml = globalThis.__WAKU_NOT_FOUND_HTML__; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 3e6f51f9f..47982b78b 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -15,18 +15,23 @@ const getServeJsContent = ( ) => ` import path from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; -import { runner, importHono, importHonoContextStorage, importHonoNodeServer } from 'waku/unstable_hono'; +import { runner, importHono, importHonoNodeServer } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const { contextStorage } = await importHonoContextStorage(); const { getRequestListener } = await importHonoNodeServer(); +let contextStorage; +try { + ({ contextStorage } = await import('hono/context-storage')); +} catch () {} const distDir = '${distDir}'; const publicDir = '${distPublic}'; const loadEntries = () => import('${srcEntriesFile}'); const app = new Hono(); -app.use(contextStorage()); +if (contextStorage) { + app.use(contextStorage()); +} app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound((c) => { // FIXME better implementation using node stream? diff --git a/packages/waku/src/unstable_hono.ts b/packages/waku/src/unstable_hono.ts index 197c8fb46..c1e3292da 100644 --- a/packages/waku/src/unstable_hono.ts +++ b/packages/waku/src/unstable_hono.ts @@ -3,7 +3,6 @@ export { runner } from './lib/hono/runner.js'; export const importHono = () => import('hono'); -export const importHonoContextStorage = () => import('hono/context-storage'); export const importHonoNodeServer: any = () => import('@hono/node-server'); export const importHonoNodeServerServeStatic = () => import('@hono/node-server/serve-static'); From 53f85630f28319931590e610fc80e54a33dd85ca Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 22:15:58 +0900 Subject: [PATCH 2/7] fix catch statement --- packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 2 +- packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts | 2 +- packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts index 3914d9bb4..db38b2bf5 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -23,7 +23,7 @@ const { Hono } = await importHono(); let contextStorage; try { ({ contextStorage } = await import('hono/context-storage')); -} catch () {} +} catch {} const loadEntries = () => import('${srcEntriesFile}'); let serveWaku; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts index 3f3cad5c4..3ef427d16 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -15,7 +15,7 @@ const { Hono } = await importHono(); let contextStorage; try { ({ contextStorage } = await import('hono/context-storage')); -} catch () {} +} catch {} const loadEntries = () => import('${srcEntriesFile}'); diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 47982b78b..0005ebfc8 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -22,7 +22,7 @@ const { getRequestListener } = await importHonoNodeServer(); let contextStorage; try { ({ contextStorage } = await import('hono/context-storage')); -} catch () {} +} catch {} const distDir = '${distDir}'; const publicDir = '${distPublic}'; From 927b02a00051582d78eaa0aa426b20082eb1e15e Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 22:20:22 +0900 Subject: [PATCH 3/7] does this work? --- packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 0005ebfc8..567987084 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -21,7 +21,7 @@ const { Hono } = await importHono(); const { getRequestListener } = await importHonoNodeServer(); let contextStorage; try { - ({ contextStorage } = await import('hono/context-storage')); + ({ contextStorage } = await import(/* @vite-ignore */ 'hono/context-storage')); } catch {} const distDir = '${distDir}'; From ea66492e1c1cc1e476e9a3908f2106461c4a111e Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 22:38:47 +0900 Subject: [PATCH 4/7] do not bundle --- packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 3 ++- packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts | 3 ++- packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts index db38b2bf5..6f971600d 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -20,9 +20,10 @@ const getServeJsContent = (srcEntriesFile: string) => ` import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); +const DO_NOT_BUNDLE = ''; let contextStorage; try { - ({ contextStorage } = await import('hono/context-storage')); + ({ contextStorage } = await import(DO_NOT_BUNDLE + 'hono/context-storage')); } catch {} const loadEntries = () => import('${srcEntriesFile}'); diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts index 3ef427d16..9b9654ce1 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -12,9 +12,10 @@ const getServeJsContent = (srcEntriesFile: string) => ` import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); +const DO_NOT_BUNDLE = ''; let contextStorage; try { - ({ contextStorage } = await import('hono/context-storage')); + ({ contextStorage } = await import(DO_NOT_BUNDLE + 'hono/context-storage')); } catch {} const loadEntries = () => import('${srcEntriesFile}'); diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 567987084..1b2ae830a 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -19,9 +19,10 @@ import { runner, importHono, importHonoNodeServer } from 'waku/unstable_hono'; const { Hono } = await importHono(); const { getRequestListener } = await importHonoNodeServer(); +const DO_NOT_BUNDLE = ''; let contextStorage; try { - ({ contextStorage } = await import(/* @vite-ignore */ 'hono/context-storage')); + ({ contextStorage } = await import(DO_NOT_BUNDLE + 'hono/context-storage')); } catch {} const distDir = '${distDir}'; From 94619b67a8634117090022b115c299f7e0522b07 Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 23:03:18 +0900 Subject: [PATCH 5/7] revert it --- packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 3 +-- packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts | 3 +-- packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts index 6f971600d..db38b2bf5 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -20,10 +20,9 @@ const getServeJsContent = (srcEntriesFile: string) => ` import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const DO_NOT_BUNDLE = ''; let contextStorage; try { - ({ contextStorage } = await import(DO_NOT_BUNDLE + 'hono/context-storage')); + ({ contextStorage } = await import('hono/context-storage')); } catch {} const loadEntries = () => import('${srcEntriesFile}'); diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts index 9b9654ce1..3ef427d16 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -12,10 +12,9 @@ const getServeJsContent = (srcEntriesFile: string) => ` import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const DO_NOT_BUNDLE = ''; let contextStorage; try { - ({ contextStorage } = await import(DO_NOT_BUNDLE + 'hono/context-storage')); + ({ contextStorage } = await import('hono/context-storage')); } catch {} const loadEntries = () => import('${srcEntriesFile}'); diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 1b2ae830a..0005ebfc8 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -19,10 +19,9 @@ import { runner, importHono, importHonoNodeServer } from 'waku/unstable_hono'; const { Hono } = await importHono(); const { getRequestListener } = await importHonoNodeServer(); -const DO_NOT_BUNDLE = ''; let contextStorage; try { - ({ contextStorage } = await import(DO_NOT_BUNDLE + 'hono/context-storage')); + ({ contextStorage } = await import('hono/context-storage')); } catch {} const distDir = '${distDir}'; From ad6a073f4a5f5275af232489f8516fbe8ee11580 Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 23:09:58 +0900 Subject: [PATCH 6/7] add load fallback --- packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 3 +++ packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts | 3 +++ packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts index db38b2bf5..741154083 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -123,6 +123,9 @@ export function deployCloudflarePlugin(opts: { if (id === `${opts.srcDir}/${SERVE_JS}`) { return getServeJsContent(entriesFile); } + if (id === 'hono/context-storage') { + return ''; + } }, closeBundle() { const { deploy, unstable_phase } = platformObject.buildOptions || {}; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts index 3ef427d16..47255d9e0 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -71,6 +71,9 @@ export function deployNetlifyPlugin(opts: { if (id === `${opts.srcDir}/${SERVE_JS}`) { return getServeJsContent(entriesFile); } + if (id === 'hono/context-storage') { + return ''; + } }, closeBundle() { const { deploy, unstable_phase } = platformObject.buildOptions || {}; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 0005ebfc8..47d3e3519 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -83,6 +83,9 @@ export function deployVercelPlugin(opts: { if (id === `${opts.srcDir}/${SERVE_JS}`) { return getServeJsContent(opts.distDir, DIST_PUBLIC, entriesFile); } + if (id === 'hono/context-storage') { + return ''; + } }, closeBundle() { const { deploy, unstable_phase } = platformObject.buildOptions || {}; From 6179bbfbb1c6f99c88263f6828610be3ddf3fd77 Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 24 Sep 2024 23:16:03 +0900 Subject: [PATCH 7/7] revert https://github.com/dai-shi/waku/pull/880/commits/ed4ace1d74007369aa62d0c46e5f6d9101ea6bfe :-) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e30870e4a..79a538d46 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "examples:prd:24_nesting": "NAME=24_nesting pnpm run examples:prd", "website:dev": "(cd packages/website && pnpm run dev)", "website:build": "cd packages/website && pnpm run build", - "website:vercel": "pnpm run compile && pnpm run website:build && mv packages/website/.vercel/output .vercel/", + "website:vercel": "pnpm run compile && pnpm run website:build --with-vercel-static && mv packages/website/.vercel/output .vercel/", "website:prd": "pnpm run website:build && (cd packages/website && pnpm start)" }, "prettier": {