chore: add bun support #2254
@ -8,8 +8,11 @@
 | 
				
			|||||||
    "build": "tsc --incremental --sourceMap && ncp static/webui build/static/webui",
 | 
					    "build": "tsc --incremental --sourceMap && ncp static/webui build/static/webui",
 | 
				
			||||||
    "build:dev": "tsc --incremental --sourceMap",
 | 
					    "build:dev": "tsc --incremental --sourceMap",
 | 
				
			||||||
    "build-and-start": "npm run build && npm run start",
 | 
					    "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": "node scripts/dev.js",
 | 
				
			||||||
 | 
					    "dev:bun": "bun scripts/dev.js",
 | 
				
			||||||
    "verify": "tsgo --noEmit",
 | 
					    "verify": "tsgo --noEmit",
 | 
				
			||||||
 | 
					    "bun-run": "bun src/index.ts",
 | 
				
			||||||
    "lint": "eslint --ext .ts .",
 | 
					    "lint": "eslint --ext .ts .",
 | 
				
			||||||
    "lint:ci": "eslint --ext .ts --rule \"prettier/prettier: off\" .",
 | 
					    "lint:ci": "eslint --ext .ts --rule \"prettier/prettier: off\" .",
 | 
				
			||||||
    "lint:fix": "eslint --fix --ext .ts .",
 | 
					    "lint:fix": "eslint --fix --ext .ts .",
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,8 @@ function run(changedFile) {
 | 
				
			|||||||
        runproc = undefined;
 | 
					        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 = thisbuildproc;
 | 
				
			||||||
    buildproc.on("exit", code => {
 | 
					    buildproc.on("exit", code => {
 | 
				
			||||||
        if (buildproc !== thisbuildproc) {
 | 
					        if (buildproc !== thisbuildproc) {
 | 
				
			||||||
@ -36,7 +37,8 @@ function run(changedFile) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        buildproc = undefined;
 | 
					        buildproc = undefined;
 | 
				
			||||||
        if (code === 0) {
 | 
					        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.on("exit", () => {
 | 
				
			||||||
                runproc = undefined;
 | 
					                runproc = undefined;
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,12 @@ import { config, configPath, loadConfig } from "./configService";
 | 
				
			|||||||
import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService";
 | 
					import { getWebPorts, sendWsBroadcast, startWebServer, stopWebServer } from "./webService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let amnesia = false;
 | 
					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) {
 | 
					    if (amnesia) {
 | 
				
			||||||
        amnesia = false;
 | 
					        amnesia = false;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -46,9 +46,13 @@ export const startWebServer = (): void => {
 | 
				
			|||||||
                "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
 | 
					                "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // https://github.com/oven-sh/bun/issues/20547
 | 
				
			||||||
 | 
					            if (!process.versions.bun) {
 | 
				
			||||||
                void runWsSelfTest("wss", httpsPort).then(ok => {
 | 
					                void runWsSelfTest("wss", httpsPort).then(ok => {
 | 
				
			||||||
                    if (!ok) {
 | 
					                    if (!ok) {
 | 
				
			||||||
                    logger.warn(`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`);
 | 
					                        logger.warn(
 | 
				
			||||||
 | 
					                            `WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`
 | 
				
			||||||
 | 
					                        );
 | 
				
			||||||
                        if (process.platform == "win32") {
 | 
					                        if (process.platform == "win32") {
 | 
				
			||||||
                            logger.warn(
 | 
					                            logger.warn(
 | 
				
			||||||
                                `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
 | 
					                                `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
 | 
				
			||||||
@ -56,6 +60,7 @@ export const startWebServer = (): void => {
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user