XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: add bun support (#2254)

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. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2254 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

cee622d5
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

4 个文件 +26 -10
Modified package.json +3 -0
@@ -8,8 +8,11 @@
8 8 "build": "tsc --incremental --sourceMap && ncp static/webui build/static/webui",
9 9 "build:dev": "tsc --incremental --sourceMap",
10 10 "build-and-start": "npm run build && npm run start",
11 "build-and-start:bun": "npm run verify && npm run bun-run",
11 12 "dev": "node scripts/dev.js",
13 "dev:bun": "bun scripts/dev.js",
12 14 "verify": "tsgo --noEmit",
15 "bun-run": "bun src/index.ts",
13 16 "lint": "eslint --ext .ts .",
14 17 "lint:ci": "eslint --ext .ts --rule \"prettier/prettier: off\" .",
15 18 "lint:fix": "eslint --fix --ext .ts .",
Modified scripts/dev.js +5 -2
@@ -14,6 +14,7 @@ args.push("--secret");
14 14 args.push(secret);
15 15
16 16 let buildproc, runproc;
17 const spawnopts = { stdio: "inherit", shell: true };
17 18 function run(changedFile) {
18 19 if (changedFile) {
19 20 console.log(`Change to ${changedFile} detected`);
@@ -28,7 +29,8 @@ function run(changedFile) {
28 29 runproc = undefined;
29 30 }
30 31
31 const thisbuildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true });
32 const thisbuildproc = spawn("npm", ["run", process.versions.bun ? "verify" : "build:dev"], spawnopts);
33 const thisbuildstart = Date.now();
32 34 buildproc = thisbuildproc;
33 35 buildproc.on("exit", code => {
34 36 if (buildproc !== thisbuildproc) {
@@ -36,7 +38,8 @@ function run(changedFile) {
36 38 }
37 39 buildproc = undefined;
38 40 if (code === 0) {
39 runproc = spawn("npm", ["run", "start", "--", ...args], { stdio: "inherit", shell: true });
41 console.log(`${process.versions.bun ? "Verified" : "Built"} in ${Date.now() - thisbuildstart} ms`);
42 runproc = spawn("npm", ["run", process.versions.bun ? "bun-run" : "start", "--", ...args], spawnopts);
40 43 runproc.on("exit", () => {
41 44 runproc = undefined;
42 45 });
Modified src/services/configWatcherService.ts +6 -1
@@ -5,7 +5,12 @@ import { config, configPath, loadConfig } from "./configService";
5 5 import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService";
6 6
7 7 let amnesia = false;
8 fs.watchFile(configPath, () => {
8 fs.watchFile(configPath, (now, then) => {
9 // https://github.com/oven-sh/bun/issues/20542
10 if (process.versions.bun && now.mtimeMs == then.mtimeMs) {
11 return;
12 }
13
9 14 if (amnesia) {
10 15 amnesia = false;
11 16 } else {
Modified src/services/webService.ts +12 -7
@@ -46,16 +46,21 @@ export const startWebServer = (): void => {
46 46 "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
47 47 );
48 48
49 void runWsSelfTest("wss", httpsPort).then(ok => {
50 if (!ok) {
51 logger.warn(`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`);
52 if (process.platform == "win32") {
49 // https://github.com/oven-sh/bun/issues/20547
50 if (!process.versions.bun) {
51 void runWsSelfTest("wss", httpsPort).then(ok => {
52 if (!ok) {
53 53 logger.warn(
54 `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
54 `WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`
55 55 );
56 if (process.platform == "win32") {
57 logger.warn(
58 `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
59 );
60 }
56 61 }
57 }
58 });
62 });
63 }
59 64 });
60 65 });
61 66 };