@react-router/serve 7.16.0 → 8.0.0-pre.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.
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // If not already set, default `NODE_ENV=production` so React loads the proper
4
- // version in it's CJS entry script
4
+ // version in its CJS entry script
5
5
  process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
6
6
 
7
- require("./dist/cli");
7
+ void import("./dist/cli.js").catch((error) => {
8
+ if (error) console.error(error);
9
+ process.exit(1);
10
+ });
package/dist/cli.d.ts CHANGED
@@ -1 +1,2 @@
1
- #!/usr/bin/env node
1
+
2
+ export { };
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * @react-router/serve v7.16.0
3
+ * @react-router/serve v8.0.0-pre.0
4
4
  *
5
5
  * Copyright (c) Remix Software Inc.
6
6
  *
@@ -9,138 +9,98 @@
9
9
  *
10
10
  * @license MIT
11
11
  */
12
- "use strict";
13
- var __create = Object.create;
14
- var __defProp = Object.defineProperty;
15
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
16
- var __getOwnPropNames = Object.getOwnPropertyNames;
17
- var __getProtoOf = Object.getPrototypeOf;
18
- var __hasOwnProp = Object.prototype.hasOwnProperty;
19
- var __copyProps = (to, from, except, desc) => {
20
- if (from && typeof from === "object" || typeof from === "function") {
21
- for (let key of __getOwnPropNames(from))
22
- if (!__hasOwnProp.call(to, key) && key !== except)
23
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
- }
25
- return to;
26
- };
27
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
- // If the importer is in node compatibility mode or this is not an ESM
29
- // file that has been converted to a CommonJS file using a Babel-
30
- // compatible transform (i.e. "__esModule" has not been set), then set
31
- // "default" to the CommonJS "module.exports" for node compatibility.
32
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
- mod
34
- ));
35
-
36
- // cli.ts
37
- var import_node_fs = __toESM(require("fs"));
38
- var import_node_os = __toESM(require("os"));
39
- var import_node_path = __toESM(require("path"));
40
- var import_node_url = __toESM(require("url"));
41
- var import_express = require("@react-router/express");
42
- var import_node_fetch_server = require("@mjackson/node-fetch-server");
43
- var import_compression = __toESM(require("compression"));
44
- var import_express2 = __toESM(require("express"));
45
- var import_morgan = __toESM(require("morgan"));
46
- var import_source_map_support = __toESM(require("source-map-support"));
47
- var import_get_port = __toESM(require("get-port"));
12
+ import fs from "node:fs";
13
+ import os from "node:os";
14
+ import path from "node:path";
15
+ import url from "node:url";
16
+ import { createRequestHandler } from "@react-router/express";
17
+ import { createRequestListener } from "@remix-run/node-fetch-server";
18
+ import compression from "compression";
19
+ import express from "express";
20
+ import morgan from "morgan";
21
+ import sourceMapSupport from "source-map-support";
22
+ import getPort from "get-port";
23
+ //#region cli.ts
48
24
  process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
49
- import_source_map_support.default.install({
50
- retrieveSourceMap: function(source) {
51
- let match = source.startsWith("file://");
52
- if (match) {
53
- let filePath = import_node_url.default.fileURLToPath(source);
54
- let sourceMapPath = `${filePath}.map`;
55
- if (import_node_fs.default.existsSync(sourceMapPath)) {
56
- return {
57
- url: source,
58
- map: import_node_fs.default.readFileSync(sourceMapPath, "utf8")
59
- };
60
- }
61
- }
62
- return null;
63
- }
64
- });
25
+ sourceMapSupport.install({ retrieveSourceMap: function(source) {
26
+ if (source.startsWith("file://")) {
27
+ let sourceMapPath = `${url.fileURLToPath(source)}.map`;
28
+ if (fs.existsSync(sourceMapPath)) return {
29
+ url: source,
30
+ map: fs.readFileSync(sourceMapPath, "utf8")
31
+ };
32
+ }
33
+ return null;
34
+ } });
65
35
  run();
66
36
  function isRSCServerBuild(build) {
67
- return Boolean(
68
- typeof build === "object" && build && "default" in build && typeof build.default === "object" && build.default && "fetch" in build.default && typeof build.default.fetch === "function"
69
- );
37
+ return Boolean(typeof build === "object" && build && "default" in build && typeof build.default === "object" && build.default && "fetch" in build.default && typeof build.default.fetch === "function");
70
38
  }
