From c22eb287192c1a5b9c9f87ab32d893f59f56bed1 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 22 Jun 2025 23:10:20 +0200 Subject: [PATCH 1/3] chore: add bun support It definitely has some benefits: - It starts up insanely quickly compared to Node. - It can run typescript directly, allow the build step to be reduced to verify/noEmit. It does not implement NodeJS APIs perfectly, so I've had to add some special handling for Bun, but I think that's okay. --- package.json | 3 +++ scripts/dev.js | 6 ++++-- src/services/configWatcherService.ts | 7 ++++++- src/services/webService.ts | 19 ++++++++++++------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 1ac5831f..a7bf6a69 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,11 @@ "build": "tsc --incremental --sourceMap && ncp static/webui build/static/webui", "build:dev": "tsc --incremental --sourceMap", "build-and-start": "npm run build && npm run start", + "build-and-start:bun": "npm run verify && npm run bun-run", "dev": "node scripts/dev.js", + "dev:bun": "bun scripts/dev.js", "verify": "tsgo --noEmit", + "bun-run": "bun src/index.ts", "lint": "eslint --ext .ts .", "lint:ci": "eslint --ext .ts --rule \"prettier/prettier: off\" .", "lint:fix": "eslint --fix --ext .ts .", diff --git a/scripts/dev.js b/scripts/dev.js index 10d6ac36..1c002c9c 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -28,7 +28,8 @@ function run(changedFile) { runproc = undefined; } - const thisbuildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true }); + const thisbuildproc = spawn("npm", ["run", process.versions.bun ? "verify" : "build:dev"], { stdio: "inherit", shell: true }); + const thisbuildstart = Date.now(); buildproc = thisbuildproc; buildproc.on("exit", code => { if (buildproc !== thisbuildproc) { @@ -36,7 +37,8 @@ function run(changedFile) { } buildproc = undefined; if (code === 0) { - runproc = spawn("npm", ["run", "start", "--", ...args], { stdio: "inherit", shell: true }); + console.log(`${process.versions.bun ? "Verified" : "Built"} in ${Date.now() - thisbuildstart} ms`); + runproc = spawn("npm", ["run", process.versions.bun ? "bun-run" : "start", "--", ...args], { stdio: "inherit", shell: true }); runproc.on("exit", () => { runproc = undefined; }); diff --git a/src/services/configWatcherService.ts b/src/services/configWatcherService.ts index b6f8e83c..bb64d5da 100644 --- a/src/services/configWatcherService.ts +++ b/src/services/configWatcherService.ts @@ -5,7 +5,12 @@ import { config, configPath, loadConfig } from "./configService"; import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService"; let amnesia = false; -fs.watchFile(configPath, () => { +fs.watchFile(configPath, (now, then) => { + // https://github.com/oven-sh/bun/issues/20542 + if (process.versions.bun && now.mtimeMs == then.mtimeMs) { + return; + } + if (amnesia) { amnesia = false; } else { diff --git a/src/services/webService.ts b/src/services/webService.ts index 3be29a58..20ffcd39 100644 --- a/src/services/webService.ts +++ b/src/services/webService.ts @@ -46,16 +46,21 @@ export const startWebServer = (): void => { "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort) ); - void runWsSelfTest("wss", httpsPort).then(ok => { - if (!ok) { - logger.warn(`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`); - if (process.platform == "win32") { + // https://github.com/oven-sh/bun/issues/20547 + if (!process.versions.bun) { + void runWsSelfTest("wss", httpsPort).then(ok => { + if (!ok) { logger.warn( - `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess` + `WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.` ); + if (process.platform == "win32") { + logger.warn( + `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess` + ); + } } - } - }); + }); + } }); }); }; -- 2.47.2 From 478839e93195caf65464c43a53fb474e2298f5b6 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 22 Jun 2025 23:23:17 +0200 Subject: [PATCH 2/3] prettier --- scripts/dev.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/dev.js b/scripts/dev.js index 1c002c9c..b689e130 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -28,7 +28,10 @@ function run(changedFile) { runproc = undefined; } - const thisbuildproc = spawn("npm", ["run", process.versions.bun ? "verify" : "build:dev"], { stdio: "inherit", shell: true }); + const thisbuildproc = spawn("npm", ["run", process.versions.bun ? "verify" : "build:dev"], { + stdio: "inherit", + shell: true + }); const thisbuildstart = Date.now(); buildproc = thisbuildproc; buildproc.on("exit", code => { @@ -38,7 +41,10 @@ function run(changedFile) { buildproc = undefined; if (code === 0) { console.log(`${process.versions.bun ? "Verified" : "Built"} in ${Date.now() - thisbuildstart} ms`); - runproc = spawn("npm", ["run", process.versions.bun ? "bun-run" : "start", "--", ...args], { stdio: "inherit", shell: true }); + runproc = spawn("npm", ["run", process.versions.bun ? "bun-run" : "start", "--", ...args], { + stdio: "inherit", + shell: true + }); runproc.on("exit", () => { runproc = undefined; }); -- 2.47.2 From 73c8a9a257fb9b32a6fa2bb408de45e775df9427 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 22 Jun 2025 23:23:55 +0200 Subject: [PATCH 3/3] actually prettier --- scripts/dev.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/dev.js b/scripts/dev.js index b689e130..542528f1 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -14,6 +14,7 @@ args.push("--secret"); args.push(secret); let buildproc, runproc; +const spawnopts = { stdio: "inherit", shell: true }; function run(changedFile) { if (changedFile) { console.log(`Change to ${changedFile} detected`); @@ -28,10 +29,7 @@ function run(changedFile) { runproc = undefined; } - const thisbuildproc = spawn("npm", ["run", process.versions.bun ? "verify" : "build:dev"], { - stdio: "inherit", - shell: true - }); + const thisbuildproc = spawn("npm", ["run", process.versions.bun ? "verify" : "build:dev"], spawnopts); const thisbuildstart = Date.now(); buildproc = thisbuildproc; buildproc.on("exit", code => { @@ -41,10 +39,7 @@ function run(changedFile) { buildproc = undefined; if (code === 0) { console.log(`${process.versions.bun ? "Verified" : "Built"} in ${Date.now() - thisbuildstart} ms`); - runproc = spawn("npm", ["run", process.versions.bun ? "bun-run" : "start", "--", ...args], { - stdio: "inherit", - shell: true - }); + runproc = spawn("npm", ["run", process.versions.bun ? "bun-run" : "start", "--", ...args], spawnopts); runproc.on("exit", () => { runproc = undefined; }); -- 2.47.2