refactor: unify bun compiled detection with windows support

- Add shared isBunCompiled() function for consistent runtime detection
- Support Windows virtual filesystem paths (/~BUN/) alongside Linux/macOS (/$bunfs/)
- Use Bun.main for reliable detection instead of process.argv[1]
- Remove redundant $bunfs checks from cli/src/index.ts
- Update cli/src/utils/bunRuntime.ts to use shared detection function
- Create server/src/utils/bunCompiled.ts for server-side compilation check
This commit is contained in:
weishu
2025-12-26 11:29:12 +08:00
parent abec6d958d
commit 76b84a0b52
5 changed files with 12 additions and 13 deletions
+4
View File
@@ -0,0 +1,4 @@
/** Bun embeds compiled code in a virtual filesystem: /$bunfs/ (Linux/macOS) or /~BUN/ (Windows) */
export function isBunCompiled(): boolean {
return Bun.main.includes('$bunfs') || Bun.main.includes('/~BUN/');
}
+2 -1
View File
@@ -20,6 +20,7 @@ import type { Server as BunServer } from 'bun'
import type { Server as SocketEngine } from '@socket.io/bun-engine'
import type { WebSocketData } from '@socket.io/bun-engine'
import { loadEmbeddedAssetMap, type EmbeddedWebAsset } from './embeddedAssets'
import { isBunCompiled } from '../utils/bunCompiled'
function findWebappDistDir(): { distDir: string; indexHtmlPath: string } {
const candidates = [
@@ -163,7 +164,7 @@ export async function startWebServer(options: {
jwtSecret: Uint8Array
socketEngine: SocketEngine
}): Promise<BunServer<WebSocketData>> {
const isCompiled = Bun.main?.startsWith('/$bunfs') ?? false
const isCompiled = isBunCompiled()
const embeddedAssetMap = isCompiled ? await loadEmbeddedAssetMap() : null
const app = createWebApp({
getSyncEngine: options.getSyncEngine,