refactor: safely access Bun.main with optional chaining

This commit is contained in:
weishu
2025-12-26 12:40:44 +08:00
parent 76b84a0b52
commit 5d5023883e
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -6,7 +6,8 @@ import packageJson from '../package.json';
const __dirname = dirname(fileURLToPath(import.meta.url));
/** Bun embeds compiled code in a virtual filesystem: /$bunfs/ (Linux/macOS) or /~BUN/ (Windows) */
const isCompiled = Bun.main.includes('$bunfs') || Bun.main.includes('/~BUN/');
const bunMain = globalThis.Bun?.main ?? '';
const isCompiled = bunMain.includes('$bunfs') || bunMain.includes('/~BUN/');
export function projectPath(): string {
return resolve(__dirname, '..');
+2 -1
View File
@@ -1,4 +1,5 @@
/** 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/');
const bunMain = globalThis.Bun?.main ?? '';
return bunMain.includes('$bunfs') || bunMain.includes('/~BUN/');
}