From 687f418dbee067d601a8deb3196f3e368b96759f Mon Sep 17 00:00:00 2001 From: daishi Date: Mon, 4 Mar 2024 22:48:05 +0900 Subject: [PATCH 1/4] remove old cli and with-ssr option --- README.md | 4 +- docs/builder/aws-lambda.mdx | 4 +- e2e/07_router_standalone.spec.ts | 6 +-- e2e/examples-smoke.spec.ts | 13 ++---- e2e/fixtures/ssr-basic/package.json | 6 +-- e2e/fixtures/ssr-swr/package.json | 6 +-- e2e/fixtures/ssr-target-bundle/package.json | 6 +-- e2e/ssr-basic.spec.ts | 6 +-- e2e/ssr-swr.spec.ts | 6 +-- e2e/ssr-target-bundle.spec.ts | 6 +-- examples/01_template/package.json | 6 +-- examples/02_demo/package.json | 6 +-- examples/03_minimal/package.json | 6 +-- examples/04_promise/package.json | 6 +-- examples/05_actions/package.json | 6 +-- examples/06_nesting/package.json | 6 +-- examples/07_router/package.json | 6 +-- examples/08_cookies/package.json | 6 +-- examples/09_cssmodules/package.json | 6 +-- examples/10_fs-router/package.json | 6 +-- examples/11_form/package.json | 6 +-- examples/12_css/package.json | 6 +-- examples/13_path-alias/package.json | 6 +-- examples/14_react-tweet/package.json | 6 +-- packages/waku/src/cli.ts | 51 +++------------------ packages/website/package.json | 6 +-- 26 files changed, 79 insertions(+), 125 deletions(-) diff --git a/README.md b/README.md index ef679e726..dc626d83b 100644 --- a/README.md +++ b/README.md @@ -644,7 +644,7 @@ Adding the `--with-vercel-static` flag to the build script will produce static s ``` { "scripts": { - "build": "waku build --with-ssr --with-vercel-static" + "build": "waku build --with-vercel-static" } } ``` @@ -665,7 +665,7 @@ Adding the `--with-netlify-static` flag to the build script will produce static ``` { "scripts": { - "build": "waku build --with-ssr --with-netlify-static" + "build": "waku build --with-netlify-static" } } ``` diff --git a/docs/builder/aws-lambda.mdx b/docs/builder/aws-lambda.mdx index 64f3d508c..2c4461cb3 100644 --- a/docs/builder/aws-lambda.mdx +++ b/docs/builder/aws-lambda.mdx @@ -59,7 +59,7 @@ custom: # add custom hooks hooks: before:package:createDeploymentArtifacts: - - pnpm waku build --with-ssr --with-aws-lambda + - pnpm waku build --with-aws-lambda ``` This configuration will include all files from the `./private` directory in the final deployment. @@ -196,7 +196,7 @@ export class WakuStack extends cdk.Stack { tryBundle(outputDir) { spawnSync( 'pnpm', - ['exec', 'waku', 'build', '--with-ssr', '--with-aws-lambda'], + ['exec', 'waku', 'build', '--with-aws-lambda'], { stdio: 'inherit' }, ); cpSync('dist', outputDir, { recursive: true, dereference: true }); diff --git a/e2e/07_router_standalone.spec.ts b/e2e/07_router_standalone.spec.ts index 31dfeed20..10699f056 100644 --- a/e2e/07_router_standalone.spec.ts +++ b/e2e/07_router_standalone.spec.ts @@ -69,7 +69,7 @@ test.describe('07_router standalone', () => { test(`should prod work ${withSSR ? 'with SSR' : ''}`, async ({ page }) => { test.fixme(withSSR, 'SSR is not working in standalone'); execSync( - `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} build${withSSR ? ' --with-ssr' : ''}`, + `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} build`, { cwd: standaloneDir, stdio: 'inherit', @@ -77,7 +77,7 @@ test.describe('07_router standalone', () => { ); const port = await getFreePort(); const cp = exec( - `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} start${withSSR ? ' --with-ssr' : ''}`, + `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} start`, { cwd: standaloneDir, env: { @@ -95,7 +95,7 @@ test.describe('07_router standalone', () => { test.fixme(withSSR, 'SSR is not working in standalone'); const port = await getFreePort(); const cp = exec( - `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} dev${withSSR ? ' --with-ssr' : ''}`, + `node ${join(standaloneDir, './node_modules/waku/dist/cli.js')} dev`, { cwd: standaloneDir, env: { diff --git a/e2e/examples-smoke.spec.ts b/e2e/examples-smoke.spec.ts index cfde5b24b..84d9208dd 100644 --- a/e2e/examples-smoke.spec.ts +++ b/e2e/examples-smoke.spec.ts @@ -23,17 +23,10 @@ const commands = [ { command: 'dev', }, - { - command: 'dev --with-ssr', - }, { build: 'build', command: 'start', }, - { - build: 'build --with-ssr', - command: 'start --with-ssr', - }, ]; const specialExamples = [ @@ -41,14 +34,14 @@ const specialExamples = [ name: '08_cookies', commands: [ { - command: 'node dev.js --with-ssr', + command: 'node dev.js', }, { command: 'node dev.js', }, { - build: 'waku build --with-ssr', - command: 'node start.js --with-ssr', + build: 'waku build', + command: 'node start.js', }, { build: 'waku build', diff --git a/e2e/fixtures/ssr-basic/package.json b/e2e/fixtures/ssr-basic/package.json index 83ee50b85..58cd0ed5b 100644 --- a/e2e/fixtures/ssr-basic/package.json +++ b/e2e/fixtures/ssr-basic/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/e2e/fixtures/ssr-swr/package.json b/e2e/fixtures/ssr-swr/package.json index dff278807..ed71abfe8 100644 --- a/e2e/fixtures/ssr-swr/package.json +++ b/e2e/fixtures/ssr-swr/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/e2e/fixtures/ssr-target-bundle/package.json b/e2e/fixtures/ssr-target-bundle/package.json index 2484ab882..d0bc1077b 100644 --- a/e2e/fixtures/ssr-target-bundle/package.json +++ b/e2e/fixtures/ssr-target-bundle/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/e2e/ssr-basic.spec.ts b/e2e/ssr-basic.spec.ts index 63b15849c..4f5d8eca5 100644 --- a/e2e/ssr-basic.spec.ts +++ b/e2e/ssr-basic.spec.ts @@ -11,11 +11,11 @@ const waku = fileURLToPath( const commands = [ { - command: 'dev --with-ssr', + command: 'dev', }, { - build: 'build --with-ssr', - command: 'start --with-ssr', + build: 'build', + command: 'start', }, ]; diff --git a/e2e/ssr-swr.spec.ts b/e2e/ssr-swr.spec.ts index c070a4dc1..b5f7ad95e 100644 --- a/e2e/ssr-swr.spec.ts +++ b/e2e/ssr-swr.spec.ts @@ -11,11 +11,11 @@ const waku = fileURLToPath( const commands = [ { - command: 'dev --with-ssr', + command: 'dev', }, { - build: 'build --with-ssr', - command: 'start --with-ssr', + build: 'build', + command: 'start', }, ]; diff --git a/e2e/ssr-target-bundle.spec.ts b/e2e/ssr-target-bundle.spec.ts index 7d7316ff8..705d057d2 100644 --- a/e2e/ssr-target-bundle.spec.ts +++ b/e2e/ssr-target-bundle.spec.ts @@ -12,11 +12,11 @@ const waku = fileURLToPath( const commands = [ { - command: 'dev --with-ssr', + command: 'dev', }, { - build: 'build --with-ssr', - command: 'start --with-ssr', + build: 'build', + command: 'start', }, ]; diff --git a/examples/01_template/package.json b/examples/01_template/package.json index f5013c0f9..d9a8afac2 100644 --- a/examples/01_template/package.json +++ b/examples/01_template/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/02_demo/package.json b/examples/02_demo/package.json index 656ba73fe..0efb2676d 100644 --- a/examples/02_demo/package.json +++ b/examples/02_demo/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/03_minimal/package.json b/examples/03_minimal/package.json index 06a744bd1..572255012 100644 --- a/examples/03_minimal/package.json +++ b/examples/03_minimal/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/04_promise/package.json b/examples/04_promise/package.json index 06a744bd1..572255012 100644 --- a/examples/04_promise/package.json +++ b/examples/04_promise/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/05_actions/package.json b/examples/05_actions/package.json index 2db6ade78..4a6022340 100644 --- a/examples/05_actions/package.json +++ b/examples/05_actions/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/06_nesting/package.json b/examples/06_nesting/package.json index 06a744bd1..572255012 100644 --- a/examples/06_nesting/package.json +++ b/examples/06_nesting/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/07_router/package.json b/examples/07_router/package.json index 7f4dd1574..51a7454d0 100644 --- a/examples/07_router/package.json +++ b/examples/07_router/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/08_cookies/package.json b/examples/08_cookies/package.json index 41a1f5e5f..7dfab6b33 100644 --- a/examples/08_cookies/package.json +++ b/examples/08_cookies/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "cookie": "0.6.0", diff --git a/examples/09_cssmodules/package.json b/examples/09_cssmodules/package.json index 06a744bd1..572255012 100644 --- a/examples/09_cssmodules/package.json +++ b/examples/09_cssmodules/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/10_fs-router/package.json b/examples/10_fs-router/package.json index 27b964699..352f64293 100644 --- a/examples/10_fs-router/package.json +++ b/examples/10_fs-router/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "glob": "10.3.10", diff --git a/examples/11_form/package.json b/examples/11_form/package.json index 06a744bd1..572255012 100644 --- a/examples/11_form/package.json +++ b/examples/11_form/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/12_css/package.json b/examples/12_css/package.json index c6515d939..463ee61a9 100644 --- a/examples/12_css/package.json +++ b/examples/12_css/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "@stylexjs/stylex": "0.5.1", diff --git a/examples/13_path-alias/package.json b/examples/13_path-alias/package.json index 6fff95519..261bdcea1 100644 --- a/examples/13_path-alias/package.json +++ b/examples/13_path-alias/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/examples/14_react-tweet/package.json b/examples/14_react-tweet/package.json index c75e654a6..2505f07e4 100644 --- a/examples/14_react-tweet/package.json +++ b/examples/14_react-tweet/package.json @@ -4,9 +4,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "react": "18.3.0-canary-6c3b8dbfe-20240226", diff --git a/packages/waku/src/cli.ts b/packages/waku/src/cli.ts index c0400cfca..95444d0a2 100644 --- a/packages/waku/src/cli.ts +++ b/packages/waku/src/cli.ts @@ -10,8 +10,6 @@ import * as dotenv from 'dotenv'; import type { Config } from './config.js'; import { resolveConfig } from './lib/config.js'; -import { honoMiddleware as honoDevMiddleware } from './lib/old-wrappers/hono-dev.js'; -import { honoMiddleware as honoPrdMiddleware } from './lib/old-wrappers/hono-prd.js'; import { runner } from './lib/hono/runner.js'; import { build } from './lib/builder/build.js'; @@ -25,9 +23,6 @@ const { values, positionals } = parseArgs({ args: process.argv.slice(2), allowPositionals: true, options: { - 'with-ssr': { - type: 'boolean', - }, 'with-vercel': { type: 'boolean', }, @@ -71,16 +66,15 @@ if (values.version) { } else if (values.help) { displayUsage(); } else { - const ssr = !!values['with-ssr']; switch (cmd) { case 'dev': - await runDev({ ssr }); + await runDev(); break; case 'build': await runBuild(); break; case 'start': - await runStart({ ssr }); + await runStart(); break; default: if (cmd) { @@ -91,17 +85,10 @@ if (values.version) { } } -async function runDev(options: { ssr: boolean }) { +async function runDev() { const config = await loadConfig(); const app = new Hono(); - if (!process.env.WAKU_OLD_MIDDLEWARE) { - app.use('*', runner({ cmd: 'dev', config, env: process.env as any })); - } else { - app.use( - '*', - honoDevMiddleware({ ...options, config, env: process.env as any }), - ); - } + app.use('*', runner({ cmd: 'dev', config, env: process.env as any })); const port = parseInt(process.env.PORT || '3000', 10); await startServer(app, port); } @@ -130,39 +117,14 @@ async function runBuild() { }); } -async function runStart(options: { ssr: boolean }) { +async function runStart() { const config = await loadConfig(); const { distDir, publicDir, entriesJs } = await resolveConfig(config); const loadEntries = () => import(pathToFileURL(path.resolve(distDir, entriesJs)).toString()); const app = new Hono(); app.use('*', serveStatic({ root: path.join(distDir, publicDir) })); - if (!process.env.WAKU_OLD_MIDDLEWARE) { - app.use( - '*', - runner({ cmd: 'start', loadEntries, env: process.env as any }), - ); - } else { - app.use( - '*', - honoPrdMiddleware({ - ...options, - config, - loadEntries, - env: process.env as any, - }), - ); - } - if (!options.ssr) { - // history api fallback - app.use( - '*', - serveStatic({ - root: path.join(distDir, publicDir), - rewriteRequestPath: () => '/', - }), - ); - } + app.use('*', runner({ cmd: 'start', loadEntries, env: process.env as any })); app.notFound((c) => { // FIXME better implementation using node stream? const file = path.join(distDir, publicDir, '404.html'); @@ -206,7 +168,6 @@ Commands: start Start the production server Options: - --with-ssr Use opt-in SSR --with-vercel Output for Vercel on build --with-netlify Output for Netlify on build --with-cloudflare Output for Cloudflare on build diff --git a/packages/website/package.json b/packages/website/package.json index 8f4f60fcc..e72d594fc 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -5,9 +5,9 @@ "type": "module", "private": true, "scripts": { - "dev": "waku dev --with-ssr", - "build": "waku build --with-ssr", - "start": "waku start --with-ssr" + "dev": "waku dev", + "build": "waku build", + "start": "waku start" }, "dependencies": { "@sindresorhus/slugify": "^2.2.1", From 83e0307ab2b970e85105e3e7af45f69d9586fd54 Mon Sep 17 00:00:00 2001 From: daishi Date: Mon, 4 Mar 2024 23:00:38 +0900 Subject: [PATCH 2/4] overlooked --- e2e/examples-smoke.spec.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/e2e/examples-smoke.spec.ts b/e2e/examples-smoke.spec.ts index 84d9208dd..14bb19e09 100644 --- a/e2e/examples-smoke.spec.ts +++ b/e2e/examples-smoke.spec.ts @@ -36,13 +36,6 @@ const specialExamples = [ { command: 'node dev.js', }, - { - command: 'node dev.js', - }, - { - build: 'waku build', - command: 'node start.js', - }, { build: 'waku build', command: 'node start.js', From fab148c09c1ea46c2908b1a8249f08a1d80449bc Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 5 Mar 2024 11:41:51 +0900 Subject: [PATCH 3/4] fix tests --- e2e/ssr-target-bundle.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/ssr-target-bundle.spec.ts b/e2e/ssr-target-bundle.spec.ts index 705d057d2..bea1ac182 100644 --- a/e2e/ssr-target-bundle.spec.ts +++ b/e2e/ssr-target-bundle.spec.ts @@ -65,7 +65,7 @@ for (const { build, command } of commands) { }); test('image exists in folder public/assets', async () => { - test.skip(command.startsWith('dev ')); + test.skip(command.startsWith('dev')); const imagePath = path.join(cwd, 'dist', 'public', 'assets'); const files = await readdir(imagePath); const imageExists = files.some((file) => @@ -75,7 +75,7 @@ for (const { build, command } of commands) { }); test('json public linked exists in folder public/assets', async () => { - test.skip(command.startsWith('dev ')); + test.skip(command.startsWith('dev')); const imagePath = path.join(cwd, 'dist', 'public', 'assets'); const files = await readdir(imagePath); const imageExists = files.some((file) => @@ -85,7 +85,7 @@ for (const { build, command } of commands) { }); test('json private NOT exists in folder public/assets', async () => { - test.skip(command.startsWith('dev ')); + test.skip(command.startsWith('dev')); const imagePath = path.join(cwd, 'dist', 'public', 'assets'); const files = await readdir(imagePath); const imageExists = files.some((file) => From e2f5a7f8eced160578e756c922c7de7a9454fa7f Mon Sep 17 00:00:00 2001 From: daishi Date: Tue, 5 Mar 2024 12:14:20 +0900 Subject: [PATCH 4/4] clean up unused code --- packages/waku/package.json | 8 - packages/waku/src/dev.ts | 4 - packages/waku/src/lib/builder/build.ts | 3 +- packages/waku/src/lib/handlers/handler-dev.ts | 278 ------------------ packages/waku/src/lib/handlers/handler-prd.ts | 146 --------- packages/waku/src/lib/handlers/types.ts | 18 -- .../waku/src/lib/old-wrappers/connect-dev.ts | 6 - .../waku/src/lib/old-wrappers/connect-prd.ts | 6 - .../src/lib/old-wrappers/connect-utils.ts | 32 -- .../waku/src/lib/old-wrappers/hono-dev.ts | 13 - .../waku/src/lib/old-wrappers/hono-prd.ts | 13 - .../waku/src/lib/old-wrappers/hono-utils.ts | 75 ----- .../waku/src/lib/renderers/html-renderer.ts | 2 +- packages/waku/src/lib/utils/stream.ts | 9 +- packages/waku/src/prd.ts | 2 - 15 files changed, 3 insertions(+), 612 deletions(-) delete mode 100644 packages/waku/src/dev.ts delete mode 100644 packages/waku/src/lib/handlers/handler-dev.ts delete mode 100644 packages/waku/src/lib/handlers/handler-prd.ts delete mode 100644 packages/waku/src/lib/handlers/types.ts delete mode 100644 packages/waku/src/lib/old-wrappers/connect-dev.ts delete mode 100644 packages/waku/src/lib/old-wrappers/connect-prd.ts delete mode 100644 packages/waku/src/lib/old-wrappers/connect-utils.ts delete mode 100644 packages/waku/src/lib/old-wrappers/hono-dev.ts delete mode 100644 packages/waku/src/lib/old-wrappers/hono-prd.ts delete mode 100644 packages/waku/src/lib/old-wrappers/hono-utils.ts delete mode 100644 packages/waku/src/prd.ts diff --git a/packages/waku/package.json b/packages/waku/package.json index 179a0a4ec..32643fd5f 100644 --- a/packages/waku/package.json +++ b/packages/waku/package.json @@ -29,14 +29,6 @@ "types": "./dist/middleware/*.d.ts", "default": "./dist/middleware/*.js" }, - "./prd": { - "types": "./dist/prd.d.ts", - "default": "./dist/prd.js" - }, - "./dev": { - "types": "./dist/dev.d.ts", - "default": "./dist/dev.js" - }, "./node-loader": { "types": "./dist/node-loader.d.ts", "default": "./dist/node-loader.js" diff --git a/packages/waku/src/dev.ts b/packages/waku/src/dev.ts deleted file mode 100644 index 2e717dc2e..000000000 --- a/packages/waku/src/dev.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { honoMiddleware as unstable_honoMiddleware } from './lib/old-wrappers/hono-dev.js'; -export { connectMiddleware as unstable_connectMiddleware } from './lib/old-wrappers/connect-dev.js'; - -export { build as unstable_build } from './lib/builder/build.js'; diff --git a/packages/waku/src/lib/builder/build.ts b/packages/waku/src/lib/builder/build.ts index 95f8775b8..726ce62ea 100644 --- a/packages/waku/src/lib/builder/build.ts +++ b/packages/waku/src/lib/builder/build.ts @@ -39,8 +39,7 @@ import { getSsrConfig, } from '../renderers/rsc-renderer.js'; import { renderHtml } from '../renderers/html-renderer.js'; -import { CLIENT_MODULE_MAP } from '../handlers/handler-dev.js'; -import { CLIENT_PREFIX } from '../handlers/handler-prd.js'; +import { CLIENT_MODULE_MAP, CLIENT_PREFIX } from '../middleware/ssr.js'; import { rscIndexPlugin } from '../plugins/vite-plugin-rsc-index.js'; import { rscAnalyzePlugin } from '../plugins/vite-plugin-rsc-analyze.js'; import { nonjsResolvePlugin } from '../plugins/vite-plugin-nonjs-resolve.js'; diff --git a/packages/waku/src/lib/handlers/handler-dev.ts b/packages/waku/src/lib/handlers/handler-dev.ts deleted file mode 100644 index 5caff6e9a..000000000 --- a/packages/waku/src/lib/handlers/handler-dev.ts +++ /dev/null @@ -1,278 +0,0 @@ -import { Readable, Writable } from 'node:stream'; -import { createServer as createViteServer } from 'vite'; -import viteReact from '@vitejs/plugin-react'; - -import type { Config } from '../../config.js'; -import { resolveConfig } from '../config.js'; -import { - joinPath, - fileURLToFilePath, - decodeFilePathFromAbsolute, -} from '../utils/path.js'; -import { endStream } from '../utils/stream.js'; -import { renderHtml } from '../renderers/html-renderer.js'; -import { decodeInput, hasStatusCode } from '../renderers/utils.js'; -import { - initializeWorker, - registerHotUpdateCallback, - renderRscWithWorker, - getSsrConfigWithWorker, -} from '../renderers/dev-worker-api.js'; -import { patchReactRefresh } from '../plugins/patch-react-refresh.js'; -import { rscIndexPlugin } from '../plugins/vite-plugin-rsc-index.js'; -import { rscHmrPlugin, hotUpdate } from '../plugins/vite-plugin-rsc-hmr.js'; -import { rscEnvPlugin } from '../plugins/vite-plugin-rsc-env.js'; -import { rscPrivatePlugin } from '../plugins/vite-plugin-rsc-private.js'; -import type { BaseReq, BaseRes, Handler } from './types.js'; -import { mergeUserViteConfig } from '../utils/merge-vite-config.js'; - -export const CLIENT_MODULE_MAP = { - react: 'react', - 'rd-server': 'react-dom/server.edge', - 'rsdw-client': 'react-server-dom-webpack/client.edge', - 'waku-client': 'waku/client', -}; -export type CLIENT_MODULE_KEY = keyof typeof CLIENT_MODULE_MAP; - -export function createHandler< - Req extends BaseReq, - Res extends BaseRes, ->(options: { - config?: Config; - ssr?: boolean; - env?: Record; - unstable_prehook?: (req: Req, res: Res) => Record; - unstable_posthook?: ( - req: Req, - res: Res, - context: Record, - ) => void; -}): Handler { - const { ssr, unstable_prehook, unstable_posthook } = options; - if (!unstable_prehook && unstable_posthook) { - throw new Error('prehook is required if posthook is provided'); - } - (globalThis as any).__WAKU_PRIVATE_ENV__ = options.env || {}; - const configPromise = resolveConfig(options.config || {}); - const vitePromise = configPromise.then(async (config) => { - const mergedViteConfig = await mergeUserViteConfig({ - base: config.basePath, - plugins: [ - patchReactRefresh(viteReact()), - rscEnvPlugin({ config }), - rscPrivatePlugin(config), - rscIndexPlugin(config), - rscHmrPlugin(), - { name: 'nonjs-resolve-plugin' }, // dummy to match with dev-worker-impl.ts - { name: 'rsc-transform-plugin' }, // dummy to match with dev-worker-impl.ts - { name: 'rsc-delegate-plugin' }, // dummy to match with dev-worker-impl.ts - ], - optimizeDeps: { - include: ['react-server-dom-webpack/client', 'react-dom'], - exclude: ['waku'], - entries: [ - `${config.srcDir}/${config.entriesJs}`.replace(/\.js$/, '.*'), - ], - }, - ssr: { - external: [ - 'waku', - 'waku/client', - 'waku/server', - 'waku/router/client', - 'waku/router/server', - ], - }, - server: { middlewareMode: true }, - }); - const vite = await createViteServer(mergedViteConfig); - initializeWorker(config); - registerHotUpdateCallback((payload) => hotUpdate(vite, payload)); - return vite; - }); - - const loadServerFile = async (fileURL: string) => { - const vite = await vitePromise; - return vite.ssrLoadModule(fileURLToFilePath(fileURL)); - }; - - const transformIndexHtml = async (pathname: string) => { - const vite = await vitePromise; - const encoder = new TextEncoder(); - const decoder = new TextDecoder(); - let headSent = false; - return new TransformStream({ - transform(chunk, controller) { - if (!(chunk instanceof Uint8Array)) { - throw new Error('Unknown chunk type'); - } - if (!headSent) { - headSent = true; - let data = decoder.decode(chunk); - // FIXME without removing async, Vite will move it - // to the proxy cache, which breaks __WAKU_PUSH__. - data = data.replace(/