react-router-hono-server 2.26.0 → 3.0.0-next.0

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/dist/dev.js CHANGED
@@ -1,302 +1,200 @@
1
- // src/dev.ts
2
- import fs from "fs";
3
- import path from "path";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
4
3
  import honoDevServer from "@hono/vite-dev-server";
5
4
  import bunAdapter from "@hono/vite-dev-server/bun";
6
5
  import nodeAdapter from "@hono/vite-dev-server/node";
7
- var REACT_ROUTER_SERVER_BUILD_MODULE_ID = "\0virtual:react-router/server-build";
8
- var VIRTUAL_MODULE_ID = "\0virtual:react-router-hono-server/server";
9
- var REACT_ROUTER_EXPORT = "export { serverManifest as assets, assetsBuildDirectory, basename, entry, future, isSpaMode, prerender, publicPath, routes, ssr, routeDiscovery };";
6
+ //#region src/dev.ts
7
+ const REACT_ROUTER_SERVER_BUILD_MODULE_ID = "\0virtual:react-router/server-build";
8
+ const VIRTUAL_MODULE_ID = "\0virtual:react-router-hono-server/server";
9
+ const REACT_ROUTER_EXPORT = "export { serverManifest as assets, assetsBuildDirectory, basename, entry, future, isSpaMode, prerender, publicPath, routes, ssr, routeDiscovery };";
10
10
  function reactRouterHonoServer(options = {}) {
11
- const runtime = options.runtime || "node";
12
- let pluginConfig;
13
- let devServerPlugin;
14
- return {
15
- name: "react-router-hono-server",
16
- enforce: "post",
17
- resolveId(id) {
18
- if (id === VIRTUAL_MODULE_ID) {
19
- return id;
20
- }
21
- },
22
- load(id) {
23
- if (id === VIRTUAL_MODULE_ID) {
24
- return `
11
+ const runtime = options.runtime || "node";
12
+ let pluginConfig;
13
+ let devServerPlugin;
14
+ return {
15
+ name: "react-router-hono-server",
16
+ enforce: "post",
17
+ resolveId(id) {
18
+ if (id === VIRTUAL_MODULE_ID) return id;
19
+ },
20
+ load(id) {
21
+ if (id === VIRTUAL_MODULE_ID) return `
25
22
  // generated by react-router-hono-server/dev
26
23
  import { createHonoServer } from "react-router-hono-server/${runtime}";
27
24
 
28
25
  export default await createHonoServer();
29
26
  `;
30
- }
31
- },
32
- async config(config, env) {
33
- pluginConfig = resolvePluginConfig(config, options);
34
- if (!pluginConfig) {
35
- return;
36
- }
37
- const isEnvironmentApiEnabled = pluginConfig.future.unstable_viteEnvironmentApi ?? pluginConfig.future.v8_viteEnvironmentApi;
38
- const flagName = pluginConfig.future.unstable_viteEnvironmentApi ? "unstable_viteEnvironmentApi" : "v8_viteEnvironmentApi";
39
- const serverEntryPoint = pluginConfig.serverEntryPoint;
40
- if (isEnvironmentApiEnabled) {
41
- console.warn(`\x1B[33mThe ${flagName} is enabled.
42
- This is experimental and may break your build.\x1B[0m
43
- `);
44
- }
45
- if (env.mode === "development" && runtime === "cloudflare" && !config.plugins?.find((p) => p && "name" in p && p.name === "react-router-cloudflare-vite-dev-proxy")) {
46
- console.warn(
47
- `\x1B[31mMissing cloudflareDevProxy() in your vite.config.ts.
48
- Please add it to your plugins: import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";\x1B[0m
49
- `
50
- );
51
- }
52
- const baseConfig = {
53
- // Define environment variables that are hot-swapped during development and SSR build
54
- define: {
55
- "import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY": JSON.stringify(pluginConfig.buildDirectory),
56
- "import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR": JSON.stringify(pluginConfig.assetsDir),
57
- "import.meta.env.REACT_ROUTER_HONO_SERVER_RUNTIME": JSON.stringify(runtime),
58
- "import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME": JSON.stringify(pluginConfig.basename)
59
- },
60
- ssr: {
61
- target: runtime === "cloudflare" ? "webworker" : void 0,
62
- // Ensure our package is not externalized during SSR build
63
- // This is necessary because we are using a virtual import to load the React Router server entry point
64
- noExternal: ["react-router-hono-server"],
65
- external: ["@hono/node-ws"]
66
- }
67
- };
68
- if (!isEnvironmentApiEnabled && !pluginConfig.isSsrBuild) {
69
- return baseConfig;
70
- }
71
- let reactRouterBuildFile = pluginConfig.serverBuildFile;
72
- if (reactRouterBuildFile === "index.js") {
73
- reactRouterBuildFile = "assets/server-build.js";
74
- }
75
- let alias = {};
76
- if (runtime === "cloudflare") {
77
- const reactVersion = await getReactVersion(pluginConfig);
78
- alias = {
79
- "react-dom/server": reactVersion >= 19 ? "react-dom/server.edge" : "react-dom/server.browser"
80
- };
81
- }
82
- if (runtime === "bun" && isEnvironmentApiEnabled) {
83
- throw new Error(
84
- `The ${flagName} is not supported with the Bun runtime. Please disable it in your react-router.config.ts`
85
- );
86
- }
87
- if (runtime === "bun" && env.command === "build") {
88
- alias = {
89
- "react-dom/server": "react-dom/server.node"
90
- };
91
- }
92
- if (runtime === "deno" && env.command === "build") {
93
- alias = {
94
- "react-dom/server": "react-dom/server.node"
95
- };
96
- }
97
- const ssrConfig = {
98
- resolve: {
99
- alias
100
- },
101
- build: {
102
- rollupOptions: {
103
- input: serverEntryPoint,
104
- output: {
105
- entryFileNames: (chunk) => {
106
- chunk.facadeModuleId = REACT_ROUTER_SERVER_BUILD_MODULE_ID;
107
- return "index.js";
108
- },
109
- // not invoked when target is webworker (single file output)
110
- chunkFileNames: (chunk) => {
111
- if (chunk.name === "server-build") {
112
- return reactRouterBuildFile;
113
- }
114
- return "assets/[name]-[hash].js";
115
- },
116
- manualChunks: runtime !== "cloudflare" ? (id, meta) => {
117
- if (meta.getModuleInfo(id)?.importers.some((id2) => id2.includes(serverEntryPoint))) {
118
- return path.basename(id, path.extname(id));
119
- }
120
- return void 0;
121
- } : void 0,
122
- // We are doing that because we build a single file that only exports the Hono server
123
- // RR needs its exports for prerendering
124
- footer: runtime === "cloudflare" ? REACT_ROUTER_EXPORT : void 0
125
- }
126
- }
127
- }
128
- };
129
- if (isEnvironmentApiEnabled) {
130
- return {
131
- ...baseConfig,
132
- environments: {
133
- ssr: ssrConfig
134
- }
135
- };
136
- }
137
- return {
138
- ...baseConfig,
139
- ...ssrConfig
140
- };
141
- },
142
- async closeBundle() {
143
- if (!pluginConfig || !pluginConfig.isSsrBuild || runtime !== "cloudflare") {
144
- return;
145
- }
146
- console.log("Cleaning up server exports...");
147
- const buildPath = path.join(pluginConfig.rootDirectory, pluginConfig.buildDirectory, "server", "index.js");
148
- let serverFile = await fs.promises.readFile(buildPath, "utf-8").catch((e) => {
149
- if (e.code === "ENOENT") {
150
- console.error("\x1B[31m\nThe server was not built\x1B[0m");
151
- if (pluginConfig?.flag?.force_react_19) {
152
- console.error(
153
- "\x1B[31m\nYou are forcing React 19 but the server failed to be built by React Router.\nCheck your dependencies, but it's possible that your project is still using React 18 from a node_modules root (monorepo?)\n\x1B[0m"
154
- );
155
- }
156
- }
157
- return null;
158
- });
159
- if (!serverFile) {
160
- return;
161
- }
162
- serverFile = serverFile.replace(REACT_ROUTER_EXPORT, "");
163
- if (await getReactVersion(pluginConfig) >= 19) {
164
- serverFile = serverFile.replace(/react-dom\/server\.browser/g, "react-dom/server.edge");
165
- }
166
- await fs.promises.writeFile(buildPath, serverFile);
167
- console.log("\x1B[32mAll done!\x1B[0m");
168
- },
169
- async configureServer(server) {
170
- globalThis.__viteDevServer = server;
171
- if (!pluginConfig) {
172
- return;
173
- }
174
- if (devServerPlugin) {
175
- return;
176
- }
177
- let adapter = nodeAdapter;
178
- if (runtime === "bun") {
179
- adapter = bunAdapter;
180
- }
181
- if (runtime === "cloudflare") {
182
- const { cloudflareAdapter } = await import("@hono/vite-dev-server/cloudflare");
183
- adapter = cloudflareAdapter;
184
- }
185
- if (runtime === "deno") {
186
- adapter = () => {
187
- if (typeof globalThis.navigator === "undefined") {
188
- globalThis.navigator = {
189
- userAgent: "Deno"
190
- };
191
- } else {
192
- Object.defineProperty(globalThis.navigator, "userAgent", {
193
- value: "Deno",
194
- writable: false
195
- });
196
- }
197
- return {
198
- env: Deno.env.toObject()
199
- };
200
- };
201
- }
202
- devServerPlugin = honoDevServer({
203
- adapter,
204
- injectClientScript: false,
205
- entry: pluginConfig.serverEntryPoint,
206
- export: options.dev?.export || "default",
207
- exclude: [
208
- new RegExp(
209
- `^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/")}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`
210
- ),
211
- new RegExp(
212
- `^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/").split("/")[0]}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`
213
- ),
214
- /\?import(\?.*)?$/,
215
- /^\/@.+$/,
216
- /^\/node_modules\/.*/,
217
- `^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/")}/**/.*/**)`,
218
- `^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/").split("/")[0]}/**/.*/**)`,
219
- ...pluginConfig.dev?.exclude || []
220
- ]
221
- });
222
- server.middlewares.use((req, _res, next) => {
223
- req.rawHeaders.push("x-remote-address", req.socket.remoteAddress || "unknown");
224
- req.rawHeaders.push("x-remote-port", String(req.socket.remotePort || "unknown"));
225
- req.rawHeaders.push("x-remote-family", req.socket.remoteFamily || "unknown");
226
- next();
227
- });
228
- if (typeof devServerPlugin.configureServer === "function") {
229
- devServerPlugin.configureServer(server);
230
- } else {
231
- console.error("Dev server plugin configureServer hook is not a function. This is likely a bug, I guess \u{1F605}\n");
232
- throw new Error("Cannot apply dev server plugin configureServer hook");
233
- }
234
- }
235
- };
27
+ },
28
+ async config(config, env) {
29
+ pluginConfig = resolvePluginConfig(config, options);
30
+ if (!pluginConfig) return;
31
+ const serverEntryPoint = pluginConfig.serverEntryPoint;
32
+ if (env.mode === "development" && runtime === "cloudflare" && !config.plugins?.find((p) => p && "name" in p && p.name === "react-router-cloudflare-vite-dev-proxy")) console.warn(`\x1b[31mMissing cloudflareDevProxy() in your vite.config.ts.\nPlease add it to your plugins: import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";\x1b[0m\n`);
33
+ const baseConfig = {
34
+ define: {
35
+ "import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY": JSON.stringify(pluginConfig.buildDirectory),
36
+ "import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR": JSON.stringify(pluginConfig.assetsDir),
37
+ "import.meta.env.REACT_ROUTER_HONO_SERVER_RUNTIME": JSON.stringify(runtime),
38
+ "import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME": JSON.stringify(pluginConfig.basename)
39
+ },
40
+ ssr: {
41
+ target: runtime === "cloudflare" ? "webworker" : void 0,
42
+ noExternal: ["react-router-hono-server"],
43
+ external: ["@hono/node-ws"],
44
+ optimizeDeps: runtime === "bun" ? {
45
+ include: ["react-dom/server"],
46
+ exclude: ["react"]
47
+ } : void 0
48
+ }
49
+ };
50
+ let reactRouterBuildFile = pluginConfig.serverBuildFile;
51
+ if (reactRouterBuildFile === "index.js") reactRouterBuildFile = "assets/server-build.js";
52
+ const resolve = {};
53
+ if (runtime === "cloudflare") resolve.alias = { "react-dom/server": await getReactVersion(pluginConfig) >= 19 ? "react-dom/server.edge" : "react-dom/server.browser" };
54
+ if (runtime === "bun") resolve.alias = { "react-dom/server": "react-dom/server.node" };
55
+ if (runtime === "deno") resolve.alias = { "react-dom/server": "react-dom/server.node" };
56
+ const ssrConfig = {
57
+ resolve,
58
+ build: { rollupOptions: {
59
+ input: serverEntryPoint,
60
+ output: {
61
+ entryFileNames: (chunk) => {
62
+ chunk.facadeModuleId = REACT_ROUTER_SERVER_BUILD_MODULE_ID;
63
+ return "index.js";
64
+ },
65
+ chunkFileNames: (chunk) => {
66
+ if (chunk.name === "server-build") return reactRouterBuildFile;
67
+ return "assets/[name]-[hash].js";
68
+ },
69
+ manualChunks: runtime !== "cloudflare" ? (id, meta) => {
70
+ if (meta.getModuleInfo(id)?.importers.some((id) => id.includes(serverEntryPoint))) return path.basename(id, path.extname(id));
71
+ } : void 0,
72
+ footer: runtime === "cloudflare" ? REACT_ROUTER_EXPORT : void 0
73
+ }
74
+ } }
75
+ };
76
+ return {
77
+ ...baseConfig,
78
+ resolve,
79
+ environments: { ssr: ssrConfig }
80
+ };
81
+ },
82
+ async closeBundle() {
83
+ if (!pluginConfig?.isSsrBuild || runtime !== "cloudflare") return;
84
+ console.log("Cleaning up server exports...");
85
+ const buildPath = path.join(pluginConfig.rootDirectory, pluginConfig.buildDirectory, "server", "index.js");
86
+ let serverFile = await fs.promises.readFile(buildPath, "utf-8").catch((e) => {
87
+ if (e.code === "ENOENT") {
88
+ console.error("\x1B[31m\nThe server was not built\x1B[0m");
89
+ if (pluginConfig?.flag?.force_react_19) console.error("\x1B[31m\nYou are forcing React 19 but the server failed to be built by React Router.\nCheck your dependencies, but it's possible that your project is still using React 18 from a node_modules root (monorepo?)\n\x1B[0m");
90
+ }
91
+ return null;
92
+ });
93
+ if (!serverFile) return;
94
+ serverFile = serverFile.replace(REACT_ROUTER_EXPORT, "");
95
+ if (await getReactVersion(pluginConfig) >= 19) serverFile = serverFile.replace(/react-dom\/server\.browser/g, "react-dom/server.edge");
96
+ await fs.promises.writeFile(buildPath, serverFile);
97
+ console.log("\x1B[32mAll done!\x1B[0m");
98
+ },
99
+ async configureServer(server) {
100
+ globalThis.__viteDevServer = server;
101
+ if (!pluginConfig) return;
102
+ if (devServerPlugin) return;
103
+ let adapter = nodeAdapter;
104
+ if (runtime === "bun") adapter = bunAdapter;
105
+ if (runtime === "cloudflare") {
106
+ const { cloudflareAdapter } = await import("@hono/vite-dev-server/cloudflare");
107
+ adapter = cloudflareAdapter;
108
+ }
109
+ if (runtime === "deno") adapter = () => {
110
+ if (typeof globalThis.navigator === "undefined") globalThis.navigator = { userAgent: "Deno" };
111
+ else Object.defineProperty(globalThis.navigator, "userAgent", {
112
+ value: "Deno",
113
+ writable: false
114
+ });
115
+ return { env: Deno.env.toObject() };
116
+ };
117
+ devServerPlugin = honoDevServer({
118
+ adapter,
119
+ injectClientScript: false,
120
+ entry: pluginConfig.serverEntryPoint,
121
+ export: options.dev?.export || "default",
122
+ exclude: [
123
+ new RegExp(`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/")}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`),
124
+ new RegExp(`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/").split("/")[0]}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`),
125
+ /\?import(\?.*)?$/,
126
+ /^\/@.+$/,
127
+ /^\/node_modules\/.*/,
128
+ `^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/")}/**/.*/**)`,
129
+ `^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/").split("/")[0]}/**/.*/**)`,
130
+ ...pluginConfig.dev?.exclude || []
131
+ ]
132
+ });
133
+ server.middlewares.use((req, _res, next) => {
134
+ req.rawHeaders.push("x-remote-address", req.socket.remoteAddress || "unknown");
135
+ req.rawHeaders.push("x-remote-port", String(req.socket.remotePort || "unknown"));
136
+ req.rawHeaders.push("x-remote-family", req.socket.remoteFamily || "unknown");
137
+ next();
138
+ });
139
+ if (typeof devServerPlugin.configureServer === "function") devServerPlugin.configureServer(server);
140
+ else {
141
+ console.error("Dev server plugin configureServer hook is not a function. This is likely a bug, I guess 😅\n");
142
+ throw new Error("Cannot apply dev server plugin configureServer hook");
143
+ }
144
+ }
145
+ };
236
146
  }
