@rshono/core 1.0.0-rc.1 → 1.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -159
- package/dist/builder/page-files.d.ts.map +1 -1
- package/dist/builder/page-files.js +7 -3
- package/dist/builder/page-files.js.map +1 -1
- package/dist/builder/public-env.d.ts +6 -0
- package/dist/builder/public-env.d.ts.map +1 -1
- package/dist/builder/public-env.js +6 -0
- package/dist/builder/public-env.js.map +1 -1
- package/dist/builder/rspack-config.d.ts +3 -3
- package/dist/builder/rspack-config.d.ts.map +1 -1
- package/dist/builder/rspack-config.js +18 -21
- package/dist/builder/rspack-config.js.map +1 -1
- package/dist/cli/build.d.ts +2 -2
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/dev.d.ts +2 -2
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dev.js +63 -35
- package/dist/cli/dev.js.map +1 -1
- package/dist/cli/index.js +10 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/config.d.ts +58 -70
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -1
- package/dist/config.js.map +1 -1
- package/dist/deploy/cloudflare/build.js +1 -1
- package/dist/deploy/cloudflare/build.js.map +1 -1
- package/dist/deploy/cloudflare/runtime.d.ts.map +1 -1
- package/dist/deploy/cloudflare/runtime.js +7 -37
- package/dist/deploy/cloudflare/runtime.js.map +1 -1
- package/dist/deploy/contract.d.ts +22 -16
- package/dist/deploy/contract.d.ts.map +1 -1
- package/dist/deploy/contract.js.map +1 -1
- package/dist/deploy/filesystem.d.ts +1 -1
- package/dist/deploy/filesystem.d.ts.map +1 -1
- package/dist/deploy/filesystem.js +7 -10
- package/dist/deploy/filesystem.js.map +1 -1
- package/dist/deploy/node/runtime.d.ts +4 -0
- package/dist/deploy/node/runtime.d.ts.map +1 -1
- package/dist/deploy/node/runtime.js +24 -3
- package/dist/deploy/node/runtime.js.map +1 -1
- package/dist/deploy/presets.d.ts +3 -3
- package/dist/deploy/presets.d.ts.map +1 -1
- package/dist/deploy/presets.js +13 -30
- package/dist/deploy/presets.js.map +1 -1
- package/dist/deploy/vercel/runtime.d.ts.map +1 -1
- package/dist/deploy/vercel/runtime.js +0 -3
- package/dist/deploy/vercel/runtime.js.map +1 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts +85 -48
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +4 -6
- package/dist/router.js.map +1 -1
- package/dist/runtime/boundaries.d.ts +39 -25
- package/dist/runtime/boundaries.d.ts.map +1 -1
- package/dist/runtime/boundaries.js +22 -17
- package/dist/runtime/boundaries.js.map +1 -1
- package/dist/runtime/client.d.ts +9 -8
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +9 -8
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/context.d.ts +216 -70
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +299 -93
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/control.d.ts.map +1 -1
- package/dist/runtime/control.js +7 -0
- package/dist/runtime/control.js.map +1 -1
- package/dist/runtime/dev-protocol.d.ts.map +1 -1
- package/dist/runtime/dev-protocol.js.map +1 -1
- package/dist/runtime/entry.client.d.ts +4 -0
- package/dist/runtime/entry.client.d.ts.map +1 -1
- package/dist/runtime/entry.client.js +190 -154
- package/dist/runtime/entry.client.js.map +1 -1
- package/dist/runtime/entry.rsc.d.ts.map +1 -1
- package/dist/runtime/entry.rsc.js +145 -159
- package/dist/runtime/entry.rsc.js.map +1 -1
- package/dist/runtime/entry.ssr.d.ts +9 -1
- package/dist/runtime/entry.ssr.d.ts.map +1 -1
- package/dist/runtime/entry.ssr.js +36 -18
- package/dist/runtime/entry.ssr.js.map +1 -1
- package/dist/runtime/flight-inject.d.ts +31 -0
- package/dist/runtime/flight-inject.d.ts.map +1 -0
- package/dist/runtime/flight-inject.js +221 -0
- package/dist/runtime/flight-inject.js.map +1 -0
- package/dist/runtime/navigation.d.ts +20 -38
- package/dist/runtime/navigation.d.ts.map +1 -1
- package/dist/runtime/navigation.js +10 -53
- package/dist/runtime/navigation.js.map +1 -1
- package/dist/runtime/request.d.ts +6 -0
- package/dist/runtime/request.d.ts.map +1 -1
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/request.js.map +1 -1
- package/dist/runtime/server.d.ts +7 -12
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/runtime/server.js +15 -12
- package/dist/runtime/server.js.map +1 -1
- package/dist/server/headers.d.ts +9 -9
- package/dist/server/headers.js +9 -9
- package/dist/server/headers.js.map +1 -1
- package/dist/server/load-config.d.ts +2 -2
- package/dist/server/load-config.d.ts.map +1 -1
- package/dist/server/load-config.js +22 -11
- package/dist/server/load-config.js.map +1 -1
- package/dist/server/prerendered.d.ts +43 -15
- package/dist/server/prerendered.d.ts.map +1 -1
- package/dist/server/prerendered.js +47 -0
- package/dist/server/prerendered.js.map +1 -1
- package/dist/server/server-config.d.ts +13 -39
- package/dist/server/server-config.d.ts.map +1 -1
- package/dist/server/server-config.js +5 -74
- package/dist/server/server-config.js.map +1 -1
- package/dist/server/ssg.d.ts +2 -2
- package/dist/server/ssg.d.ts.map +1 -1
- package/dist/server/ssg.js +21 -34
- package/dist/server/ssg.js.map +1 -1
- package/package.json +13 -16
- package/dist/deploy/bun/runtime.d.ts +0 -11
- package/dist/deploy/bun/runtime.d.ts.map +0 -1
- package/dist/deploy/bun/runtime.js +0 -22
- package/dist/deploy/bun/runtime.js.map +0 -1
- package/dist/deploy/deno/runtime.d.ts +0 -11
- package/dist/deploy/deno/runtime.d.ts.map +0 -1
- package/dist/deploy/deno/runtime.js +0 -16
- package/dist/deploy/deno/runtime.js.map +0 -1
- package/dist/deploy/listen.d.ts +0 -20
- package/dist/deploy/listen.d.ts.map +0 -1
- package/dist/deploy/listen.js +0 -24
- package/dist/deploy/listen.js.map +0 -1
- package/dist/deploy/netlify/build.d.ts +0 -8
- package/dist/deploy/netlify/build.d.ts.map +0 -1
- package/dist/deploy/netlify/build.js +0 -52
- package/dist/deploy/netlify/build.js.map +0 -1
- package/dist/deploy/netlify/runtime.d.ts +0 -13
- package/dist/deploy/netlify/runtime.d.ts.map +0 -1
- package/dist/deploy/netlify/runtime.js +0 -24
- package/dist/deploy/netlify/runtime.js.map +0 -1
- package/dist/server/compress.d.ts +0 -15
- package/dist/server/compress.d.ts.map +0 -1
- package/dist/server/compress.js +0 -76
- package/dist/server/compress.js.map +0 -1
|
@@ -2,6 +2,10 @@ import type { DeployRuntime } from '../contract.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Node: a long-lived process that owns its own port, with a filesystem behind every asset. The shape
|
|
4
4
|
* the framework was built against, and the only target `rshono dev` ever produces.
|
|
5
|
+
*
|
|
6
|
+
* Anything that runs a Node process runs this build — a VPS, a container, a PaaS — and Bun and Deno
|
|
7
|
+
* are expected to as well, since the listener below is `@hono/node-server` and both implement the
|
|
8
|
+
* `node:` APIs it needs.
|
|
5
9
|
*/
|
|
6
10
|
export declare const runtime: DeployRuntime;
|
|
7
11
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/deploy/node/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/deploy/node/runtime.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAqBpD;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,EAAE,aA4BrB,CAAC"}
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
import { serve } from '@hono/node-server';
|
|
2
2
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
3
|
+
import { SERVER_DEFAULTS } from '../../server/server-config.js';
|
|
3
4
|
import { onShutdown } from '../../server/shutdown.js';
|
|
4
5
|
import { fileSystemRuntime } from '../filesystem.js';
|
|
5
|
-
|
|
6
|
+
/** Bound to every interface — so the address printed on start is `localhost`, not this. */
|
|
7
|
+
const WILDCARD_HOST = '0.0.0.0';
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the address to listen on: an explicit override (the dev server, which picks the port for its
|
|
10
|
+
* worker) beats the environment, which beats the built-in default.
|
|
11
|
+
*
|
|
12
|
+
* `PORT` and `HOST` are the whole interface, because that is the deployment convention everywhere
|
|
13
|
+
* this runs. `??` rather than `||` so an explicit `PORT=0`, meaning "any free port", is honoured.
|
|
14
|
+
*/
|
|
15
|
+
function listenAddress(overrides) {
|
|
16
|
+
const envPort = process.env.PORT !== undefined ? Number(process.env.PORT) : undefined;
|
|
17
|
+
return {
|
|
18
|
+
port: overrides?.port ?? envPort ?? SERVER_DEFAULTS.port,
|
|
19
|
+
hostname: overrides?.hostname ?? process.env.HOST ?? SERVER_DEFAULTS.host,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
6
22
|
/**
|
|
7
23
|
* Node: a long-lived process that owns its own port, with a filesystem behind every asset. The shape
|
|
8
24
|
* the framework was built against, and the only target `rshono dev` ever produces.
|
|
25
|
+
*
|
|
26
|
+
* Anything that runs a Node process runs this build — a VPS, a container, a PaaS — and Bun and Deno
|
|
27
|
+
* are expected to as well, since the listener below is `@hono/node-server` and both implement the
|
|
28
|
+
* `node:` APIs it needs.
|
|
9
29
|
*/
|
|
10
30
|
export const runtime = {
|
|
11
31
|
...fileSystemRuntime,
|
|
@@ -16,7 +36,7 @@ export const runtime = {
|
|
|
16
36
|
if (process.env.RSHONO_PRERENDER)
|
|
17
37
|
return;
|
|
18
38
|
// The dev server runs this bundle in a worker thread and picks the port itself, so its choice wins
|
|
19
|
-
// over
|
|
39
|
+
// over the environment.
|
|
20
40
|
const devWorker = workerData;
|
|
21
41
|
const address = listenAddress(devWorker ?? undefined);
|
|
22
42
|
const server = serve({ fetch: app.fetch, ...address }, (info) => {
|
|
@@ -24,7 +44,8 @@ export const runtime = {
|
|
|
24
44
|
parentPort.postMessage({ type: 'ready', port: info.port });
|
|
25
45
|
}
|
|
26
46
|
else {
|
|
27
|
-
|
|
47
|
+
const host = address.hostname === WILDCARD_HOST ? 'localhost' : address.hostname;
|
|
48
|
+
console.log(` ➜ rshono serving on http://${host}:${info.port}`);
|
|
28
49
|
}
|
|
29
50
|
});
|
|
30
51
|
onShutdown(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/deploy/node/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/deploy/node/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,2FAA2F;AAC3F,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,SAAgD;IACrE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,S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,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import { serve } from '@hono/node-server';\nimport type { Hono } from 'hono';\nimport { parentPort, workerData } from 'node:worker_threads';\nimport { SERVER_DEFAULTS } from '../../server/server-config.js';\nimport { onShutdown } from '../../server/shutdown.js';\nimport type { DeployRuntime } from '../contract.js';\nimport { fileSystemRuntime } from '../filesystem.js';\n\n/** Bound to every interface — so the address printed on start is `localhost`, not this. */\nconst WILDCARD_HOST = '0.0.0.0';\n\n/**\n * Resolves the address to listen on: an explicit override (the dev server, which picks the port for its\n * worker) beats the environment, which beats the built-in default.\n *\n * `PORT` and `HOST` are the whole interface, because that is the deployment convention everywhere\n * this runs. `??` rather than `||` so an explicit `PORT=0`, meaning \"any free port\", is honoured.\n */\nfunction listenAddress(overrides?: { port?: number; hostname?: string }): { port: number; hostname: string } {\n const envPort = process.env.PORT !== undefined ? Number(process.env.PORT) : undefined;\n return {\n port: overrides?.port ?? envPort ?? SERVER_DEFAULTS.port,\n hostname: overrides?.hostname ?? process.env.HOST ?? SERVER_DEFAULTS.host,\n };\n}\n\n/**\n * Node: a long-lived process that owns its own port, with a filesystem behind every asset. The shape\n * the framework was built against, and the only target `rshono dev` ever produces.\n *\n * Anything that runs a Node process runs this build — a VPS, a container, a PaaS — and Bun and Deno\n * are expected to as well, since the listener below is `@hono/node-server` and both implement the\n * `node:` APIs it needs.\n */\nexport const runtime: DeployRuntime = {\n ...fileSystemRuntime,\n\n serveApp(app: Hono): undefined {\n // `rshono build` imports this bundle to prerender `render: 'static'` routes. That pass renders\n // through `app.fetch` directly and must not bind a port — nothing is listening for it, and the\n // build would never exit.\n if (process.env.RSHONO_PRERENDER) return;\n\n // The dev server runs this bundle in a worker thread and picks the port itself, so its choice wins\n // over the environment.\n const devWorker = workerData as { port?: number; hostname?: string } | null;\n const address = listenAddress(devWorker ?? undefined);\n\n const server = serve({ fetch: app.fetch, ...address }, (info) => {\n if (parentPort) {\n parentPort.postMessage({ type: 'ready', port: info.port });\n } else {\n const host = address.hostname === WILDCARD_HOST ? 'localhost' : address.hostname;\n console.log(` ➜ rshono serving on http://${host}:${info.port}`);\n }\n });\n\n onShutdown(() => {\n server.close(() => process.exit(0));\n setTimeout(() => process.exit(0), 3000).unref();\n });\n },\n};\n"]}
|
package/dist/deploy/presets.d.ts
CHANGED
|
@@ -57,8 +57,8 @@ export interface DeployPreset {
|
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Node: a long-lived server process. The generated config is already this shape, so the preset has
|
|
60
|
-
* nothing to contribute — the
|
|
61
|
-
*
|
|
60
|
+
* nothing to contribute — the settings in `builder/rspack-config.ts` (`target: 'node'`, the externals
|
|
61
|
+
* policy, ESM chunk output) are the Node ones by default.
|
|
62
62
|
*/
|
|
63
63
|
export declare const NODE_PRESET: DeployPreset;
|
|
64
64
|
/** Every target `deploy` accepts, for error messages and docs. */
|
|
@@ -74,7 +74,7 @@ export interface DeploySources {
|
|
|
74
74
|
flag?: string;
|
|
75
75
|
/** The `RSHONO_DEPLOY` env var — for a CI job that deploys the same app to more than one place. */
|
|
76
76
|
env?: string;
|
|
77
|
-
/** {@link
|
|
77
|
+
/** {@link RshonoConfig.deploy} from `rshono.config.ts`. */
|
|
78
78
|
config?: string;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/deploy/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/deploy/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EA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;IACd,mGAAmG;IACnG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,aAAkB,GAAG,YAAY,CAS7E"}
|
package/dist/deploy/presets.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { finalizeCloudflareBuild } from './cloudflare/build.js';
|
|
2
|
-
import { finalizeNetlifyBuild } from './netlify/build.js';
|
|
3
2
|
import { finalizeVercelBuild } from './vercel/build.js';
|
|
4
3
|
/**
|
|
5
4
|
* Node: a long-lived server process. The generated config is already this shape, so the preset has
|
|
6
|
-
* nothing to contribute — the
|
|
7
|
-
*
|
|
5
|
+
* nothing to contribute — the settings in `builder/rspack-config.ts` (`target: 'node'`, the externals
|
|
6
|
+
* policy, ESM chunk output) are the Node ones by default.
|
|
8
7
|
*/
|
|
9
8
|
export const NODE_PRESET = {
|
|
10
9
|
name: 'node',
|
|
@@ -36,23 +35,11 @@ const CLOUDFLARE_PRESET = {
|
|
|
36
35
|
finalize: finalizeCloudflareBuild,
|
|
37
36
|
};
|
|
38
37
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
name: 'bun',
|
|
45
|
-
runtimeModule: 'deploy/bun/runtime.js',
|
|
46
|
-
deployHint: 'run `bun dist/server/main.mjs`',
|
|
47
|
-
};
|
|
48
|
-
const DENO_PRESET = {
|
|
49
|
-
name: 'deno',
|
|
50
|
-
runtimeModule: 'deploy/deno/runtime.js',
|
|
51
|
-
deployHint: 'run `deno serve -A dist/server/main.mjs`',
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Vercel and Netlify: one Node function behind the platform's CDN, which serves the assets and reaches
|
|
55
|
-
* the function only for a page. Both `finalize` hooks assemble the layout the platform uploads.
|
|
38
|
+
* Vercel: one Node function behind the platform's CDN, which serves the assets and reaches the function
|
|
39
|
+
* only for a page. `finalize` assembles the Build Output API layout the platform uploads — including the
|
|
40
|
+
* `supportsResponseStreaming` flag, without which Vercel buffers the whole response and streamed SSR is
|
|
41
|
+
* silently undone. That flag, and the exact path the bundle has to keep, are the reason this is a preset
|
|
42
|
+
* rather than a snippet in the docs.
|
|
56
43
|
*/
|
|
57
44
|
const VERCEL_PRESET = {
|
|
58
45
|
name: 'vercel',
|
|
@@ -60,13 +47,12 @@ const VERCEL_PRESET = {
|
|
|
60
47
|
deployHint: 'deploy with `vercel deploy --prebuilt`',
|
|
61
48
|
finalize: finalizeVercelBuild,
|
|
62
49
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/** AWS Lambda behind a Function URL in `RESPONSE_STREAM` mode — the AWS shape that keeps streaming. */
|
|
50
|
+
/**
|
|
51
|
+
* AWS Lambda behind a Function URL in `RESPONSE_STREAM` mode — the AWS shape that keeps streaming.
|
|
52
|
+
*
|
|
53
|
+
* Same reasoning as Vercel: the runtime wraps the app in `awslambda.streamifyResponse`, and the buffered
|
|
54
|
+
* alternative would deploy fine and then hold every page until its last byte rendered.
|
|
55
|
+
*/
|
|
70
56
|
const AWS_LAMBDA_PRESET = {
|
|
71
57
|
name: 'aws-lambda',
|
|
72
58
|
runtimeModule: 'deploy/aws-lambda/runtime.js',
|
|
@@ -75,10 +61,7 @@ const AWS_LAMBDA_PRESET = {
|
|
|
75
61
|
const PRESETS = {
|
|
76
62
|
node: NODE_PRESET,
|
|
77
63
|
cloudflare: CLOUDFLARE_PRESET,
|
|
78
|
-
bun: BUN_PRESET,
|
|
79
|
-
deno: DENO_PRESET,
|
|
80
64
|
vercel: VERCEL_PRESET,
|
|
81
|
-
netlify: NETLIFY_PRESET,
|
|
82
65
|
'aws-lambda': AWS_LAMBDA_PRESET,
|
|
83
66
|
};
|
|
84
67
|
/** Every target `deploy` accepts, for error messages and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,MAAM,CAAC,uBAAuB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/H,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { RspackOptions } from '@rspack/core';\nimport { finalizeCloudflareBuild } from './cloudflare/build.js';\nimport type { DeployTarget } from './contract.js';\nimport { finalizeNetlifyBuild } from './netlify/build.js';\nimport { finalizeVercelBuild } from './vercel/build.js';\n\n/** What a preset's {@link DeployPreset.finalize} is told about the build it is arranging. */\nexport interface DeployBuildContext {\n /** The project root — where `rshono build` ran, and what a platform config file is written next to. */\n rootDir: string;\n /** `<root>/dist`. */\n distDir: string;\n /** The hashed client bundle, `<root>/dist/static` — served at `/_static`. */\n staticDir: string;\n /** The copy of the app's `public/`, or `null` when it has none. Served at the web root. */\n publicDir: string | null;\n /** Prerendered pages, `<root>/dist/ssg` — empty when the app has no `render: 'static'` routes. */\n ssgDir: string;\n}\n\n/**\n * The build-time half of a deploy target: which runtime module the bundle gets, how the server\n * compiler has to change to produce something the platform can run, and how the output is arranged\n * once it exists.\n *\n * The runtime half is {@link DeployRuntime}, in its own file because it is compiled *into* the app\n * bundle — this side only ever runs in the CLI.\n */\nexport interface DeployPreset {\n readonly name: DeployTarget;\n /**\n * The module `@rshono/deploy` resolves to, as a path relative to the framework's own `dist/`.\n * Slash-separated and split on use, so it stays a valid path on Windows too.\n */\n readonly runtimeModule: string;\n /** How to run what was just built, completing the \"build complete —\" line. */\n readonly deployHint: string;\n /**\n * Extra resolve conditions for the server bundle, most specific first.\n *\n * This is what picks the right build of React and the RSC runtime: both ship one per runtime behind\n * `workerd` / `deno` / `edge-light` / `node` conditions. Omit it to accept whatever the Rspack\n * target implies, which is correct for Node.\n */\n readonly resolveConditions?: readonly string[];\n /** browserslist-style targets for the server bundle's swc pass. Defaults to Node. */\n readonly syntaxTargets?: readonly string[];\n /**\n * Adjusts the generated server Rspack config for this platform — target, externals policy, output\n * shape. Mutates in place, and runs *before* the user's `rspack` hook so that hook keeps the last\n * word.\n */\n configureServer?(config: RspackOptions): void;\n /**\n * Arranges the finished build for the platform: assembles whatever directory layout it expects,\n * emits its config file, and prints how to deploy.\n *\n * Runs last — after both bundles, the `public/` copy and the prerender pass — so everything it\n * needs to move is already on disk.\n */\n finalize?(ctx: DeployBuildContext): Promise<void> | void;\n}\n\n/**\n * Node: a long-lived server process. The generated config is already this shape, so the preset has\n * nothing to contribute — the platform-specific settings still living in `builder/rspack-config.ts`\n * (`target: 'node'`, the externals policy, ESM chunk output) are the Node ones by default.\n */\nexport const NODE_PRESET: DeployPreset = {\n name: 'node',\n runtimeModule: 'deploy/node/runtime.js',\n deployHint: 'run `rshono start`',\n};\n\n/**\n * Cloudflare Workers: the host owns the process, the CDN owns the assets, and there is no filesystem.\n *\n * Every compiler setting here follows from `workerd` not being Node. Dependencies are bundled because\n * nothing resolves `node_modules` at runtime; `node:` and `cloudflare:` imports stay external because\n * the runtime provides them (`nodejs_compat`, which the scaffolded config enables for\n * `AsyncLocalStorage`); and async chunks are inlined because Wrangler's bundler cannot follow the\n * computed specifier Rspack's ESM chunk loader emits — a split bundle would deploy and then fail on\n * the first page render.\n */\nconst CLOUDFLARE_PRESET: DeployPreset = {\n name: 'cloudflare',\n runtimeModule: 'deploy/cloudflare/runtime.js',\n deployHint: 'deploy with `wrangler deploy`',\n resolveConditions: ['workerd'],\n syntaxTargets: ['chrome 120'],\n configureServer(config) {\n config.target = 'webworker';\n config.externalsType = 'module-import';\n config.externals = [/^(?:node|cloudflare):/];\n config.output = { ...config.output, asyncChunks: false };\n },\n finalize: finalizeCloudflareBuild,\n};\n\n/**\n * Bun and Deno: like Node, but the runtime opens the socket from the module's default export. Their\n * `node:` compatibility covers everything `server/` uses, so the bundle is Node's — only the handoff\n * differs, which is precisely the thing an app cannot do for itself.\n */\nconst BUN_PRESET: DeployPreset = {\n name: 'bun',\n runtimeModule: 'deploy/bun/runtime.js',\n deployHint: 'run `bun dist/server/main.mjs`',\n};\n\nconst DENO_PRESET: DeployPreset = {\n name: 'deno',\n runtimeModule: 'deploy/deno/runtime.js',\n deployHint: 'run `deno serve -A dist/server/main.mjs`',\n};\n\n/**\n * Vercel and Netlify: one Node function behind the platform's CDN, which serves the assets and reaches\n * the function only for a page. Both `finalize` hooks assemble the layout the platform uploads.\n */\nconst VERCEL_PRESET: DeployPreset = {\n name: 'vercel',\n runtimeModule: 'deploy/vercel/runtime.js',\n deployHint: 'deploy with `vercel deploy --prebuilt`',\n finalize: finalizeVercelBuild,\n};\n\nconst NETLIFY_PRESET: DeployPreset = {\n name: 'netlify',\n runtimeModule: 'deploy/netlify/runtime.js',\n deployHint: 'deploy with `netlify deploy --build=false --dir=.netlify/publish`',\n finalize: finalizeNetlifyBuild,\n};\n\n/** AWS Lambda behind a Function URL in `RESPONSE_STREAM` mode — the AWS shape that keeps streaming. */\nconst AWS_LAMBDA_PRESET: DeployPreset = {\n name: 'aws-lambda',\n runtimeModule: 'deploy/aws-lambda/runtime.js',\n deployHint: 'zip dist/ with the handler at dist/server/main.mjs',\n};\n\nconst PRESETS: Record<DeployTarget, DeployPreset> = {\n node: NODE_PRESET,\n cloudflare: CLOUDFLARE_PRESET,\n bun: BUN_PRESET,\n deno: DENO_PRESET,\n vercel: VERCEL_PRESET,\n netlify: NETLIFY_PRESET,\n 'aws-lambda': AWS_LAMBDA_PRESET,\n};\n\n/** Every target `deploy` accepts, for error messages and docs. */\nexport const DEPLOY_TARGETS = Object.keys(PRESETS) as DeployTarget[];\n\n/**\n * How to deploy what a given target built, or `null` for a name this rshono does not know — which a\n * `dist/` produced by a newer version can legitimately carry.\n */\nexport function deployHintFor(target: string): string | null {\n return (PRESETS as Record<string, DeployPreset | undefined>)[target]?.deployHint ?? null;\n}\n\n/** Where a deploy target can be named, in precedence order. */\nexport interface DeploySources {\n /** The `--deploy` flag. */\n flag?: string;\n /** The `RSHONO_DEPLOY` env var — for a CI job that deploys the same app to more than one place. */\n env?: string;\n /** {@link RSHonoConfig.deploy} from `rshono.config.ts`. */\n config?: string;\n}\n\n/**\n * Resolves the preset to build with: the flag wins over the environment, which wins over the config\n * file, which wins over the `node` default.\n *\n * Blank values are ignored at every level, so an unset-but-present `RSHONO_DEPLOY=` in a CI\n * environment falls through to the config file instead of failing the build.\n */\nexport function resolveDeployPreset(sources: DeploySources = {}): DeployPreset {\n const target = sources.flag?.trim() || sources.env?.trim() || sources.config?.trim();\n if (!target) return NODE_PRESET;\n\n const preset = (PRESETS as Record<string, DeployPreset | undefined>)[target];\n if (!preset) {\n throw new Error(`[rshono] unknown deploy target ${JSON.stringify(target)} — expected one of: ${DEPLOY_TARGETS.join(', ')}.`);\n }\n return preset;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../../src/deploy/presets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA2DxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAiB;IACvC,IAAI,EAAE,MAAM;IACZ,aAAa,EAAE,wBAAwB;IACvC,UAAU,EAAE,oBAAoB;CACjC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,iBAAiB,GAAiB;IACtC,IAAI,EAAE,YAAY;IAClB,aAAa,EAAE,8BAA8B;IAC7C,UAAU,EAAE,+BAA+B;IAC3C,iBAAiB,EAAE,CAAC,SAAS,CAAC;IAC9B,aAAa,EAAE,CAAC,YAAY,CAAC;IAC7B,eAAe,CAAC,MAAM;QACpB,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC;QAC5B,MAAM,CAAC,aAAa,GAAG,eAAe,CAAC;QACvC,MAAM,CAAC,SAAS,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IAC3D,C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CAAC;AAChB,CAAC","sourcesContent":["import type { RspackOptions } from '@rspack/core';\nimport { finalizeCloudflareBuild } from './cloudflare/build.js';\nimport type { DeployTarget } from './contract.js';\nimport { finalizeVercelBuild } from './vercel/build.js';\n\n/** What a preset's {@link DeployPreset.finalize} is told about the build it is arranging. */\nexport interface DeployBuildContext {\n /** The project root — where `rshono build` ran, and what a platform config file is written next to. */\n rootDir: string;\n /** `<root>/dist`. */\n distDir: string;\n /** The hashed client bundle, `<root>/dist/static` — served at `/_static`. */\n staticDir: string;\n /** The copy of the app's `public/`, or `null` when it has none. Served at the web root. */\n publicDir: string | null;\n /** Prerendered pages, `<root>/dist/ssg` — empty when the app has no `render: 'static'` routes. */\n ssgDir: string;\n}\n\n/**\n * The build-time half of a deploy target: which runtime module the bundle gets, how the server\n * compiler has to change to produce something the platform can run, and how the output is arranged\n * once it exists.\n *\n * The runtime half is {@link DeployRuntime}, in its own file because it is compiled *into* the app\n * bundle — this side only ever runs in the CLI.\n */\nexport interface DeployPreset {\n readonly name: DeployTarget;\n /**\n * The module `@rshono/deploy` resolves to, as a path relative to the framework's own `dist/`.\n * Slash-separated and split on use, so it stays a valid path on Windows too.\n */\n readonly runtimeModule: string;\n /** How to run what was just built, completing the \"build complete —\" line. */\n readonly deployHint: string;\n /**\n * Extra resolve conditions for the server bundle, most specific first.\n *\n * This is what picks the right build of React and the RSC runtime: both ship one per runtime behind\n * `workerd` / `deno` / `edge-light` / `node` conditions. Omit it to accept whatever the Rspack\n * target implies, which is correct for Node.\n */\n readonly resolveConditions?: readonly string[];\n /** browserslist-style targets for the server bundle's swc pass. Defaults to Node. */\n readonly syntaxTargets?: readonly string[];\n /**\n * Adjusts the generated server Rspack config for this platform — target, externals policy, output\n * shape. Mutates in place, and runs *before* the user's `rspack` hook so that hook keeps the last\n * word.\n */\n configureServer?(config: RspackOptions): void;\n /**\n * Arranges the finished build for the platform: assembles whatever directory layout it expects,\n * emits its config file, and prints how to deploy.\n *\n * Runs last — after both bundles, the `public/` copy and the prerender pass — so everything it\n * needs to move is already on disk.\n */\n finalize?(ctx: DeployBuildContext): Promise<void> | void;\n}\n\n/**\n * Node: a long-lived server process. The generated config is already this shape, so the preset has\n * nothing to contribute — the settings in `builder/rspack-config.ts` (`target: 'node'`, the externals\n * policy, ESM chunk output) are the Node ones by default.\n */\nexport const NODE_PRESET: DeployPreset = {\n name: 'node',\n runtimeModule: 'deploy/node/runtime.js',\n deployHint: 'run `rshono start`',\n};\n\n/**\n * Cloudflare Workers: the host owns the process, the CDN owns the assets, and there is no filesystem.\n *\n * Every compiler setting here follows from `workerd` not being Node. Dependencies are bundled because\n * nothing resolves `node_modules` at runtime; `node:` and `cloudflare:` imports stay external because\n * the runtime provides them (`nodejs_compat`, which the scaffolded config enables for\n * `AsyncLocalStorage`); and async chunks are inlined because Wrangler's bundler cannot follow the\n * computed specifier Rspack's ESM chunk loader emits — a split bundle would deploy and then fail on\n * the first page render.\n */\nconst CLOUDFLARE_PRESET: DeployPreset = {\n name: 'cloudflare',\n runtimeModule: 'deploy/cloudflare/runtime.js',\n deployHint: 'deploy with `wrangler deploy`',\n resolveConditions: ['workerd'],\n syntaxTargets: ['chrome 120'],\n configureServer(config) {\n config.target = 'webworker';\n config.externalsType = 'module-import';\n config.externals = [/^(?:node|cloudflare):/];\n config.output = { ...config.output, asyncChunks: false };\n },\n finalize: finalizeCloudflareBuild,\n};\n\n/**\n * Vercel: one Node function behind the platform's CDN, which serves the assets and reaches the function\n * only for a page. `finalize` assembles the Build Output API layout the platform uploads — including the\n * `supportsResponseStreaming` flag, without which Vercel buffers the whole response and streamed SSR is\n * silently undone. That flag, and the exact path the bundle has to keep, are the reason this is a preset\n * rather than a snippet in the docs.\n */\nconst VERCEL_PRESET: DeployPreset = {\n name: 'vercel',\n runtimeModule: 'deploy/vercel/runtime.js',\n deployHint: 'deploy with `vercel deploy --prebuilt`',\n finalize: finalizeVercelBuild,\n};\n\n/**\n * AWS Lambda behind a Function URL in `RESPONSE_STREAM` mode — the AWS shape that keeps streaming.\n *\n * Same reasoning as Vercel: the runtime wraps the app in `awslambda.streamifyResponse`, and the buffered\n * alternative would deploy fine and then hold every page until its last byte rendered.\n */\nconst AWS_LAMBDA_PRESET: DeployPreset = {\n name: 'aws-lambda',\n runtimeModule: 'deploy/aws-lambda/runtime.js',\n deployHint: 'zip dist/ with the handler at dist/server/main.mjs',\n};\n\nconst PRESETS: Record<DeployTarget, DeployPreset> = {\n node: NODE_PRESET,\n cloudflare: CLOUDFLARE_PRESET,\n vercel: VERCEL_PRESET,\n 'aws-lambda': AWS_LAMBDA_PRESET,\n};\n\n/** Every target `deploy` accepts, for error messages and docs. */\nexport const DEPLOY_TARGETS = Object.keys(PRESETS) as DeployTarget[];\n\n/**\n * How to deploy what a given target built, or `null` for a name this rshono does not know — which a\n * `dist/` produced by a newer version can legitimately carry.\n */\nexport function deployHintFor(target: string): string | null {\n return (PRESETS as Record<string, DeployPreset | undefined>)[target]?.deployHint ?? null;\n}\n\n/** Where a deploy target can be named, in precedence order. */\nexport interface DeploySources {\n /** The `--deploy` flag. */\n flag?: string;\n /** The `RSHONO_DEPLOY` env var — for a CI job that deploys the same app to more than one place. */\n env?: string;\n /** {@link RshonoConfig.deploy} from `rshono.config.ts`. */\n config?: string;\n}\n\n/**\n * Resolves the preset to build with: the flag wins over the environment, which wins over the config\n * file, which wins over the `node` default.\n *\n * Blank values are ignored at every level, so an unset-but-present `RSHONO_DEPLOY=` in a CI\n * environment falls through to the config file instead of failing the build.\n */\nexport function resolveDeployPreset(sources: DeploySources = {}): DeployPreset {\n const target = sources.flag?.trim() || sources.env?.trim() || sources.config?.trim();\n if (!target) return NODE_PRESET;\n\n const preset = (PRESETS as Record<string, DeployPreset | undefined>)[target];\n if (!preset) {\n throw new Error(`[rshono] unknown deploy target ${JSON.stringify(target)} — expected one of: ${DEPLOY_TARGETS.join(', ')}.`);\n }\n return preset;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/deploy/vercel/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/deploy/vercel/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,EAAE,aAUrB,CAAC"}
|
|
@@ -19,8 +19,5 @@ export const runtime = {
|
|
|
19
19
|
serveApp(app) {
|
|
20
20
|
return handle(app);
|
|
21
21
|
},
|
|
22
|
-
// Vercel compresses at the edge. Its Node runtime does support streaming, so the framework's own
|
|
23
|
-
// streamed SSR still reaches the browser progressively.
|
|
24
|
-
compress: null,
|
|
25
22
|
};
|
|
26
23
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/deploy/vercel/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAkB;IACpC,GAAG,iBAAiB;IAEpB,iBAAiB;QACf,gEAAgE;IAClE,CAAC;IAED,QAAQ,CAAC,GAAS;QAChB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/deploy/vercel/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAkB;IACpC,GAAG,iBAAiB;IAEpB,iBAAiB;QACf,gEAAgE;IAClE,CAAC;IAED,QAAQ,CAAC,GAAS;QAChB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { Hono } from 'hono';\nimport { handle } from 'hono/vercel';\nimport type { DeployRuntime } from '../contract.js';\nimport { fileSystemRuntime } from '../filesystem.js';\n\n/**\n * Vercel, as a single Node function fed by the platform's own router.\n *\n * `/_static` and `public/` are in the static output, and `config.json` puts the filesystem handler\n * ahead of the function — so the CDN answers them and the function is never invoked for an asset,\n * which is why mounting them here would only be dead weight.\n *\n * Prerendered pages are *not* static output: one URL answers with a document or a flight payload\n * depending on `Accept`, and a path-keyed CDN cannot choose. They ship inside the function instead and\n * are read from its read-only disk, exactly as on a server.\n */\nexport const runtime: DeployRuntime = {\n ...fileSystemRuntime,\n\n mountStaticAssets(): void {\n // Served from `.vercel/output/static` before the function runs.\n },\n\n serveApp(app: Hono): unknown {\n return handle(app);\n },\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,19 +5,16 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The two companion entry points are runtime-only:
|
|
7
7
|
* - `@rshono/core/server` — {@link https://hono.dev | Hono} request context inside
|
|
8
|
-
* server components and actions (`
|
|
8
|
+
* server components and actions (`getRequestContext`, `redirect`, `notFound`), plus
|
|
9
9
|
* `onServerError` for reporting the errors the framework catches.
|
|
10
10
|
* - `@rshono/core/client` — hooks and components for `'use client'` modules
|
|
11
|
-
* (`useNavigation`, `
|
|
11
|
+
* (`useNavigation`, `AsyncBoundary`, `CatchBoundary`).
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://www.rshono.com/docs/api | Docs — API reference}
|
|
12
14
|
*
|
|
13
15
|
* @packageDocumentation
|
|
14
16
|
*/
|
|
15
|
-
export { defineRoutes,
|
|
16
|
-
export { defineConfig, type
|
|
17
|
+
export { defineRoutes, type EndpointRoute, type EndpointServerModule, type ErrorPageInfo, type ErrorPageProps, type FallbackPage, type HTTPMethod, type PageComponent, type PageProps, type PageRoute, type PathParams, type Route, type RouteConfig, } from './router.js';
|
|
18
|
+
export { defineConfig, type RshonoConfig, type RspackHookContext } from './config.js';
|
|
17
19
|
export type { DeployTarget } from './deploy/contract.js';
|
|
18
|
-
/**
|
|
19
|
-
* Re-exported from Hono for convenience, so an endpoint module can type its
|
|
20
|
-
* `handler` without depending on `hono` directly.
|
|
21
|
-
*/
|
|
22
|
-
export type { Context, Handler } from 'hono';
|
|
23
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEtF,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,18 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The two companion entry points are runtime-only:
|
|
7
7
|
* - `@rshono/core/server` — {@link https://hono.dev | Hono} request context inside
|
|
8
|
-
* server components and actions (`
|
|
8
|
+
* server components and actions (`getRequestContext`, `redirect`, `notFound`), plus
|
|
9
9
|
* `onServerError` for reporting the errors the framework catches.
|
|
10
10
|
* - `@rshono/core/client` — hooks and components for `'use client'` modules
|
|
11
|
-
* (`useNavigation`, `
|
|
11
|
+
* (`useNavigation`, `AsyncBoundary`, `CatchBoundary`).
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://www.rshono.com/docs/api | Docs — API reference}
|
|
12
14
|
*
|
|
13
15
|
* @packageDocumentation
|
|
14
16
|
*/
|
|
15
|
-
export { defineRoutes,
|
|
17
|
+
export { defineRoutes, } from './router.js';
|
|
16
18
|
export { defineConfig } from './config.js';
|
|
19
|
+
// Hono's `Context` and `Handler` are deliberately not re-exported: `hono` is a peer dependency every
|
|
20
|
+
// app already has, so an endpoint module imports them from there rather than choosing between two
|
|
21
|
+
// spellings of the same type.
|
|
17
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,YAAY,GAab,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAA6C,MAAM,aAAa,CAAC;AAItF,qGAAqG;AACrG,kGAAkG;AAClG,8BAA8B","sourcesContent":["/**\n * `@rshono/core` — the build-time surface: route and config declaration plus the types\n * your pages and endpoints are written against. Everything here is safe to\n * import from server code; none of it pulls in runtime machinery.\n *\n * The two companion entry points are runtime-only:\n * - `@rshono/core/server` — {@link https://hono.dev | Hono} request context inside\n * server components and actions (`getRequestContext`, `redirect`, `notFound`), plus\n * `onServerError` for reporting the errors the framework catches.\n * - `@rshono/core/client` — hooks and components for `'use client'` modules\n * (`useNavigation`, `AsyncBoundary`, `CatchBoundary`).\n *\n * @see {@link https://www.rshono.com/docs/api | Docs — API reference}\n *\n * @packageDocumentation\n */\n\nexport {\n defineRoutes,\n type EndpointRoute,\n type EndpointServerModule,\n type ErrorPageInfo,\n type ErrorPageProps,\n type FallbackPage,\n type HTTPMethod,\n type PageComponent,\n type PageProps,\n type PageRoute,\n type PathParams,\n type Route,\n type RouteConfig,\n} from './router.js';\n\nexport { defineConfig, type RshonoConfig, type RspackHookContext } from './config.js';\n\nexport type { DeployTarget } from './deploy/contract.js';\n\n// Hono's `Context` and `Handler` are deliberately not re-exported: `hono` is a peer dependency every\n// app already has, so an endpoint module imports them from there rather than choosing between two\n// spellings of the same type.\n"]}
|
package/dist/router.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Env, Handler } from 'hono';
|
|
2
2
|
import type { ParamKeys, ParamKeyToRecord } from 'hono/types';
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
|
-
import type {
|
|
4
|
+
import type { RequestContext } from './runtime/context.js';
|
|
5
5
|
type Simplify<T> = {
|
|
6
6
|
[K in keyof T]: T[K];
|
|
7
7
|
} & {};
|
|
@@ -19,6 +19,8 @@ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) exten
|
|
|
19
19
|
* ```ts
|
|
20
20
|
* type P = PathParams<'/users/:id/posts/:postId'>; // { id: string; postId: string }
|
|
21
21
|
* ```
|
|
22
|
+
*
|
|
23
|
+
* @see {@link https://hono.dev/docs/api/routing#path-parameter | Hono — path parameters}
|
|
22
24
|
*/
|
|
23
25
|
export type PathParams<P extends string> = ParamKeys<P> extends never ? Record<string, never> : Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>>>;
|
|
24
26
|
/**
|
|
@@ -34,8 +36,8 @@ export type PathParams<P extends string> = ParamKeys<P> extends never ? Record<s
|
|
|
34
36
|
* the server/client line is a copy-paste.
|
|
35
37
|
*
|
|
36
38
|
* @typeParam Path - The literal path this page is mounted at, e.g. `'/profile/:id'`.
|
|
37
|
-
* @typeParam E - The app's Hono {@link Env}, to type {@link
|
|
38
|
-
* {@link
|
|
39
|
+
* @typeParam E - The app's Hono {@link Env}, to type {@link RequestContext.var} and
|
|
40
|
+
* {@link RequestContext.env} on {@link PageProps.ctx}.
|
|
39
41
|
*
|
|
40
42
|
* @example
|
|
41
43
|
* ```tsx
|
|
@@ -47,6 +49,8 @@ export type PathParams<P extends string> = ParamKeys<P> extends never ? Record<s
|
|
|
47
49
|
* return <Layout>{user.name} — {tab}</Layout>;
|
|
48
50
|
* }
|
|
49
51
|
* ```
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://www.rshono.com/docs/pages#page-props | Docs — page props}
|
|
50
54
|
*/
|
|
51
55
|
export interface PageProps<Path extends string = string, E extends Env = Env> {
|
|
52
56
|
/**
|
|
@@ -55,42 +59,35 @@ export interface PageProps<Path extends string = string, E extends Env = Env> {
|
|
|
55
59
|
* the rest off it.
|
|
56
60
|
*
|
|
57
61
|
* A fresh instance per request that nothing else holds, so mutating it is local
|
|
58
|
-
* to the page
|
|
59
|
-
*
|
|
62
|
+
* to the page. It is not serializable, so a `'use client'` component has to be
|
|
63
|
+
* handed `url.href` rather than `url`.
|
|
60
64
|
*
|
|
61
|
-
* On a
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
65
|
+
* On a `render: 'static'` route this is the build-time URL — rendered once
|
|
66
|
+
* against `siteUrl` with no query string, and that one file answers every
|
|
67
|
+
* request whatever its own query. So `url.searchParams` is always empty there:
|
|
68
|
+
* read the query from `useNavigation().url` in a `'use client'` component
|
|
69
|
+
* instead, or mark the route `render: 'dynamic'`.
|
|
66
70
|
*/
|
|
67
71
|
url: URL;
|
|
68
72
|
/** Matched route params for this request, e.g. `{ id: '42' }` for `/profile/:id`. */
|
|
69
73
|
params: string extends Path ? Record<string, string> : PathParams<Path>;
|
|
70
74
|
/**
|
|
71
|
-
* The request context — the very object `
|
|
75
|
+
* The request context — the very object `getRequestContext()` returns, handed to the
|
|
72
76
|
* page so cookies, headers, env and middleware variables are reachable without
|
|
73
77
|
* an import.
|
|
74
78
|
*
|
|
75
|
-
* Server-only
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* plain objects … can be passed to Client Components"*. Read what you need on
|
|
83
|
-
* the server and pass plain values down.
|
|
84
|
-
* - Spreading the page's props instead (`<Counter {...props} />`) drops `ctx`
|
|
85
|
-
* silently rather than failing, since the spread copies enumerables only.
|
|
86
|
-
* (That spread still fails, mind — on `url`, which is enumerable and just as
|
|
87
|
-
* unserializable. Pass the values you need.)
|
|
88
|
-
* - `Object.keys(props)`, `JSON.stringify(props)` and friends don't see it.
|
|
79
|
+
* Server-only and never serialized: React puts a server component's *output* on
|
|
80
|
+
* the wire, not its props. It is also deliberately **non-enumerable**, so
|
|
81
|
+
* `Object.keys(props)`, `JSON.stringify(props)` and a `{...props}` spread all
|
|
82
|
+
* skip it. Handing it to a `'use client'` component directly
|
|
83
|
+
* (`<Counter ctx={ctx} />`) fails the render — it wraps the live request and
|
|
84
|
+
* response, which do not exist in the browser. Read what you need here and pass
|
|
85
|
+
* plain values down.
|
|
89
86
|
*
|
|
90
87
|
* Reading it on a `render: 'static'` route throws: a prerendered page has no
|
|
91
|
-
* per-request context at build time. Mark the route `render: 'dynamic'
|
|
92
|
-
* the `url` / `params` props
|
|
93
|
-
*
|
|
88
|
+
* per-request context at build time. Mark the route `render: 'dynamic'`, or use
|
|
89
|
+
* the `url` / `params` props — available either way, with the build-time caveat
|
|
90
|
+
* noted on `url`.
|
|
94
91
|
*
|
|
95
92
|
* @example
|
|
96
93
|
* ```tsx
|
|
@@ -101,7 +98,7 @@ export interface PageProps<Path extends string = string, E extends Env = Env> {
|
|
|
101
98
|
* }
|
|
102
99
|
* ```
|
|
103
100
|
*/
|
|
104
|
-
ctx:
|
|
101
|
+
ctx: RequestContext<E>;
|
|
105
102
|
}
|
|
106
103
|
/**
|
|
107
104
|
* A page: a React **server component** that renders the entire document
|
|
@@ -112,6 +109,9 @@ export interface PageProps<Path extends string = string, E extends Env = Env> {
|
|
|
112
109
|
* belong in `'use client'` components the page imports — only those ship JS.
|
|
113
110
|
*
|
|
114
111
|
* @typeParam P - The component's props; for a page these are {@link PageProps}.
|
|
112
|
+
*
|
|
113
|
+
* @see {@link https://react.dev/reference/rsc/server-components | React — Server Components}
|
|
114
|
+
* @see {@link https://www.rshono.com/docs/pages | Docs — pages}
|
|
115
115
|
*/
|
|
116
116
|
export type PageComponent<P = any> = (props: P) => ReactNode | Promise<ReactNode>;
|
|
117
117
|
/**
|
|
@@ -122,13 +122,21 @@ export type PageComponent<P = any> = (props: P) => ReactNode | Promise<ReactNode
|
|
|
122
122
|
* @example
|
|
123
123
|
* ```ts
|
|
124
124
|
* // src/health.ts
|
|
125
|
-
* import type { Handler } from '
|
|
125
|
+
* import type { Handler } from 'hono';
|
|
126
126
|
*
|
|
127
127
|
* export const handler: Handler = (c) => c.json({ ok: true });
|
|
128
128
|
* ```
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://www.rshono.com/docs/routing#endpoint-routes | Docs — endpoint routes}
|
|
129
131
|
*/
|
|
130
132
|
export interface EndpointServerModule {
|
|
131
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* A Hono {@link Handler} handling every request matched by the route. It is passed Hono's
|
|
135
|
+
* `Context`, so the request, response builders (`c.json`, `c.text`, `c.body`) and middleware
|
|
136
|
+
* variables are all reached through it.
|
|
137
|
+
*
|
|
138
|
+
* @see {@link https://hono.dev/docs/api/context | Hono — Context}
|
|
139
|
+
*/
|
|
132
140
|
handler: Handler;
|
|
133
141
|
}
|
|
134
142
|
/**
|
|
@@ -143,7 +151,12 @@ export interface EndpointServerModule {
|
|
|
143
151
|
export interface PageRoute {
|
|
144
152
|
/** Discriminates a page from an endpoint; optional because `'page'` is the default. */
|
|
145
153
|
type?: 'page';
|
|
146
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* Hono-style path pattern, e.g. `/`, `/profile/:id`, `/files/*`. Routes are matched in
|
|
156
|
+
* declaration order.
|
|
157
|
+
*
|
|
158
|
+
* @see {@link https://hono.dev/docs/api/routing | Hono — routing}
|
|
159
|
+
*/
|
|
147
160
|
path: string;
|
|
148
161
|
/**
|
|
149
162
|
* Dynamic import of the page module, whose default export is the
|
|
@@ -156,6 +169,8 @@ export interface PageRoute {
|
|
|
156
169
|
* component up any other way — a variable, a barrel re-export, a computed
|
|
157
170
|
* specifier — add `'use server-entry'` as the first line of the page module
|
|
158
171
|
* yourself; the framework throws a descriptive error when neither happened.
|
|
172
|
+
*
|
|
173
|
+
* @see {@link https://www.rshono.com/docs/pages#the-use-server-entry-directive | Docs — the `'use server-entry'` directive}
|
|
159
174
|
*/
|
|
160
175
|
component: () => Promise<{
|
|
161
176
|
default: PageComponent;
|
|
@@ -180,6 +195,8 @@ export interface PageRoute {
|
|
|
180
195
|
* staticPaths: async () => (await db.docs.all()).map((d) => ({ slug: d.slug })),
|
|
181
196
|
* }
|
|
182
197
|
* ```
|
|
198
|
+
*
|
|
199
|
+
* @see {@link https://www.rshono.com/docs/routing#static-rendering | Docs — static rendering}
|
|
183
200
|
*/
|
|
184
201
|
staticPaths?: () => Array<Record<string, string>> | Promise<Array<Record<string, string>>>;
|
|
185
202
|
}
|
|
@@ -192,11 +209,17 @@ export interface PageRoute {
|
|
|
192
209
|
* ```ts
|
|
193
210
|
* { type: 'endpoint', path: '/api/health', server: () => import('./health') }
|
|
194
211
|
* ```
|
|
212
|
+
*
|
|
213
|
+
* @see {@link https://www.rshono.com/docs/routing#endpoint-routes | Docs — endpoint routes}
|
|
195
214
|
*/
|
|
196
215
|
export interface EndpointRoute {
|
|
197
216
|
/** Marks this route as an endpoint rather than a page. Required. */
|
|
198
217
|
type: 'endpoint';
|
|
199
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Hono-style path pattern, e.g. `/api/health`, `/api/users/:id`.
|
|
220
|
+
*
|
|
221
|
+
* @see {@link https://hono.dev/docs/api/routing | Hono — routing}
|
|
222
|
+
*/
|
|
200
223
|
path: string;
|
|
201
224
|
/** HTTP method to match. Defaults to `'all'` — every method. */
|
|
202
225
|
method?: HTTPMethod;
|
|
@@ -211,12 +234,10 @@ export type Route = PageRoute | EndpointRoute;
|
|
|
211
234
|
* Type guard narrowing a {@link Route} to a {@link PageRoute}. Because `type` is
|
|
212
235
|
* optional on page routes, anything not explicitly `'endpoint'` is a page.
|
|
213
236
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
237
|
+
* Framework internal — not re-exported from `index.ts`. The request renderer and
|
|
238
|
+
* the SSG pass use it to split the route table.
|
|
239
|
+
*
|
|
240
|
+
* @internal
|
|
220
241
|
*/
|
|
221
242
|
export declare function isPageRoute(route: Route): route is PageRoute;
|
|
222
243
|
/**
|
|
@@ -235,7 +256,7 @@ export interface FallbackPage {
|
|
|
235
256
|
* message is a generic `'Internal Server Error'` and there is no `stack`. In dev
|
|
236
257
|
* you get the real message plus the stack.
|
|
237
258
|
*/
|
|
238
|
-
export interface
|
|
259
|
+
export interface ErrorPageInfo {
|
|
239
260
|
/** The thrown error's message in dev; `'Internal Server Error'` in production. */
|
|
240
261
|
message: string;
|
|
241
262
|
/** The stack trace. Present in dev only. */
|
|
@@ -243,7 +264,7 @@ export interface ErrorInfo {
|
|
|
243
264
|
}
|
|
244
265
|
/**
|
|
245
266
|
* Props for the `error` page declared in {@link RouteConfig.error} — the usual
|
|
246
|
-
* {@link PageProps} plus the redaction-aware {@link
|
|
267
|
+
* {@link PageProps} plus the redaction-aware {@link ErrorPageInfo}.
|
|
247
268
|
*
|
|
248
269
|
* @typeParam E - The app's Hono {@link Env}, forwarded to {@link PageProps.ctx}.
|
|
249
270
|
*
|
|
@@ -257,7 +278,8 @@ export interface ErrorInfo {
|
|
|
257
278
|
* ```
|
|
258
279
|
*/
|
|
259
280
|
export type ErrorPageProps<E extends Env = Env> = PageProps<string, E> & {
|
|
260
|
-
error
|
|
281
|
+
/** The error that failed the request, redacted in production — see {@link ErrorPageInfo}. */
|
|
282
|
+
error: ErrorPageInfo;
|
|
261
283
|
};
|
|
262
284
|
/**
|
|
263
285
|
* The object form accepted by {@link defineRoutes}: the route table plus the two
|
|
@@ -265,6 +287,8 @@ export type ErrorPageProps<E extends Env = Env> = PageProps<string, E> & {
|
|
|
265
287
|
*
|
|
266
288
|
* @typeParam TRoutes - Inferred tuple of route literals, which is what makes the
|
|
267
289
|
* per-route `path` → props check possible.
|
|
290
|
+
*
|
|
291
|
+
* @see {@link https://www.rshono.com/docs/routing#notfound-and-error | Docs — notFound and error pages}
|
|
268
292
|
*/
|
|
269
293
|
export interface RouteConfig<TRoutes extends readonly Route[] = readonly Route[]> {
|
|
270
294
|
/** Every page and endpoint in the app, matched in order. */
|
|
@@ -298,8 +322,10 @@ type ValidateRoutes<TRoutes extends readonly Route[]> = {
|
|
|
298
322
|
* PageProps<'/…'>`. Fix it by matching the page's `PageProps<Path>` type
|
|
299
323
|
* argument to the path it's mounted at.
|
|
300
324
|
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
325
|
+
* A bare {@link Route} array is accepted as shorthand — see the second overload.
|
|
326
|
+
*
|
|
327
|
+
* @param config - A {@link RouteConfig}: the `routes` array plus the optional
|
|
328
|
+
* `notFound` and `error` pages.
|
|
303
329
|
* @returns The config, unchanged and fully typed.
|
|
304
330
|
*
|
|
305
331
|
* @example
|
|
@@ -324,14 +350,25 @@ type ValidateRoutes<TRoutes extends readonly Route[]> = {
|
|
|
324
350
|
* });
|
|
325
351
|
* ```
|
|
326
352
|
*
|
|
327
|
-
* @
|
|
328
|
-
* ```ts
|
|
329
|
-
* export const routes = defineRoutes([{ path: '/', component: () => import('./components/home') }]);
|
|
330
|
-
* ```
|
|
353
|
+
* @see {@link https://www.rshono.com/docs/routing | Docs — routing}
|
|
331
354
|
*/
|
|
332
355
|
export declare function defineRoutes<const TRoutes extends readonly Route[]>(config: RouteConfig<TRoutes> & {
|
|
333
356
|
routes: ValidateRoutes<TRoutes>;
|
|
334
357
|
}): RouteConfig<TRoutes>;
|
|
358
|
+
/**
|
|
359
|
+
* Array shorthand for {@link defineRoutes} — equivalent to `defineRoutes({ routes })`, for an app
|
|
360
|
+
* with no `notFound` or `error` page.
|
|
361
|
+
*
|
|
362
|
+
* @param routes - The {@link Route} array; each page is checked against its own `path`.
|
|
363
|
+
* @returns A {@link RouteConfig} wrapping them.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* export const routes = defineRoutes([{ path: '/', component: () => import('./components/home') }]);
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @see {@link https://www.rshono.com/docs/routing | Docs — routing}
|
|
371
|
+
*/
|
|
335
372
|
export declare function defineRoutes<const TRoutes extends readonly Route[]>(routes: TRoutes & ValidateRoutes<TRoutes>): RouteConfig<TRoutes>;
|
|
336
373
|
export {};
|
|
337
374
|
//# sourceMappingURL=router.d.ts.map
|