From 7c537de3bc85030d713f8d017a9f7a0add6437b9 Mon Sep 17 00:00:00 2001 From: Rob Marscher Date: Fri, 27 Sep 2024 16:15:11 -0400 Subject: [PATCH 1/7] Update cloudflare with hono/context-storage external build fix --- .../waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 8 +++++--- 1 file changed, 5 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 8ef6a153c..deef40b3e 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -100,6 +100,11 @@ export function deployCloudflarePlugin(opts: { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy, unstable_phase } = platformObject.buildOptions || {}; + if (deploy === 'cloudflare' && Array.isArray(config.ssr.external)) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } if ( (unstable_phase !== 'buildServerBundle' && unstable_phase !== 'buildSsrBundle') || @@ -118,9 +123,6 @@ export function deployCloudflarePlugin(opts: { if (source === `${opts.srcDir}/${SERVE_JS}`) { return source; } - if (source === 'hono/context-storage') { - return { id: source, external: true }; - } }, load(id) { if (id === `${opts.srcDir}/${SERVE_JS}`) { From eaf7817e8d80701d46778e43631afd0920a78d04 Mon Sep 17 00:00:00 2001 From: daishi Date: Sat, 28 Sep 2024 10:22:50 +0900 Subject: [PATCH 2/7] do the same for vercel --- packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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..2b6f4f06c 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -73,6 +73,12 @@ export function deployVercelPlugin(opts: { configResolved(config) { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; + const { deploy } = platformObject.buildOptions || {}; + if (deploy === 'vercel-serverless' && Array.isArray(config.ssr.external)) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { From e519fce17e6400a61ca50593d5201df90a183b15 Mon Sep 17 00:00:00 2001 From: daishi Date: Sat, 28 Sep 2024 10:23:44 +0900 Subject: [PATCH 3/7] make the code consistent --- .../waku/src/lib/plugins/vite-plugin-deploy-deno.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts index c032dc641..e103346cb 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts @@ -61,6 +61,11 @@ export function deployDenoPlugin(opts: { configResolved(config) { entriesFile = `${config.root}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy, unstable_phase } = platformObject.buildOptions || {}; + if (deploy === 'deno' && Array.isArray(config.ssr.external)) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } if ( (unstable_phase !== 'buildServerBundle' && unstable_phase !== 'buildSsrBundle') || @@ -74,11 +79,6 @@ export function deployDenoPlugin(opts: { config.ssr.resolve.conditions.push('worker'); config.ssr.resolve.externalConditions ||= []; config.ssr.resolve.externalConditions.push('worker'); - if (Array.isArray(config.ssr.external)) { - config.ssr.external = config.ssr.external.filter( - (item) => item !== 'hono/context-storage', - ); - } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { From 3e0bdbd6eb87bedeea2ea49259e2ede6f2fe9498 Mon Sep 17 00:00:00 2001 From: daishi Date: Sat, 28 Sep 2024 10:27:52 +0900 Subject: [PATCH 4/7] most likely netlify needs it too --- .../waku/src/lib/plugins/vite-plugin-deploy-netlify.ts | 9 +++++++++ 1 file changed, 9 insertions(+) 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..3bec3354c 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -61,6 +61,15 @@ export function deployNetlifyPlugin(opts: { configResolved(config) { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; + const { deploy } = platformObject.buildOptions || {}; + if ( + deploy === 'netlify-functions' && + Array.isArray(config.ssr.external) + ) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { From 8816efc533a155816fc4520b949e59c318285b80 Mon Sep 17 00:00:00 2001 From: daishi Date: Sat, 28 Sep 2024 10:28:06 +0900 Subject: [PATCH 5/7] run prettier --- packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 5 ++++- 1 file changed, 4 insertions(+), 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 2b6f4f06c..ea91f8b8e 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -74,7 +74,10 @@ export function deployVercelPlugin(opts: { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy } = platformObject.buildOptions || {}; - if (deploy === 'vercel-serverless' && Array.isArray(config.ssr.external)) { + if ( + deploy === 'vercel-serverless' && + Array.isArray(config.ssr.external) + ) { config.ssr.external = config.ssr.external.filter( (item) => item !== 'hono/context-storage', ); From bb7d18b2ae308ad1c4592ed400ef67fbe07e2c58 Mon Sep 17 00:00:00 2001 From: daishi Date: Sat, 28 Sep 2024 11:31:30 +0900 Subject: [PATCH 6/7] revert #898 --- .../plugins/vite-plugin-deploy-aws-lambda.ts | 17 +++------------- .../plugins/vite-plugin-deploy-cloudflare.ts | 16 +++------------ .../lib/plugins/vite-plugin-deploy-deno.ts | 5 ----- .../lib/plugins/vite-plugin-deploy-netlify.ts | 20 +++---------------- .../lib/plugins/vite-plugin-deploy-vercel.ts | 20 +++---------------- packages/waku/src/unstable_hono.ts | 1 + 6 files changed, 13 insertions(+), 66 deletions(-) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts index 473239b02..c5fcc2332 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts @@ -17,24 +17,19 @@ const getServeJsContent = ( ) => ` import path from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; -import { runner, importHono, importHonoNodeServerServeStatic, importHonoAwsLambda } from 'waku/unstable_hono'; +import { runner, importHono, importHonoContextStorage, importHonoNodeServerServeStatic, importHonoAwsLambda } from 'waku/unstable_hono'; const { Hono } = await importHono(); +const { contextStorage } = await importHonoContextStorage(); const { serveStatic } = await importHonoNodeServerServeStatic(); const { ${lambdaStreaming ? 'streamHandle:' : ''}handle } = await importHonoAwsLambda(); -let contextStorage; -try { - ({ contextStorage } = await import('hono/context-storage')); -} catch {} const distDir = '${distDir}'; const publicDir = '${distPublic}'; const loadEntries = () => import('${srcEntriesFile}'); const app = new Hono(); -if (contextStorage) { - app.use(contextStorage()); -} +app.use(contextStorage()); app.use('*', serveStatic({ root: distDir + '/' + publicDir })); app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound(async (c) => { @@ -68,12 +63,6 @@ export function deployAwsLambdaPlugin(opts: { }, configResolved(config) { entriesFile = `${config.root}/${opts.srcDir}/${SRC_ENTRIES}`; - const { deploy } = platformObject.buildOptions || {}; - if (deploy === 'aws-lambda' && Array.isArray(config.ssr.external)) { - config.ssr.external = config.ssr.external.filter( - (item) => item !== 'hono/context-storage', - ); - } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { 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 deef40b3e..64ecb137d 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -17,21 +17,16 @@ import { DIST_ENTRIES_JS, DIST_PUBLIC } from '../builder/constants.js'; const SERVE_JS = 'serve-cloudflare.js'; const getServeJsContent = (srcEntriesFile: string) => ` -import { runner, importHono } from 'waku/unstable_hono'; +import { runner, importHono, importHonoContextStorage } from 'waku/unstable_hono'; const { Hono } = await importHono(); -let contextStorage; -try { - ({ contextStorage } = await import('hono/context-storage')); -} catch {} +const { contextStorage } = await importHonoContextStorage(); const loadEntries = () => import('${srcEntriesFile}'); let serveWaku; const app = new Hono(); -if (contextStorage) { - app.use(contextStorage()); -} +app.use(contextStorage()); app.use('*', (c, next) => serveWaku(c, next)); app.notFound(async (c) => { const assetsFetcher = c.env.ASSETS; @@ -100,11 +95,6 @@ export function deployCloudflarePlugin(opts: { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy, unstable_phase } = platformObject.buildOptions || {}; - if (deploy === 'cloudflare' && Array.isArray(config.ssr.external)) { - config.ssr.external = config.ssr.external.filter( - (item) => item !== 'hono/context-storage', - ); - } if ( (unstable_phase !== 'buildServerBundle' && unstable_phase !== 'buildSsrBundle') || diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts index e103346cb..18e80fcd6 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts @@ -61,11 +61,6 @@ export function deployDenoPlugin(opts: { configResolved(config) { entriesFile = `${config.root}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy, unstable_phase } = platformObject.buildOptions || {}; - if (deploy === 'deno' && Array.isArray(config.ssr.external)) { - config.ssr.external = config.ssr.external.filter( - (item) => item !== 'hono/context-storage', - ); - } if ( (unstable_phase !== 'buildServerBundle' && unstable_phase !== 'buildSsrBundle') || 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 3bec3354c..c915ee701 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -9,20 +9,15 @@ import { DIST_PUBLIC } from '../builder/constants.js'; const SERVE_JS = 'serve-netlify.js'; const getServeJsContent = (srcEntriesFile: string) => ` -import { runner, importHono } from 'waku/unstable_hono'; +import { runner, importHono, importHonoContextStorage } from 'waku/unstable_hono'; const { Hono } = await importHono(); -let contextStorage; -try { - ({ contextStorage } = await import('hono/context-storage')); -} catch {} +const { contextStorage } = await importHonoContextStorage(); const loadEntries = () => import('${srcEntriesFile}'); const app = new Hono(); -if (contextStorage) { - app.use(contextStorage()); -} +app.use(contextStorage()); app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound((c) => { const notFoundHtml = globalThis.__WAKU_NOT_FOUND_HTML__; @@ -61,15 +56,6 @@ export function deployNetlifyPlugin(opts: { configResolved(config) { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; - const { deploy } = platformObject.buildOptions || {}; - if ( - deploy === 'netlify-functions' && - Array.isArray(config.ssr.external) - ) { - config.ssr.external = config.ssr.external.filter( - (item) => item !== 'hono/context-storage', - ); - } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { 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 ea91f8b8e..3e6f51f9f 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -15,23 +15,18 @@ const getServeJsContent = ( ) => ` import path from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; -import { runner, importHono, importHonoNodeServer } from 'waku/unstable_hono'; +import { runner, importHono, importHonoContextStorage, 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(); -if (contextStorage) { - app.use(contextStorage()); -} +app.use(contextStorage()); app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound((c) => { // FIXME better implementation using node stream? @@ -73,15 +68,6 @@ export function deployVercelPlugin(opts: { configResolved(config) { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; - const { deploy } = platformObject.buildOptions || {}; - if ( - deploy === 'vercel-serverless' && - Array.isArray(config.ssr.external) - ) { - config.ssr.external = config.ssr.external.filter( - (item) => item !== 'hono/context-storage', - ); - } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { diff --git a/packages/waku/src/unstable_hono.ts b/packages/waku/src/unstable_hono.ts index a6c1e8c14..1663b81f8 100644 --- a/packages/waku/src/unstable_hono.ts +++ b/packages/waku/src/unstable_hono.ts @@ -3,6 +3,7 @@ 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 a22aa13c2ad0934dc982eea5ec2dd5404c183308 Mon Sep 17 00:00:00 2001 From: daishi Date: Sat, 28 Sep 2024 11:37:02 +0900 Subject: [PATCH 7/7] oops this should be kept --- .../src/lib/plugins/vite-plugin-deploy-aws-lambda.ts | 6 ++++++ .../src/lib/plugins/vite-plugin-deploy-cloudflare.ts | 5 +++++ packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts | 5 +++++ .../waku/src/lib/plugins/vite-plugin-deploy-netlify.ts | 9 +++++++++ .../waku/src/lib/plugins/vite-plugin-deploy-vercel.ts | 9 +++++++++ 5 files changed, 34 insertions(+) diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts index c5fcc2332..3d7eb779e 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts @@ -63,6 +63,12 @@ export function deployAwsLambdaPlugin(opts: { }, configResolved(config) { entriesFile = `${config.root}/${opts.srcDir}/${SRC_ENTRIES}`; + const { deploy } = platformObject.buildOptions || {}; + if (deploy === 'aws-lambda' && Array.isArray(config.ssr.external)) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { 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..077a6c201 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -95,6 +95,11 @@ export function deployCloudflarePlugin(opts: { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy, unstable_phase } = platformObject.buildOptions || {}; + if (deploy === 'cloudflare' && Array.isArray(config.ssr.external)) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } if ( (unstable_phase !== 'buildServerBundle' && unstable_phase !== 'buildSsrBundle') || diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts index 18e80fcd6..e103346cb 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts @@ -61,6 +61,11 @@ export function deployDenoPlugin(opts: { configResolved(config) { entriesFile = `${config.root}/${opts.srcDir}/${SRC_ENTRIES}`; const { deploy, unstable_phase } = platformObject.buildOptions || {}; + if (deploy === 'deno' && Array.isArray(config.ssr.external)) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } if ( (unstable_phase !== 'buildServerBundle' && unstable_phase !== 'buildSsrBundle') || 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..18c1b7237 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -56,6 +56,15 @@ export function deployNetlifyPlugin(opts: { configResolved(config) { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; + const { deploy } = platformObject.buildOptions || {}; + if ( + deploy === 'netlify-functions' && + Array.isArray(config.ssr.external) + ) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) { 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..1ebef3d87 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -68,6 +68,15 @@ export function deployVercelPlugin(opts: { configResolved(config) { rootDir = config.root; entriesFile = `${rootDir}/${opts.srcDir}/${SRC_ENTRIES}`; + const { deploy } = platformObject.buildOptions || {}; + if ( + deploy === 'vercel-serverless' && + Array.isArray(config.ssr.external) + ) { + config.ssr.external = config.ssr.external.filter( + (item) => item !== 'hono/context-storage', + ); + } }, resolveId(source) { if (source === `${opts.srcDir}/${SERVE_JS}`) {