237
147
  function resolvePluginConfig(config, options) {
238
- if (!("__reactRouterPluginContext" in config)) {
239
- return null;
240
- }
241
- const { reactRouterConfig, environmentBuildContext, rootDirectory } = config.__reactRouterPluginContext;
242
- const buildDirectory = path.relative(rootDirectory, reactRouterConfig.buildDirectory);
243
- const appDirectory = path.relative(rootDirectory, reactRouterConfig.appDirectory);
244
- const isSsrBuild = environmentBuildContext?.name === "ssr";
245
- const assetsDir = config.build?.assetsDir || "assets";
246
- const serverEntryPoint = options.serverEntryPoint || findDefaultServerEntry(appDirectory);
247
- const serverBuildFile = reactRouterConfig.serverBuildFile;
248
- const basename = reactRouterConfig.basename;
249
- const future = reactRouterConfig.future;
250
- return {
251
- rootDirectory,
252
- buildDirectory,
253
- appDirectory,
254
- isSsrBuild,
255
- assetsDir,
256
- serverEntryPoint,
257
- dev: options.dev,
258
- serverBuildFile,
259
- basename,
260
- future,
261
- flag: isCloudflareOptions(options) ? options.flag : {}
262
- };
148
+ if (!("__reactRouterPluginContext" in config)) return null;
149
+ const { reactRouterConfig, environmentBuildContext, rootDirectory } = config.__reactRouterPluginContext;
150
+ const buildDirectory = path.relative(rootDirectory, reactRouterConfig.buildDirectory);
151
+ const appDirectory = path.relative(rootDirectory, reactRouterConfig.appDirectory);
152
+ const isSsrBuild = environmentBuildContext?.name === "ssr";
153
+ const assetsDir = config.build?.assetsDir || "assets";
154
+ const serverEntryPoint = options.serverEntryPoint || findDefaultServerEntry(appDirectory);
155
+ const serverBuildFile = reactRouterConfig.serverBuildFile;
156
+ const basename = reactRouterConfig.basename;
157
+ const future = reactRouterConfig.future;
158
+ return {
159
+ rootDirectory,
160
+ buildDirectory,
161
+ appDirectory,
162
+ isSsrBuild,
163
+ assetsDir,
164
+ serverEntryPoint,
165
+ dev: options.dev,
166
+ serverBuildFile,
167
+ basename,
168
+ future,
169
+ flag: isCloudflareOptions(options) ? options.flag : {}
170
+ };
263
171
  }
