react-router-hono-server 1.2.0 → 2.1.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.
@@ -0,0 +1,107 @@
1
+ import * as bun from 'bun';
2
+ import { Serve, ServeOptions } from 'bun';
3
+ import * as hono from 'hono';
4
+ import { Env } from 'hono';
5
+ import { BlankEnv } from 'hono/types';
6
+ import { H as HonoServerOptionsBase } from '../hono-server-options-base.d-DChVrA1u.mjs';
7
+ import 'hono/hono-base';
8
+ import 'react-router';
9
+
10
+ interface HonoServerOptions<E extends Env = BlankEnv> extends HonoServerOptionsBase<E> {
11
+ /**
12
+ * Customize the bun server
13
+ *
14
+ * {@link https://bun.sh/docs/api/http#start-a-server-bun-serve}
15
+ */
16
+ customBunServer?: Serve & ServeOptions;
17
+ }
18
+ /**
19
+ * Create a Hono server
20
+ *
21
+ * @param HonoServerOptions options {@link HonoServerOptions} - The configuration options for the server
22
+ */
23
+ declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<{
24
+ fetch: (request: Request, Env?: {} | E["Bindings"] | undefined, executionCtx?: hono.ExecutionContext) => Response | Promise<Response>;
25
+ port: number;
26
+ development: boolean;
27
+ } | {
28
+ fetch: (request: Request, Env?: {} | E["Bindings"] | undefined, executionCtx?: hono.ExecutionContext) => Response | Promise<Response>;
29
+ port: number;
30
+ development: boolean;
31
+ reusePort?: boolean;
32
+ hostname?: string;
33
+ unix?: never;
34
+ idleTimeout?: number;
35
+ maxRequestBodySize?: number;
36
+ error?: (this: bun.Server, error: bun.ErrorLike) => Response | Promise<Response> | undefined | Promise<undefined>;
37
+ id?: string | null;
38
+ static?: Record<`/${string}`, Response>;
39
+ } | {
40
+ fetch: (request: Request, Env?: {} | E["Bindings"] | undefined, executionCtx?: hono.ExecutionContext) => Response | Promise<Response>;
41
+ port: number;
42
+ development: boolean;
43
+ tls?: bun.TLSOptions | bun.TLSOptions[];
44
+ reusePort?: boolean;
45
+ hostname?: string;
46
+ unix?: never;
47
+ idleTimeout?: number;
48
+ maxRequestBodySize?: number;
49
+ error?: (this: bun.Server, error: bun.ErrorLike) => Response | Promise<Response> | undefined | Promise<undefined>;
50
+ id?: string | null;
51
+ static?: Record<`/${string}`, Response>;
52
+ passphrase?: string;
53
+ dhParamsFile?: string;
54
+ serverName?: string;
55
+ lowMemoryMode?: boolean;
56
+ rejectUnauthorized?: boolean;
57
+ requestCert?: boolean;
58
+ ca?: string | Buffer | bun.BunFile | Array<string | Buffer | bun.BunFile> | undefined;
59
+ cert?: string | Buffer | bun.BunFile | Array<string | Buffer | bun.BunFile> | undefined;
60
+ key?: string | Buffer | bun.BunFile | Array<string | Buffer | bun.BunFile> | undefined;
61
+ secureOptions?: number | undefined;
62
+ keyFile?: string;
63
+ certFile?: string;
64
+ caFile?: string;
65
+ } | {
66
+ fetch: (request: Request, Env?: {} | E["Bindings"] | undefined, executionCtx?: hono.ExecutionContext) => Response | Promise<Response>;
67
+ port: number;
68
+ development: boolean;
69
+ hostname?: string;
70
+ websocket: bun.WebSocketHandler<undefined>;
71
+ maxRequestBodySize?: number;
72
+ error?: (this: bun.Server, error: bun.ErrorLike) => Response | Promise<Response> | undefined | Promise<undefined>;
73
+ id?: string | null;
74
+ static?: Record<`/${string}`, Response>;
75
+ reusePort?: boolean;
76
+ unix?: never;
77
+ idleTimeout?: number;
78
+ } | {
79
+ fetch: (request: Request, Env?: {} | E["Bindings"] | undefined, executionCtx?: hono.ExecutionContext) => Response | Promise<Response>;
80
+ port: number;
81
+ development: boolean;
82
+ unix?: never;
83
+ tls?: bun.TLSOptions | bun.TLSOptions[];
84
+ hostname?: string;
85
+ websocket: bun.WebSocketHandler<undefined>;
86
+ maxRequestBodySize?: number;
87
+ error?: (this: bun.Server, error: bun.ErrorLike) => Response | Promise<Response> | undefined | Promise<undefined>;
88
+ id?: string | null;
89
+ static?: Record<`/${string}`, Response>;
90
+ passphrase?: string;
91
+ dhParamsFile?: string;
92
+ serverName?: string;
93
+ lowMemoryMode?: boolean;
94
+ rejectUnauthorized?: boolean;
95
+ requestCert?: boolean;
96
+ ca?: string | Buffer | bun.BunFile | Array<string | Buffer | bun.BunFile> | undefined;
97
+ cert?: string | Buffer | bun.BunFile | Array<string | Buffer | bun.BunFile> | undefined;
98
+ key?: string | Buffer | bun.BunFile | Array<string | Buffer | bun.BunFile> | undefined;
99
+ secureOptions?: number | undefined;
100
+ keyFile?: string;
101
+ certFile?: string;
102
+ caFile?: string;
103
+ reusePort?: boolean;
104
+ idleTimeout?: number;
105
+ }>;
106
+
107
+ export { type HonoServerOptions, createHonoServer };
@@ -0,0 +1,57 @@
1
+ import {
2
+ cache
3
+ } from "../chunk-ENK5WJB4.mjs";
4
+
5
+ // src/adapters/bun.ts
6
+ import { Hono } from "hono";
7
+ import { serveStatic } from "hono/bun";
8
+ import { createMiddleware } from "hono/factory";
9
+ import { logger } from "hono/logger";
10
+ import { createRequestHandler } from "react-router";
11
+ async function createHonoServer(options = {}) {
12
+ const mergedOptions = {
13
+ ...options,
14
+ port: options.port || Number(options.customBunServer?.port) || Number(process.env.PORT) || 3e3,
15
+ defaultLogger: options.defaultLogger ?? true
16
+ };
17
+ const mode = import.meta.env.MODE;
18
+ const PRODUCTION = mode === "production";
19
+ const server = new Hono(mergedOptions.honoOptions);
20
+ const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
21
+ server.use(
22
+ `/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`,
23
+ cache(60 * 60 * 24 * 365),
24
+ // 1 year
25
+ serveStatic({ root: clientBuildPath })
26
+ );
27
+ server.use("*", cache(60 * 60), serveStatic({ root: PRODUCTION ? clientBuildPath : "./public" }));
28
+ if (mergedOptions.defaultLogger) {
29
+ server.use("*", logger());
30
+ }
31
+ if (mergedOptions.configure) {
32
+ await mergedOptions.configure(server);
33
+ }
34
+ server.use(async (c, next) => {
35
+ const build = await import(
36
+ // @ts-expect-error - Virtual module provided by React Router at build time
37
+ "virtual:react-router/server-build"
38
+ );
39
+ return createMiddleware(async (c2) => {
40
+ const requestHandler = createRequestHandler(build, mode);
41
+ const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
42
+ return requestHandler(c2.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
43
+ })(c, next);
44
+ });
45
+ if (!PRODUCTION) {
46
+ console.log("\u{1F6A7} Running in development mode");
47
+ }
48
+ return {
49
+ ...mergedOptions.customBunServer,
50
+ fetch: server.fetch,
51
+ port: mergedOptions.port,
52
+ development: !PRODUCTION
53
+ };
54
+ }
55
+ export {
56
+ createHonoServer
57
+ };
@@ -0,0 +1,17 @@
1
+ import * as hono_types from 'hono/types';
2
+ import { BlankEnv } from 'hono/types';
3
+ import { Env, Hono } from 'hono';
4
+ import { H as HonoServerOptionsBase } from '../hono-server-options-base.d-DChVrA1u.mjs';
5
+ import 'hono/hono-base';
6
+ import 'react-router';
7
+
8
+ interface HonoServerOptions<E extends Env = BlankEnv> extends Omit<HonoServerOptionsBase<E>, "port"> {
9
+ }
10
+ /**
11
+ * Create a Hono server
12
+ *
13
+ * @param config {@link HonoServerOptions} - The configuration options for the server
14
+ */
15
+ declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, hono_types.BlankSchema, "/">>;
16
+
17
+ export { type HonoServerOptions, createHonoServer };
@@ -0,0 +1,38 @@
1
+ // src/adapters/cloudflare.ts
2
+ import { Hono } from "hono";
3
+ import { createMiddleware } from "hono/factory";
4
+ import { logger } from "hono/logger";
5
+ import { createRequestHandler } from "react-router";
6
+ async function createHonoServer(options = {}) {
7
+ const mergedOptions = {
8
+ ...options,
9
+ defaultLogger: options.defaultLogger ?? true
10
+ };
11
+ const mode = import.meta.env.MODE;
12
+ const PRODUCTION = mode === "production";
13
+ const server = new Hono(mergedOptions.honoOptions);
14
+ if (mergedOptions.defaultLogger) {
15
+ server.use("*", logger());
16
+ }
17
+ if (mergedOptions.configure) {
18
+ await mergedOptions.configure(server);
19
+ }
20
+ server.use(async (c, next) => {
21
+ const build = await import(
22
+ // @ts-expect-error - Virtual module provided by React Router at build time
23
+ "virtual:react-router/server-build"
24
+ );
25
+ return createMiddleware(async (c2) => {
26
+ const requestHandler = createRequestHandler(build, mode);
27
+ const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
28
+ return requestHandler(c2.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
29
+ })(c, next);
30
+ });
31
+ if (!PRODUCTION) {
32
+ console.log("\u{1F6A7} Running in development mode");
33
+ }
34
+ return server;
35
+ }
36
+ export {
37
+ createHonoServer
38
+ };
@@ -0,0 +1,57 @@
1
+ import * as hono_types from 'hono/types';
2
+ import { BlankEnv } from 'hono/types';
3
+ import { AddressInfo } from 'node:net';
4
+ import { Env, Hono } from 'hono';
5
+ import { H as HonoServerOptionsBase } from '../hono-server-options-base.d-DChVrA1u.mjs';
6
+ import { ServerOptions, createServer } from 'node:http';
7
+ import { ServerOptions as ServerOptions$2, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
8
+ import { ServerOptions as ServerOptions$1, createServer as createServer$1 } from 'node:https';
9
+ import 'hono/hono-base';
10
+ import 'react-router';
11
+
12
+ type createHttpOptions = {
13
+ serverOptions?: ServerOptions;
14
+ createServer?: typeof createServer;
15
+ };
16
+ type createHttpsOptions = {
17
+ serverOptions?: ServerOptions$1;
18
+ createServer?: typeof createServer$1;
19
+ };
20
+ type createHttp2Options = {
21
+ serverOptions?: ServerOptions$2;
22
+ createServer?: typeof createServer$2;
23
+ };
24
+ type createSecureHttp2Options = {
25
+ serverOptions?: SecureServerOptions;
26
+ createServer?: typeof createSecureServer;
27
+ };
28
+ type CreateNodeServerOptions =
29
+ | createHttpOptions
30
+ | createHttpsOptions
31
+ | createHttp2Options
32
+ | createSecureHttp2Options;
33
+
34
+ interface HonoServerOptions<E extends Env = BlankEnv> extends HonoServerOptionsBase<E> {
35
+ /**
36
+ * Listening listener (production mode only)
37
+ *
38
+ * It is called when the server is listening
39
+ *
40
+ * Defaults log the port
41
+ */
42
+ listeningListener?: (info: AddressInfo) => void;
43
+ /**
44
+ * Customize the node server (ex: using http2)
45
+ *
46
+ * {@link https://hono.dev/docs/getting-started/nodejs#http2}
47
+ */
48
+ customNodeServer?: CreateNodeServerOptions;
49
+ }
50
+ /**
51
+ * Create a Hono server
52
+ *
53
+ * @param config {@link HonoServerOptions} - The configuration options for the server
54
+ */
55
+ declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, hono_types.BlankSchema, "/">>;
56
+
57
+ export { type HonoServerOptions, createHonoServer };
@@ -0,0 +1,66 @@
1
+ import {
2
+ cache
3
+ } from "../chunk-ENK5WJB4.mjs";
4
+
5
+ // src/adapters/node.ts
6
+ import { serve } from "@hono/node-server";
7
+ import { serveStatic } from "@hono/node-server/serve-static";
8
+ import { Hono } from "hono";
9
+ import { createMiddleware } from "hono/factory";
10
+ import { logger } from "hono/logger";
11
+ import { createRequestHandler } from "react-router";
12
+ async function createHonoServer(options = {}) {
13
+ const mergedOptions = {
14
+ listeningListener: (info) => {
15
+ console.log(`\u{1F680} Server started on port ${info.port}`);
16
+ console.log(`\u{1F30D} http://127.0.0.1:${info.port}`);
17
+ },
18
+ ...options,
19
+ port: options.port || Number(process.env.PORT) || 3e3,
20
+ defaultLogger: options.defaultLogger ?? true
21
+ };
22
+ const mode = import.meta.env.MODE;
23
+ const PRODUCTION = mode === "production";
24
+ const server = new Hono(mergedOptions.honoOptions);
25
+ const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
26
+ server.use(
27
+ `/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`,
28
+ cache(60 * 60 * 24 * 365),
29
+ // 1 year
30
+ serveStatic({ root: clientBuildPath })
31
+ );
32
+ server.use("*", cache(60 * 60), serveStatic({ root: PRODUCTION ? clientBuildPath : "./public" }));
33
+ if (mergedOptions.defaultLogger) {
34
+ server.use("*", logger());
35
+ }
36
+ if (mergedOptions.configure) {
37
+ await mergedOptions.configure(server);
38
+ }
39
+ server.use(async (c, next) => {
40
+ const build = await import(
41
+ // @ts-expect-error - Virtual module provided by React Router at build time
42
+ "virtual:react-router/server-build"
43
+ );
44
+ return createMiddleware(async (c2) => {
45
+ const requestHandler = createRequestHandler(build, mode);
46
+ const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
47
+ return requestHandler(c2.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
48
+ })(c, next);
49
+ });
50
+ if (PRODUCTION) {
51
+ serve(
52
+ {
53
+ ...server,
54
+ ...mergedOptions.customNodeServer,
55
+ port: mergedOptions.port
56
+ },
57
+ mergedOptions.listeningListener
58
+ );
59
+ } else {
60
+ console.log("\u{1F6A7} Dev server started");
61
+ }
62
+ return server;
63
+ }
64
+ export {
65
+ createHonoServer
66
+ };
@@ -0,0 +1,18 @@
1
+ // src/middleware.ts
2
+ import { createMiddleware } from "hono/factory";
3
+ function cache(seconds) {
4
+ return createMiddleware(async (c, next) => {
5
+ if (!c.req.path.match(/\.[a-zA-Z0-9]+$/) || c.req.path.endsWith(".data")) {
6
+ return next();
7
+ }
8
+ await next();
9
+ if (!c.res.ok) {
10
+ return;
11
+ }
12
+ c.res.headers.set("cache-control", `public, max-age=${seconds}`);
13
+ });
14
+ }
15
+
16
+ export {
17
+ cache
18
+ };
package/dist/cli.mjs ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ // src/cli.ts
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { command, run } from "@drizzle-team/brocli";
6
+ var runtimeRegex = /runtime:\s*(['"])([^'"]*)\1/;
7
+ function guessRuntime() {
8
+ try {
9
+ const viteConfig = fs.readFileSync(path.resolve(process.cwd(), "vite.config.ts"), "utf-8");
10
+ return viteConfig.match(runtimeRegex)?.[2] || "node";
11
+ } catch {
12
+ return "node";
13
+ }
14
+ }
15
+ var runtime = guessRuntime();
16
+ var serverFile = `// generated by react-router-hono-server/dev
17
+ import { createHonoServer } from "react-router-hono-server/${runtime}";
18
+
19
+ export default await createHonoServer();`;
20
+ var file = command({
21
+ name: "file",
22
+ async handler() {
23
+ const serverFilePath = path.resolve(process.cwd(), "app", "server.ts");
24
+ fs.writeFileSync(serverFilePath, serverFile);
25
+ console.log(`\x1B[33m\u2728 File created at ${serverFilePath}\x1B[0m`);
26
+ }
27
+ });
28
+ var folder = command({
29
+ name: "folder",
30
+ async handler() {
31
+ const serverFilePath = path.resolve(process.cwd(), "app", "server", "index.ts");
32
+ if (!fs.existsSync(serverFilePath)) {
33
+ fs.mkdirSync(path.dirname(serverFilePath), { recursive: true });
34
+ }
35
+ fs.writeFileSync(serverFilePath, serverFile);
36
+ console.log(`\x1B[33m\u2728 Folder and file created at ${serverFilePath}\x1B[0m`);
37
+ }
38
+ });
39
+ var reveal = command({
40
+ name: "reveal",
41
+ subcommands: [file, folder]
42
+ });
43
+ run([reveal], {
44
+ name: "React Router Hono Server CLI"
45
+ });
package/dist/dev.d.mts CHANGED
@@ -1,41 +1,38 @@
1
- import * as vite from 'vite';
1
+ import { DevServerOptions } from '@hono/vite-dev-server';
2
+ import { Plugin } from 'vite';
2
3
 
3
- type HonoDevServerOptions = {
4
+ type Runtime = "node" | "bun" | "cloudflare";
5
+ type ReactRouterHonoServerPluginOptions = {
4
6
  /**
5
- * The path to the `app` directory, relative to `vite.config.ts`.
7
+ * The runtime to use for the server.
6
8
  *
7
- * Defaults to `"app"`.
9
+ * Defaults to `node`.
8
10
  */
9
- appDirectory?: string;
11
+ runtime?: Runtime;
10
12
  /**
11
- * The path to the entry file, relative to `vite.config.ts`.
13
+ * The path to the server file, relative to `vite.config.ts`.
12
14
  *
13
- * Defaults to `"app/entry.server.tsx"`.
14
- */
15
- entry?: string;
16
- /**
17
- * The name of the export from the entry file.
15
+ * If it is a folder (`app/server`), it will look for an `index.ts` file.
18
16
  *
19
- * Defaults to `server`. If you are using export default, use `default`
17
+ * Defaults to `${appDirectory}/server[.ts | /index.ts]` if present.
20
18
  *
21
- * @example
22
- * ```ts
23
- * export const server = createHonoServer();
24
- * ```
19
+ * Fallback to a virtual module `virtual:react-router-hono-server/server`.
25
20
  */
26
- exportName?: string;
21
+ serverEntryPoint?: string;
27
22
  /**
28
23
  * The paths that are not served by the dev-server.
29
24
  *
30
25
  * Defaults include `appDirectory` content.
31
26
  */
32
- exclude?: (string | RegExp)[];
27
+ dev?: {
28
+ /**
29
+ * The paths that are not served by the dev-server.
30
+ *
31
+ * Defaults include `appDirectory` content.
32
+ */
33
+ exclude?: DevServerOptions["exclude"];
34
+ };
33
35
  };
34
- /**
35
- * Create a dev server for the Hono server
36
- *
37
- * @param config {@link HonoDevServerOptions} - The configuration options for the dev server
38
- */
39
- declare function devServer(config?: HonoDevServerOptions): vite.Plugin<any>;
36
+ declare function reactRouterHonoServer(options?: ReactRouterHonoServerPluginOptions): Plugin;
40
37
 
41
- export { devServer };
38
+ export { reactRouterHonoServer };
package/dist/dev.mjs CHANGED
@@ -1,28 +1,154 @@
1
1
  // src/dev.ts
2
- import o from "@hono/vite-dev-server";
3
- function n(r) {
4
- let t = r?.appDirectory || "app", e = {
5
- entry: `${t}/entry.server.tsx`,
6
- exportName: "server",
7
- appDirectory: t,
8
- exclude: [],
9
- ...r
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import honoDevServer from "@hono/vite-dev-server";
5
+ import bunAdapter from "@hono/vite-dev-server/bun";
6
+ import cloudflareAdapter from "@hono/vite-dev-server/cloudflare";
7
+ var virtualModuleId = "\0virtual:react-router-hono-server/server";
8
+ function reactRouterHonoServer(options = {}) {
9
+ const runtime = options.runtime || "node";
10
+ let pluginConfig;
11
+ let devServerPlugin;
12
+ return {
13
+ name: "react-router-hono-server",
14
+ enforce: "post",
15
+ resolveId(id) {
16
+ if (id === virtualModuleId) {
17
+ return id;
18
+ }
19
+ },
20
+ load(id) {
21
+ if (id === virtualModuleId) {
22
+ return `
23
+ // generated by react-router-hono-server/dev
24
+ import { createHonoServer } from "react-router-hono-server/${runtime}";
25
+
26
+ export default await createHonoServer();
27
+ `;
28
+ }
29
+ },
30
+ config(config) {
31
+ pluginConfig = resolvePluginConfig(config, options);
32
+ if (!pluginConfig) {
33
+ return;
34
+ }
35
+ if (runtime === "cloudflare" && !config.plugins?.find((p) => p && "name" in p && p.name === "react-router-cloudflare-vite-dev-proxy")) {
36
+ console.error(
37
+ `\x1B[31mMissing cloudflareDevProxy() in your vite.config.ts.
38
+ Please add it to your plugins: import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";\x1B[0m
39
+ `
40
+ );
41
+ throw new Error("Missing mandatory plugin cloudflareDevProxy() in vite.config.ts");
42
+ }
43
+ const baseConfig = {
44
+ // Define environment variables that are hot-swapped during development and SSR build
45
+ define: {
46
+ "import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY": JSON.stringify(pluginConfig.buildDirectory),
47
+ "import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR": JSON.stringify(pluginConfig.assetsDir)
48
+ },
49
+ ssr: {
50
+ target: runtime === "cloudflare" ? "webworker" : void 0,
51
+ // Ensure our package is not externalized during SSR build
52
+ // This is necessary because we are using a virtual import to load the React Router server entry point
53
+ noExternal: ["react-router-hono-server"]
54
+ }
55
+ };
56
+ if (!pluginConfig.isSsrBuild) {
57
+ return baseConfig;
58
+ }
59
+ return {
60
+ ...baseConfig,
61
+ build: {
62
+ target: "esnext",
63
+ rollupOptions: {
64
+ input: pluginConfig.serverEntryPoint
65
+ }
66
+ }
67
+ };
68
+ },
69
+ configureServer(server) {
70
+ if (!pluginConfig) {
71
+ return;
72
+ }
73
+ if (devServerPlugin) {
74
+ return;
75
+ }
76
+ let adapter;
77
+ if (runtime === "bun") {
78
+ adapter = bunAdapter;
79
+ }
80
+ if (runtime === "cloudflare") {
81
+ adapter = cloudflareAdapter;
82
+ }
83
+ devServerPlugin = honoDevServer({
84
+ adapter,
85
+ injectClientScript: false,
86
+ entry: pluginConfig.serverEntryPoint,
87
+ export: "default",
88
+ exclude: [
89
+ `/${pluginConfig.appDirectory}/**/*`,
90
+ `/${pluginConfig.appDirectory}/**/.*/**`,
91
+ /^\/@.+$/,
92
+ /^\/node_modules\/.*/,
93
+ /\?import$/,
94
+ ...pluginConfig.dev?.exclude || []
95
+ ]
96
+ });
97
+ if (typeof devServerPlugin.configureServer === "function") {
98
+ devServerPlugin.configureServer(server);
99
+ } else {
100
+ console.error("Dev server plugin configureServer hook is not a function. This is likely a bug, I guess \u{1F605}\n");
101
+ throw new Error("Cannot apply dev server plugin configureServer hook");
102
+ }
103
+ }
10
104
  };
11
- return o({
12
- injectClientScript: !1,
13
- entry: e.entry,
14
- // The file path of your server.
15
- export: e.exportName,
16
- exclude: [
17
- `/${e.appDirectory}/**/*`,
18
- `/${e.appDirectory}/**/.*/**`,
19
- /^\/@.+$/,
20
- /^\/node_modules\/.*/,
21
- /\?import$/,
22
- ...e.exclude
23
- ]
24
- });
105
+ }
106
+ function resolvePluginConfig(config, options) {
107
+ if (!("__reactRouterPluginContext" in config)) {
108
+ return null;
109
+ }
110
+ const reactRouterConfig = config.__reactRouterPluginContext;
111
+ const rootDirectory = reactRouterConfig.rootDirectory;
112
+ const buildDirectory = path.relative(rootDirectory, reactRouterConfig.reactRouterConfig.buildDirectory);
113
+ const appDirectory = path.relative(rootDirectory, reactRouterConfig.reactRouterConfig.appDirectory);
114
+ const isSsrBuild = reactRouterConfig.isSsrBuild;
115
+ const assetsDir = config.build?.assetsDir || "assets";
116
+ const serverEntryPoint = options.serverEntryPoint || findDefaultServerEntry(appDirectory);
117
+ return {
118
+ rootDirectory,
119
+ buildDirectory,
120
+ appDirectory,
121
+ isSsrBuild,
122
+ assetsDir,
123
+ serverEntryPoint,
124
+ dev: options.dev
125
+ };
126
+ }
127
+ var warned = false;
128
+ function findDefaultServerEntry(appDirectory) {
129
+ const fileWay = `${appDirectory}/server.ts`;
130
+ const folderWay = `${appDirectory}/server/index.ts`;
131
+ if (fs.existsSync(fileWay)) {
132
+ return fileWay;
133
+ }
134
+ if (fs.existsSync(folderWay)) {
135
+ return folderWay;
136
+ }
137
+ if (!warned) {
138
+ console.warn(
139
+ `\x1B[33mNo server entry point found.
140
+ Will use a virtual module (${virtualModuleId}) with a default Hono server.
141
+
142
+ To customize the server, create one of the following files:
143
+ - ${fileWay} (npx react-router-hono-server reveal file)
144
+ - ${folderWay} (npx react-router-hono-server reveal folder)
145
+ You can also set the \`serverEntryPoint\` option in the reactRouterHonoServer plugin for more control.\x1B[0m
146
+ `
147
+ );
148
+ warned = true;
149
+ }
150
+ return virtualModuleId;
25
151
  }
26
152
  export {
27
- n as devServer
153
+ reactRouterHonoServer
28
154
  };