71
39
  function parseNumber(raw) {
72
- if (raw === void 0) return void 0;
73
- let maybe = Number(raw);
74
- if (Number.isNaN(maybe)) return void 0;
75
- return maybe;
40
+ if (raw === void 0) return void 0;
41
+ let maybe = Number(raw);
42
+ if (Number.isNaN(maybe)) return void 0;
43
+ return maybe;
44
+ }
45
+ function getExpressPath(publicPath) {
46
+ let pathname;
47
+ try {
48
+ pathname = new URL(publicPath).pathname;
49
+ } catch {
50
+ pathname = publicPath;
51
+ }
52
+ return pathname.startsWith("/") ? pathname : `/${pathname}`;
76
53
  }
77
54
  async function run() {
78
- let port = parseNumber(process.env.PORT) ?? await (0, import_get_port.default)({ port: 3e3 });
79
- let buildPathArg = process.argv[2];
80
- if (!buildPathArg) {
81
- console.error(`
55
+ let port = parseNumber(process.env.PORT) ?? await getPort({ port: 3e3 });
56
+ let buildPathArg = process.argv[2];
57
+ if (!buildPathArg) {
58
+ console.error(`
82
59
  Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);
83
- process.exit(1);
84
- }
85
- let buildPath = import_node_path.default.resolve(buildPathArg);
86
- let buildModule = await import(import_node_url.default.pathToFileURL(buildPath).href);
87
- let build;
88
- let isRSCBuild = false;
89
- if (isRSCBuild = isRSCServerBuild(buildModule)) {
90
- const config = {
91
- publicPath: "/",
92
- assetsBuildDirectory: import_node_path.default.join("..", "client"),
93
- ...buildModule.unstable_reactRouterServeConfig || {}
94
- };
95
- build = {
96
- fetch: buildModule.default.fetch,
97
- publicPath: config.publicPath,
98
- assetsBuildDirectory: import_node_path.default.resolve(
99
- import_node_path.default.dirname(buildPath),
100
- config.assetsBuildDirectory
101
- )
102
- };
103
- } else {
104
- build = buildModule;
105
- }
106
- let onListen = () => {
107
- let address = process.env.HOST || Object.values(import_node_os.default.networkInterfaces()).flat().find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
108
- if (!address) {
109
- console.log(`[react-router-serve] http://localhost:${port}`);
110
- } else {
111
- console.log(
112
- `[react-router-serve] http://localhost:${port} (http://${address}:${port})`
113
- );
114
- }
115
- };
116
- let app = (0, import_express2.default)();
117
- app.disable("x-powered-by");
118
- if (!isRSCBuild) {
119
- app.use((0, import_compression.default)());
120
- }
121
- app.use(
122
- import_node_path.default.posix.join(build.publicPath, "assets"),
123
- import_express2.default.static(import_node_path.default.join(build.assetsBuildDirectory, "assets"), {
124
- immutable: true,
125
- maxAge: "1y"
126
- })
127
- );
128
- app.use(build.publicPath, import_express2.default.static(build.assetsBuildDirectory));
129
- app.use(import_express2.default.static("public", { maxAge: "1h" }));
130
- app.use((0, import_morgan.default)("tiny"));
131
- if (build.fetch) {
132
- app.all("*", (0, import_node_fetch_server.createRequestListener)(build.fetch));
133
- } else {
134
- app.all(
135
- "*",
136
- (0, import_express.createRequestHandler)({
137
- build: buildModule,
138
- mode: process.env.NODE_ENV
139
- })
140
- );
141
- }
142
- let server = process.env.HOST ? app.listen(port, process.env.HOST, onListen) : app.listen(port, onListen);
143
- ["SIGTERM", "SIGINT"].forEach((signal) => {
144
- process.once(signal, () => server?.close(console.error));
145
- });
60
+ process.exit(1);
61
+ }
62
+ let buildPath = path.resolve(buildPathArg);
63
+ let buildModule = await import(url.pathToFileURL(buildPath).href);
64
+ let build;
65
+ let isRSCBuild = false;
66
+ if (isRSCBuild = isRSCServerBuild(buildModule)) {
67
+ const config = {
68
+ publicPath: "/",
69
+ assetsBuildDirectory: path.join("..", "client"),
70
+ ...buildModule.unstable_reactRouterServeConfig || {}
71
+ };
72
+ build = {
73
+ fetch: buildModule.default.fetch,
74
+ publicPath: config.publicPath,
75
+ assetsBuildDirectory: path.resolve(path.dirname(buildPath), config.assetsBuildDirectory)
76
+ };
77
+ } else build = buildModule;
78
+ let onListen = (error) => {
79
+ if (error) throw error;
80
+ let address = process.env.HOST || Object.values(os.networkInterfaces()).flat().find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
81
+ if (!address) console.log(`[react-router-serve] http://localhost:${port}`);
82
+ else console.log(`[react-router-serve] http://localhost:${port} (http://${address}:${port})`);
83
+ };
84
+ let app = express();
85
+ app.disable("x-powered-by");
86
+ if (!isRSCBuild) app.use(compression());
87
+ let expressPublicPath = getExpressPath(build.publicPath);
88
+ app.use(path.posix.join(expressPublicPath, "assets"), express.static(path.join(build.assetsBuildDirectory, "assets"), {
89
+ immutable: true,
90
+ maxAge: "1y"
91
+ }));
92
+ app.use(expressPublicPath, express.static(build.assetsBuildDirectory));
93
+ app.use(express.static("public", { maxAge: "1h" }));
94
+ app.use(morgan("tiny"));
95
+ if (build.fetch) app.all("/{*splat}", createRequestListener(build.fetch));
96
+ else app.all("/{*splat}", createRequestHandler({
97
+ build: buildModule,
98
+ mode: process.env.NODE_ENV
99
+ }));
100
+ let server = process.env.HOST ? app.listen(port, process.env.HOST, onListen) : app.listen(port, onListen);
101
+ ["SIGTERM", "SIGINT"].forEach((signal) => {
102
+ process.once(signal, () => server?.close(console.error));
103
+ });
146
104
  }