264
- var warned = false;
172
+ let warned = false;
265
173
  function findDefaultServerEntry(appDirectory) {
266
- const fileWay = `${appDirectory}/server.ts`;
267
- const folderWay = `${appDirectory}/server/index.ts`;
268
- if (fs.existsSync(fileWay)) {
269
- return fileWay;
270
- }
271
- if (fs.existsSync(folderWay)) {
272
- return folderWay;
273
- }
274
- if (!warned) {
275
- console.warn(
276
- `\x1B[33mNo server entry point found.
277
- Will use a virtual module (${VIRTUAL_MODULE_ID}) with a default Hono server.
278
-
279
- To customize the server, create one of the following files:
280
- - ${fileWay} (npx react-router-hono-server reveal file)
281
- - ${folderWay} (npx react-router-hono-server reveal folder)
282
- You can also set the \`serverEntryPoint\` option in the reactRouterHonoServer plugin for more control.\x1B[0m
283
- `
284
- );
285
- warned = true;
286
- }
287
- return VIRTUAL_MODULE_ID;
174
+ const fileWay = `${appDirectory}/server.ts`;
175
+ const folderWay = `${appDirectory}/server/index.ts`;
176
+ if (fs.existsSync(fileWay)) return fileWay;
177
+ if (fs.existsSync(folderWay)) return folderWay;
178
+ if (!warned) {
179
+ console.warn(`\x1b[33mNo server entry point found.\nWill use a virtual module (${VIRTUAL_MODULE_ID}) with a default Hono server.\n\nTo customize the server, create one of the following files:\n - ${fileWay} (npx react-router-hono-server reveal file)\n - ${folderWay} (npx react-router-hono-server reveal folder)\nYou can also set the \`serverEntryPoint\` option in the reactRouterHonoServer plugin for more control.\x1b[0m\n`);
180
+ warned = true;
181
+ }
182
+ return VIRTUAL_MODULE_ID;
288
183
  }
