Skip to content
Merged
Show file tree
Hide file tree
Changes from 163 commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
7259f61
feat: use Vite RSC API
hi-ogawa Jun 27, 2025
99c0a45
chore: vite-rsc 0.4.6 (#9)
hi-ogawa Jun 27, 2025
80fdab7
feat: deployment adapters (#8)
hi-ogawa Jun 27, 2025
d8a1329
chore: lint (#10)
hi-ogawa Jun 27, 2025
4f3f8fd
chore: cleanup types (#12)
hi-ogawa Jun 27, 2025
873d07a
chore: comment
hi-ogawa Jun 27, 2025
1adfac4
fix: fix uncaught error in fs-router on server syntax error
hi-ogawa Jun 27, 2025
68dbd83
fix: windows?
hi-ogawa Jun 27, 2025
3640abd
test: tweak syntax error recovery test
hi-ogawa Jun 27, 2025
0ecda37
chore: cleanup (#13)
hi-ogawa Jun 27, 2025
b182318
fix: support private dir
hi-ogawa Jun 27, 2025
1b49819
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jun 29, 2025
cf1d521
test: add 1491 repro
hi-ogawa Jun 30, 2025
d508229
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jun 30, 2025
019e367
test: tweak
hi-ogawa Jun 30, 2025
bc8e6be
test: tweak
hi-ogawa Jun 30, 2025
171c4d5
test: note
hi-ogawa Jun 30, 2025
da69d31
test: tweak
hi-ogawa Jun 30, 2025
f99e6e3
fix: use pre middleware
hi-ogawa Jun 30, 2025
0612afe
fix: windows
hi-ogawa Jun 30, 2025
0c827a1
fix: avoid double refetch on redirect
hi-ogawa Jun 30, 2025
30546eb
test: full ci (#11)
hi-ogawa Jun 30, 2025
dd8f332
ci: cleanup
hi-ogawa Jun 30, 2025
8119dfb
test: cleanup
hi-ogawa Jun 30, 2025
bfa10e1
chore(deps): update vite-rsc 0.4.8
hi-ogawa Jul 1, 2025
f90eb8a
fix: automatically add import.meta.hot.accept in server entry
hi-ogawa Jul 3, 2025
51ea05c
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 3, 2025
e6efcf8
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 4, 2025
ba1bed6
chore: fix merge
hi-ogawa Jul 4, 2025
4eee317
chore: replace @hiogawa/vite-rsc with @vitejs/plugin-rsc (#17)
hi-ogawa Jul 4, 2025
44b652d
chore: limit package.json exports
hi-ogawa Jul 4, 2025
1906694
Revert "chore: limit package.json exports"
hi-ogawa Jul 4, 2025
2d91639
chore(deps): @vitejs/plugin-rsc v0.4.10-alpha.1 (#18)
hi-ogawa Jul 4, 2025
d3943d7
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 9, 2025
6b21bdc
chore: plugin-rsc v0.4.11
hi-ogawa Jul 9, 2025
726a861
test: revert `describe.serial`
hi-ogawa Jul 9, 2025
9495b01
refactor: internalize `waku/vite-rsc`
hi-ogawa Jul 9, 2025
42677b3
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 9, 2025
b0d24bc
fix: support custom react plugin
hi-ogawa Jul 9, 2025
7bd7c4c
test: retry
hi-ogawa Jul 9, 2025
24c248c
chore: cleanup
hi-ogawa Jul 9, 2025
38de285
fix: typo map -> some
hi-ogawa Jul 9, 2025
71f1019
fix: add `optimizeDeps.entries`
hi-ogawa Jul 9, 2025
045b447
chore: cleanup diff
hi-ogawa Jul 9, 2025
19052a2
chore: reduce diff
hi-ogawa Jul 9, 2025
cee7862
chore: comment
hi-ogawa Jul 9, 2025
d9eacde
fix: fix examples/41_path-alias
hi-ogawa Jul 9, 2025
57a5be3
fix: more typo
hi-ogawa Jul 9, 2025
ed00a77
fix: add `loadCss` to `examples/42_react-tweet`
hi-ogawa Jul 9, 2025
7e89d49
chore: lint
hi-ogawa Jul 9, 2025
0240254
chore: update vanilla-extract
hi-ogawa Jul 9, 2025
5b98ad1
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 9, 2025
8c12aaa
refactor: tweak deploy plugins
hi-ogawa Jul 9, 2025
084c71a
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 9, 2025
e41b2c0
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 10, 2025
5ae18cd
chore: rename like https://github.com/wakujs/waku/pull/1517
hi-ogawa Jul 10, 2025
daa21a6
refactor: constants
hi-ogawa Jul 10, 2025
0a86d76
chore: cleanup
hi-ogawa Jul 11, 2025
1d5a63d
test: tweak create-pages.spec.ts
hi-ogawa Jul 11, 2025
1ab734f
fix: use https://github.com/wakujs/waku/pull/1522
hi-ogawa Jul 11, 2025
ee8845e
test: tweak
hi-ogawa Jul 11, 2025
707a236
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 14, 2025
abc0db2
chore: cleanup
hi-ogawa Jul 14, 2025
08d2ad9
chore: update css examples
hi-ogawa Jul 14, 2025
0e6cdcb
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 16, 2025
e42e33b
test: examples-smoke with vite-rsc
hi-ogawa Jul 16, 2025
fcae1f9
chore: lint
hi-ogawa Jul 16, 2025
17536e9
chore: cleanup rsc-html-stream patch
hi-ogawa Jul 16, 2025
a1ab97e
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 16, 2025
a8bda0b
chore: log unknown handleRequest errors
hi-ogawa Jul 16, 2025
e350bcd
fix: add website/waku.config.ts
hi-ogawa Jul 16, 2025
97558a8
chore: add e2e-dev/prd scripts
hi-ogawa Jul 16, 2025
62b7259
chore: use captureOwnerStack for error logs
hi-ogawa Jul 16, 2025
ecd02d3
test: fix examples/38_cookies private dir
hi-ogawa Jul 16, 2025
92be33b
fix: fix `fsRouter(import.meta.url, ...)`
hi-ogawa Jul 16, 2025
61bf66c
fix: add client-entry to `optimizeDeps.entries`
hi-ogawa Jul 16, 2025
bde7781
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 16, 2025
270266d
test: fix e2e utils
hi-ogawa Jul 16, 2025
5ce677a
test: cherry-pick https://github.com/wakujs/waku/pull/1536
hi-ogawa Jul 16, 2025
f7c007b
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 16, 2025
ddab312
fix: add ssr retry
hi-ogawa Jul 16, 2025
7cac0bb
chore: lint
hi-ogawa Jul 17, 2025
81ed3f6
test: tweak
hi-ogawa Jul 17, 2025
0b8d50a
chore: enable default and add opt-out flag `--no-vite-rsc`
hi-ogawa Jul 17, 2025
052646e
test: no-vite-rsc -> legacy (TEST_VITE_RSC -> TEST_LEGACY)
hi-ogawa Jul 17, 2025
f1c5f77
chore: lint
hi-ogawa Jul 17, 2025
f67b64d
chore: --legacy ==> --experimental-legacy-cli
hi-ogawa Jul 17, 2025
6582395
test: tweak playwright
hi-ogawa Jul 17, 2025
adc65d1
chore: sort package.json
hi-ogawa Jul 17, 2025
fa4df7b
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 17, 2025
de59461
test: cleanup
hi-ogawa Jul 17, 2025
878e170
fix: avoid rsc reload on syntax error
hi-ogawa Jul 18, 2025
ec3fef6
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 19, 2025
ee57f6a
fix: support 'fallback'
hi-ogawa Jul 19, 2025
6c8cfe4
chore: cleanup test
hi-ogawa Jul 19, 2025
1197f5e
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 22, 2025
34eb7f8
refactor: remove ssr retry in favor of wrapper use
hi-ogawa Jul 22, 2025
753bb53
chore: cleanup
hi-ogawa Jul 22, 2025
29935b5
chore: remove help
hi-ogawa Jul 22, 2025
61d41a8
chore: opitonal chain import.meta.viteRsc?.loadCss
hi-ogawa Jul 22, 2025
eac65ba
chore: more cleanup
hi-ogawa Jul 22, 2025
fc094dd
fix: add "waku" to `frameworkPackages`
hi-ogawa Jul 22, 2025
596547d
fix: use hono server on dev
hi-ogawa Jul 22, 2025
f1f0607
fix: allow `waku/middleware/context` to be removable
hi-ogawa Jul 22, 2025
d01d3a6
fix: allow `waku/middleware/handler` to be removable
hi-ogawa Jul 22, 2025
95d2c59
chore: lint
hi-ogawa Jul 22, 2025
23484b8
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 22, 2025
7c4cbed
chore: revert pkg.pr.new + ignoredPackageWarnings
hi-ogawa Jul 22, 2025
ef6e085
chore: comment
hi-ogawa Jul 23, 2025
af9461f
chore: react named imports
hi-ogawa Jul 23, 2025
69df00e
Revert "chore: react named imports"
hi-ogawa Jul 23, 2025
ce170c7
chore: lint
hi-ogawa Jul 23, 2025
c5eb518
chore: comment
hi-ogawa Jul 23, 2025
2f01fcd
refactor: react named import (2nd try)
hi-ogawa Jul 23, 2025
ac8e1ff
chore: comment
hi-ogawa Jul 23, 2025
8191f2b
refactor: check waku.config exists beforehand
hi-ogawa Jul 23, 2025
39e4a35
chore: lint
hi-ogawa Jul 23, 2025
3a030f8
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 24, 2025
9178b95
fix: support WAKU_PUBLIC
hi-ogawa Jul 24, 2025
f7204ff
refactor: move INTERNAL_setAllEnv to deploy entry
hi-ogawa Jul 24, 2025
64d04a3
refactor: move entry.browser.pre.tsx
hi-ogawa Jul 24, 2025
f0a287f
refactor: move entry.ssr.tsx
hi-ogawa Jul 24, 2025
5f90424
refactor: move code
hi-ogawa Jul 24, 2025
b54d0b9
refactor: move code
hi-ogawa Jul 24, 2025
4562b7d
refactor: move code to lib/rsc/build.ts
hi-ogawa Jul 24, 2025
482b5c6
refactor: move code to lib/rsc/handler
hi-ogawa Jul 24, 2025
90a5282
refactor: move types
hi-ogawa Jul 24, 2025
f1cffa5
refactor: move createHonoHandler to lib/rsc/engine.ts
hi-ogawa Jul 24, 2025
3bca211
refactor: move code to lib/rsc.js
hi-ogawa Jul 24, 2025
4d46829
refactor: static import server entry
hi-ogawa Jul 24, 2025
760405b
fix: missing INTERNAL_setAllEnv on vercel
hi-ogawa Jul 25, 2025
961a3ce
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 25, 2025
a5c0450
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 25, 2025
2071f8c
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 25, 2025
f75859b
Merge remote-tracking branch 'origin/chore-vite-rsc' into chore-vite-rsc
hi-ogawa Jul 25, 2025
3078ef8
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 25, 2025
9c76aff
refactor: use https://github.com/vitejs/vite-plugin-react/pull/626 fo…
hi-ogawa Jul 26, 2025
8a1b0a3
Merge remote-tracking branch 'origin/chore-vite-rsc' into chore-vite-rsc
hi-ogawa Jul 26, 2025
b91832b
chore(deps): update
hi-ogawa Jul 26, 2025
fb3968b
chore(deps): test https://github.com/vitejs/vite-plugin-react/pull/624
hi-ogawa Jul 26, 2025
559bfe8
chore(deps): rsc plugin v0.4.14
hi-ogawa Jul 27, 2025
8c7463c
chore(deps): test https://github.com/vitejs/vite-plugin-react/pull/643
hi-ogawa Jul 28, 2025
765dba9
chore(deps): rsc plugin 0.4.15
hi-ogawa Jul 28, 2025
598ec7b
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 29, 2025
bfb29f8
fix: align server start log
hi-ogawa Jul 30, 2025
55cc5fb
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 30, 2025
51242c8
refactor: comment
hi-ogawa Jul 31, 2025
709a926
refactor: flatten `lib/rsc` directory
hi-ogawa Jul 31, 2025
2b44677
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 31, 2025
a13ab47
chore: fix lockfile
hi-ogawa Jul 31, 2025
61383e7
fix: re-export
hi-ogawa Jul 31, 2025
e8bacbc
refactor: rename waku -> wakuPlugin
hi-ogawa Jul 31, 2025
acb832c
refactor: rename entry.rsc -> entry.server
hi-ogawa Jul 31, 2025
16d6839
refactor: rename more
hi-ogawa Jul 31, 2025
5185108
refactor: rename
hi-ogawa Jul 31, 2025
6fa1d40
refactor: rename
hi-ogawa Jul 31, 2025
4d7155b
refactor: object spread
hi-ogawa Jul 31, 2025
268e39f
refactor: one more
hi-ogawa Jul 31, 2025
063ce8e
Merge branch 'main' into chore-vite-rsc
hi-ogawa Jul 31, 2025
f52fbce
chore(deps): test https://github.com/vitejs/vite-plugin-react/pull/658
hi-ogawa Aug 1, 2025
9245959
refactor: replace writeBundle with buildApp hook
hi-ogawa Aug 1, 2025
d48bbee
chore(deps): rsc plugin v0.4.16
hi-ogawa Aug 1, 2025
0625f25
Merge branch 'main' into chore-vite-rsc
hi-ogawa Aug 1, 2025
8bb7d99
refactor: named imports
hi-ogawa Aug 1, 2025
66b0d5e
chore: comment on `import.meta.viteRsc.loadModule`
hi-ogawa Aug 1, 2025
25a0670
Merge branch 'main' into chore-vite-rsc
hi-ogawa Aug 2, 2025
6eeac09
fix: support index.html
hi-ogawa Aug 2, 2025
15e2299
test: add e2e
hi-ogawa Aug 2, 2025
fb56c94
chore: lint
hi-ogawa Aug 2, 2025
a882734
chore: cleanup
hi-ogawa Aug 2, 2025
c9e6546
Merge branch 'main' into chore-vite-rsc
hi-ogawa Aug 2, 2025
db7f3b1
chore: lint
hi-ogawa Aug 2, 2025
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
9 changes: 9 additions & 0 deletions e2e/fixtures/rsc-asset/waku.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ export default defineConfig({
plugins: [importMetaUrlServerPlugin()],
}),
},
vite: {
plugins: [
{
...importMetaUrlServerPlugin(),
apply: 'build',
applyToEnvironment: (environment) => environment.name === 'rsc',
},
],
},
});

// emit asset and rewrite `new URL("./xxx", import.meta.url)` syntax for build.
Expand Down
13 changes: 13 additions & 0 deletions e2e/fixtures/ssr-swr/waku.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'waku/config';

export default defineConfig({
vite: {
environments: {
ssr: {
optimizeDeps: {
include: ['swr'],
},
},
},
},
});
3 changes: 1 addition & 2 deletions e2e/hot-reload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ test.describe('hot reload', () => {
expect(bgColor3).toBe('rgb(0, 0, 255)');
});

// https://github.com/wakujs/waku/pull/1493 will fix this
test.skip('indirect client components (#1491)', async ({ page }) => {
test('indirect client components (#1491)', async ({ page }) => {
const errors: string[] = [];
page.on('pageerror', (err) => errors.push(err.message));
await page.goto(`http://localhost:${port}/`);
Expand Down
1 change: 1 addition & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default tseslint.config(
{
files: [
'packages/waku/cli.js',
'packages/waku/src/vite-rsc/**/*',
'packages/create-waku/cli.js',
'examples/41_path-alias/**/*.tsx',
],
Expand Down
12 changes: 12 additions & 0 deletions examples/05_compiler/waku.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ export default defineConfig({
'dev-main': getConfig,
'build-client': getConfig,
},
vite: {
plugins: [
// cf. https://github.com/vitejs/vite-plugin-react/pull/537
react({ babel: { plugins: ['babel-plugin-react-compiler'] } }).map(
(p) =>
({
...p,
applyToEnvironment: (e: any) => e.name === 'client',
}) as any,
),
],
},
});
3 changes: 3 additions & 0 deletions examples/37_css-stylex/waku.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ export default defineConfig({
plugins: [react({ babel: babelConfig })],
}),
},
vite: {
plugins: [react({ babel: babelConfig })],
},
});
8 changes: 8 additions & 0 deletions examples/37_css-vanilla-extract/waku.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'waku/config';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';

export default defineConfig({
vite: {
plugins: [vanillaExtractPlugin()],
},
});
3 changes: 3 additions & 0 deletions examples/41_path-alias/waku.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export default defineConfig({
],
}),
},
vite: {
plugins: [tsconfigPaths()],
},
});
5 changes: 5 additions & 0 deletions packages/waku/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"parser": {
"syntax": "typescript"
},
"transform": {
"react": {
"runtime": "automatic"
}
},
"target": "esnext"
},
"sourceMaps": true
Expand Down
1 change: 1 addition & 0 deletions packages/waku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@hono/node-server": "1.17.1",
"@swc/core": "1.13.3",
"@vitejs/plugin-react": "4.7.0",
"@vitejs/plugin-rsc": "0.4.16",
"dotenv": "17.2.1",
"hono": "4.8.10",
"html-react-parser": "5.2.6",
Expand Down
14 changes: 13 additions & 1 deletion packages/waku/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const { values, positionals } = parseArgs({
'experimental-compress': {
type: 'boolean',
},
'experimental-legacy-cli': {
type: 'boolean',
},
port: {
type: 'string',
short: 'p',
Expand All @@ -77,6 +80,13 @@ if (values.version) {
console.log(version);
} else if (values.help) {
displayUsage();
} else if (
!values['experimental-legacy-cli'] &&
cmd &&
['dev', 'build', 'start'].includes(cmd)
) {
const { cli } = await import('./vite-rsc/cli.js');
await cli(cmd, values);
} else {
switch (cmd) {
case 'dev':
Expand Down Expand Up @@ -242,7 +252,9 @@ async function loadConfig(): Promise<Config> {
return (await loadServerModule<{ default: Config }>(file)).default;
}

type HonoEnhancer = <Hono>(fn: (app: Hono) => Hono) => (app: Hono) => Hono;
export type HonoEnhancer = <Hono>(
fn: (app: Hono) => Hono,
) => (app: Hono) => Hono;

async function loadHonoEnhancer(file: string): Promise<HonoEnhancer> {
const { loadServerModule } = await import('./lib/utils/vite-loader.js');
Expand Down
7 changes: 7 additions & 0 deletions packages/waku/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface Config {
*/
unstable_honoEnhancer?: string | undefined;
/**
* @deprecated use `vite` instead.
* Vite configuration options.
* `common` can contains shared configs that are shallowly merged with other configs.
* Defaults to `undefined` if not provided.
Expand All @@ -75,6 +76,12 @@ export interface Config {
'build-deploy'?: () => UserConfig;
}
| undefined;
/**
* Vite configuration options.
* See https://vite.dev/guide/api-environment-plugins.html#environment-api-for-plugins
* for how to configure or enable plugins per environment.
*/
vite?: UserConfig | undefined;
}

export function defineConfig(config: Config) {
Expand Down
1 change: 1 addition & 0 deletions packages/waku/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function resolveConfigDev(config: Config) {
middleware: DEFAULT_MIDDLEWARE,
unstable_honoEnhancer: undefined,
unstable_viteConfigs: undefined,
vite: undefined,
...config,
};
return configDev;
Expand Down
56 changes: 56 additions & 0 deletions packages/waku/src/vite-rsc/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as vite from 'vite';
import { mainPlugin, type MainPluginOptions } from './plugin.js';
import type { Config } from '../config.js';
import { existsSync } from 'node:fs';

export async function cli(cmd: string, flags: Record<string, any>) {
// set NODE_ENV before runnerImport https://github.com/vitejs/vite/issues/20299
process.env.NODE_ENV ??= cmd === 'dev' ? 'development' : 'production';

// TODO: reload during dev
let config: Config | undefined;
if (existsSync('waku.config.ts') || existsSync('waku.config.js')) {
const imported = await vite.runnerImport<{ default: Config }>(
'/waku.config',
);
config = imported.module.default;
}

const mainPluginOptions: MainPluginOptions = {
flags,
config,
};

if (cmd === 'dev') {
const server = await vite.createServer({
configFile: false,
plugins: [mainPlugin(mainPluginOptions)],
server: {
port: parseInt(flags.port || '3000', 10),
},
});
await server.listen();
const url = server.resolvedUrls!['local'];
console.log(`ready: Listening on ${url}`);
}

if (cmd === 'build') {
const builder = await vite.createBuilder({
configFile: false,
plugins: [mainPlugin(mainPluginOptions)],
});
await builder.buildApp();
}

if (cmd === 'start') {
const server = await vite.preview({
configFile: false,
plugins: [mainPlugin(mainPluginOptions)],
preview: {
port: parseInt(flags.port || '8080', 10),
},
});
const url = server.resolvedUrls!['local'];
console.log(`ready: Listening on ${url}`);
}
}
32 changes: 32 additions & 0 deletions packages/waku/src/vite-rsc/deploy/aws-lambda/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Hono } from 'hono';
import * as honoAwsLambda from 'hono/aws-lambda';
import { createHonoHandler } from '../../lib/engine.js';
import { honoEnhancer } from 'virtual:vite-rsc-waku/hono-enhancer';
import { config } from 'virtual:vite-rsc-waku/config';
import { serveStatic } from '@hono/node-server/serve-static';
import path from 'node:path';
import fs from 'node:fs';
import { DIST_PUBLIC } from '../../../lib/builder/constants.js';
import { INTERNAL_setAllEnv } from '../../../server.js';

function createApp(app: Hono) {
INTERNAL_setAllEnv(process.env as any);
app.use(serveStatic({ root: path.join(config.distDir, DIST_PUBLIC) }));
app.use(createHonoHandler());
app.notFound((c) => {
const file = path.join(config.distDir, DIST_PUBLIC, '404.html');
if (fs.existsSync(file)) {
return c.html(fs.readFileSync(file, 'utf8'), 404);
}
return c.text('404 Not Found', 404);
});
return app;
}

const app = honoEnhancer(createApp)(new Hono());

export const handler: any = import.meta.env.WAKU_AWS_LAMBDA_STREAMING
? honoAwsLambda.streamHandle(app)
: honoAwsLambda.handle(app);

export { handleBuild } from '../../lib/build.js';
63 changes: 63 additions & 0 deletions packages/waku/src/vite-rsc/deploy/aws-lambda/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { type Plugin, type ResolvedConfig } from 'vite';
import { writeFileSync } from 'node:fs';
import path from 'node:path';
import type { Config } from '../../../config.js';
import { fileURLToPath } from 'node:url';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const SERVER_ENTRY = path.join(__dirname, 'entry.js');
const SERVE_JS = 'serve-aws-lambda.js';

export function deployAwsLambdaPlugin(deployOptions: {
config: Required<Config>;
streaming: boolean;
}): Plugin {
return {
name: 'waku:deploy-aws-lambda',
config() {
return {
environments: {
rsc: {
build: {
rollupOptions: {
input: {
index: SERVER_ENTRY,
},
},
},
define: {
'import.meta.env.WAKU_AWS_LAMBDA_STREAMING': JSON.stringify(
deployOptions.streaming,
),
},
},
},
};
},
buildApp: {
order: 'post',
async handler(builder) {
await build({
config: builder.config,
opts: deployOptions.config,
});
},
},
};
}

async function build({
opts,
}: {
config: ResolvedConfig;
opts: Required<Config>;
}) {
writeFileSync(
path.join(opts.distDir, SERVE_JS),
`export { handler } from './rsc/index.js';\n`,
);
writeFileSync(
path.join(opts.distDir, 'package.json'),
JSON.stringify({ type: 'module' }, null, 2),
);
}
38 changes: 38 additions & 0 deletions packages/waku/src/vite-rsc/deploy/cloudflare/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Hono } from 'hono';
import { createHonoHandler } from '../../lib/engine.js';
import { honoEnhancer } from 'virtual:vite-rsc-waku/hono-enhancer';
import { INTERNAL_setAllEnv } from '../../../server.js';

function createApp(app: Hono) {
app.use(createHonoHandler());
app.notFound(async (c) => {
const assetsFetcher = (c.env as any).ASSETS;
const url = new URL(c.req.raw.url);
const errorHtmlUrl = url.origin + '/404.html';
const notFoundStaticAssetResponse = await assetsFetcher.fetch(
new URL(errorHtmlUrl),
);
if (
notFoundStaticAssetResponse &&
notFoundStaticAssetResponse.status < 400
) {
return c.body(notFoundStaticAssetResponse.body, 404);
}
return c.text('404 Not Found', 404);
});
return app;
}

let app: Hono | undefined;

export default {
fetch: (request: Request, env: any, ctx: any) => {
if (!app) {
INTERNAL_setAllEnv(env);
app = honoEnhancer(createApp)(new Hono());
}
return app.fetch(request, env, ctx);
},
};

export { handleBuild } from '../../lib/build.js';
Loading
Loading