105
+ //#endregion
106
+ export {};
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@react-router/serve",
3
- "version": "7.16.0",
3
+ "type": "module",
4
+ "version": "8.0.0-pre.0",
4
5
  "description": "Production application server for React Router",
5
6
  "bugs": {
6
7
  "url": "https://github.com/remix-run/react-router/issues"
@@ -15,15 +16,15 @@
15
16
  "./package.json": "./package.json"
16
17
  },
17
18
  "bin": {
18
- "react-router-serve": "bin.js"
19
+ "react-router-serve": "bin.cjs"
19
20
  },
20
21
  "wireit": {
21
22
  "build": {
22
- "command": "tsup",
23
+ "command": "tsdown",
23
24
  "files": [
24
25
  "../../pnpm-workspace.yaml",
25
26
  "*.ts",
26
- "bin.js",
27
+ "bin.cjs",
27
28
  "tsconfig.json",
28
29
  "package.json"
29
30
  ],
@@ -33,33 +34,34 @@
33
34
  }
34
35
  },
35
36
  "dependencies": {
36
- "@mjackson/node-fetch-server": "^0.2.0",
37
+ "@remix-run/node-fetch-server": "^0.13.3",
37
38
  "compression": "^1.8.1",
38
- "express": "^4.19.2",
39
- "get-port": "5.1.1",
39
+ "express": "^5.2.1",
40
+ "get-port": "7.2.0",
40
41
  "morgan": "^1.10.1",
41
42
  "source-map-support": "^0.5.21",
42
- "@react-router/express": "7.16.0",
43
- "@react-router/node": "7.16.0"
43
+ "@react-router/express": "8.0.0-pre.0",
44
+ "@react-router/node": "8.0.0-pre.0"
44
45
  },
45
46
  "peerDependencies": {
46
- "react-router": "7.16.0"
47
+ "react-router": "8.0.0-pre.0"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@types/compression": "^1.8.1",
50
- "@types/express": "^4.17.9",
51
+ "@types/express": "^5.0.6",
51
52
  "@types/morgan": "^1.9.10",
53
+ "@types/node": "^22.19.19",
52
54
  "@types/source-map-support": "^0.5.6",
53
- "tsup": "^8.3.0",
54
- "typescript": "^5.4.5",
55
- "wireit": "0.14.9"
55
+ "tsdown": "^0.22.0",
56
+ "typescript": "^6.0.3",
57
+ "wireit": "0.14.12"
56
58
  },
57
59
  "engines": {
58
- "node": ">=20.0.0"
60
+ "node": ">=22.12.0"
59
61
  },
60
62
  "files": [
61
63
  "dist/",
62
- "bin.js",
64
+ "bin.cjs",
63
65
  "CHANGELOG.md",
64
66
  "LICENSE.md",
65
67
  "README.md"