184
+ /**
185
+ * Retrieves the major React version from node_modules
186
+ */
289
187
  async function getReactVersion(pluginConfig) {
290
- if (pluginConfig?.flag?.force_react_19) {
291
- return 19;
292
- }
293
- const reactPackage = await import("react");
294
- const version = reactPackage.default.version || reactPackage.version;
295
- return Number.parseInt(version.split(".")[0], 10);
188
+ if (pluginConfig?.flag?.force_react_19) return 19;
189
+ const reactPackage = await import("react");
190
+ const version = reactPackage.default.version || reactPackage.version;
191
+ return Number.parseInt(version.split(".")[0], 10);
296
192
  }
193
+ /**
194
+ * Type guard to check if options is the Cloudflare variant
195
+ */
297
196
  function isCloudflareOptions(options) {
298
- return options.runtime === "cloudflare";
197
+ return options.runtime === "cloudflare";
299
198
  }
300
- export {
301
- reactRouterHonoServer
302
- };
199
+ //#endregion
200
+ export { reactRouterHonoServer };
@@ -1,12 +1,10 @@
1
- import * as hono from 'hono';
2
- import { Env, Hono, Context } from 'hono';
3
- import { UpgradeWebSocket } from 'hono/ws';
4
- import { ServerBuild, UNSAFE_MiddlewareEnabled, RouterContextProvider, AppLoadContext } from 'react-router';
5
-
6
- type ReactRouterHonoServerAppLoadContext = UNSAFE_MiddlewareEnabled extends true
7
- ? RouterContextProvider
8
- : AppLoadContext;
1
+ import { ServerType } from "@hono/node-server";
2
+ import { Context, Env, Hono } from "hono";
3
+ import { AppLoadContext, RouterContextProvider, ServerBuild, UNSAFE_MiddlewareEnabled } from "react-router";
4
+ import { UpgradeWebSocket } from "hono/ws";
9
5
 
