Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hono): import hono/context-storage directly #898

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 11 additions & 3 deletions packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,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 || {};
Expand Down
14 changes: 11 additions & 3 deletions packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down Expand Up @@ -66,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 || {};
Expand Down
14 changes: 11 additions & 3 deletions packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -78,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 || {};
Expand Down
1 change: 0 additions & 1 deletion packages/waku/src/unstable_hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Loading