Skip to content

Commit b7c9ee8

Browse files
committed
v3.0.3 - Dev server improvements
1 parent 304b206 commit b7c9ee8

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/dev-server/init.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ServerBuild } from "@remix-run/server-runtime";
22
import { singleton } from "./singleton.js";
33
import { WebSocketServer } from "ws";
4-
import { successLog } from "./logger.js";
4+
import { errorLog, successLog } from "./logger.js";
55
import { augmentLoader } from "./loader.js";
66
import { augmentAction } from "./action.js";
77
import { setConfig, type DevToolsServerConfig } from "./config.js";
@@ -19,15 +19,22 @@ export const augmentIfExists = (property: string, object: Record<string, any>, a
1919
const installDevToolsGlobals = (config?: DevToolsServerConfig) => {
2020
const ws = singleton("ws", () => {
2121
if (config?.withWebsocket === false) return;
22+
2223
const port = config?.wsPort || 8080;
2324
const ws = new WebSocketServer({ port });
25+
ws.on("listening", () => {
26+
successLog(`🌍 DevTools Websocket Server started on port ${chalk.green(port)}`);
27+
});
28+
ws.on("error", () => {
29+
errorLog(`🌍 DevTools Websocket Server failed to start, port ${port} already in use!`);
30+
});
31+
2432
["SIGINT", "SIGTERM"].forEach((event) => {
2533
process.on(event, () => {
2634
ws.close();
2735
});
2836
});
2937

30-
successLog(`🌍 DevTools Websocket Server started on port ${chalk.green(port)}`);
3138
return ws;
3239
});
3340

src/dev-server/server.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from "node:fs";
1+
import fs, { existsSync } from "node:fs";
22
import os from "node:os";
33
import path from "node:path";
44
import url from "node:url";
@@ -12,6 +12,7 @@ import sourceMapSupport from "source-map-support";
1212
import getPort from "get-port";
1313
import { withServerDevTools } from "./init.js";
1414
import chalk from "chalk";
15+
1516
if (process.env.NODE_ENV === "production") {
1617
throw new Error("You can't use Remix Dev Tools server in production mode!");
1718
}
@@ -39,7 +40,11 @@ export async function run() {
3940
}
4041

4142
const buildPath = path.resolve(buildPathArg);
42-
const versionPath = path.resolve(buildPathArg, "..", "version.txt");
43+
let versionPath: string | undefined = path.resolve(buildPathArg, "..", "version.txt");
44+
45+
if (!existsSync(versionPath)) {
46+
versionPath = undefined;
47+
}
4348
async function reimportServer() {
4449
// Kill ESM cache
4550
const stat = fs.statSync(buildPath);
@@ -66,7 +71,10 @@ export async function run() {
6671
broadcastDevReady(build);
6772
}
6873

69-
chokidar.watch(versionPath, { ignoreInitial: true }).on("add", handleServerUpdate).on("change", handleServerUpdate);
74+
chokidar
75+
.watch(versionPath ?? buildPath, { ignoreInitial: true })
76+
.on("add", handleServerUpdate)
77+
.on("change", handleServerUpdate);
7078

7179
// wrap request handler to make sure its recreated with the latest build for every request
7280
return async (req, res, next) => {

src/test-apps/cjs-app/remix.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
// assetsBuildDirectory: "public/build",
88
// serverBuildPath: "build/index.js",
99
// publicPath: "/build/",
10-
watchPaths: ["../../dist"],
10+
watchPaths: ["../../../dist"],
1111
serverModuleFormat: "cjs",
1212
tailwind: true,
1313
/* routes(defineRoutes) {

0 commit comments

Comments
 (0)