6
+ //#region src/types/hono-server-options-base.d.ts
7
+ type ReactRouterHonoServerAppLoadContext = UNSAFE_MiddlewareEnabled extends true ? RouterContextProvider : AppLoadContext;
10
8
  interface HonoServerOptionsBase<E extends Env> {
11
9
  /**
12
10
  * The base Hono app to use as a replacement for the default one created automatically
@@ -53,13 +51,10 @@ interface HonoServerOptionsBase<E extends Env> {
53
51
  * }
54
52
  * ```
55
53
  */
56
- getLoadContext?: (
57
- c: Context<E>,
58
- options: {
59
- build: ServerBuild;
60
- mode: string;
61
- }
62
- ) => Promise<ReactRouterHonoServerAppLoadContext> | ReactRouterHonoServerAppLoadContext;
54
+ getLoadContext?: (c: Context<E>, options: {
55
+ build: ServerBuild;
56
+ mode: string;
57
+ }) => Promise<ReactRouterHonoServerAppLoadContext> | ReactRouterHonoServerAppLoadContext;
63
58
  /**
64
59
  * Hook to add middleware that runs before any built-in middleware, including assets serving.
65
60
  *
@@ -67,7 +62,6 @@ interface HonoServerOptionsBase<E extends Env> {
67
62
  */
68
63
  beforeAll?: (app: Hono<E>) => Promise<void> | void;
69
64
  }
70
-
71
65
  interface WithWebsocket<E extends Env> {
72
66
  /**
73
67
  * Enable WebSockets support in `configure`
@@ -82,9 +76,10 @@ interface WithWebsocket<E extends Env> {
82
76
  *
83
77
  * It is applied after the default middleware and before the React Router middleware
84
78
  */
85
- configure: (app: Hono<E>, options: { upgradeWebSocket: UpgradeWebSocket }) => Promise<void> | void;
79
+ configure: (app: Hono<E>, options: {
80
+ upgradeWebSocket: UpgradeWebSocket;
81
+ }) => Promise<void> | void;
86
82
  }
87
-
88
83
  interface WithoutWebsocket<E extends Env> {
89
84
  /**
90
85
  * Enable WebSockets support in `configure`
@@ -101,13 +96,14 @@ interface WithoutWebsocket<E extends Env> {
101
96
  */
102
97
  configure?: (app: Hono<E>) => Promise<void> | void;
103
98
  }
104
-
99
+ //#endregion
100
+ //#region src/helpers.d.ts
105
101
  /**
106
102
  * Helper to create a getLoadContext function fully typed
107
103
  */
108
- declare function createGetLoadContext(getLoadContext: HonoServerOptionsBase<Env>["getLoadContext"]): ((c: hono.Context<Env, any, {}>, options: {
109
- build: ServerBuild;
110
- mode: string;
104
+ declare function createGetLoadContext(getLoadContext: HonoServerOptionsBase<Env>["getLoadContext"]): ((c: import("hono").Context<Env, any, {}>, options: {
105
+ build: ServerBuild;
106
+ mode: string;
111
107
  }) => Promise<ReactRouterHonoServerAppLoadContext> | ReactRouterHonoServerAppLoadContext) | undefined;
112
-
113
- export { type HonoServerOptionsBase as H, type WithoutWebsocket as W, type WithWebsocket as a, createGetLoadContext as c };
108
+ //#endregion
109
+ export { WithoutWebsocket as i, HonoServerOptionsBase as n, WithWebsocket as r, createGetLoadContext as t };