-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Expand file tree
/
Copy pathbundledMode.ts
More file actions
27 lines (26 loc) · 862 Bytes
/
bundledMode.ts
File metadata and controls
27 lines (26 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Detects if the current runtime is Bun.
* Returns true when:
* - Running a JS file via the `bun` command
* - Running a Bun-compiled standalone executable
*/
export function isRunningWithBun(): boolean {
// https://bun.com/guides/util/detect-bun
return process.versions.bun !== undefined
}
/**
* Detects if running as a Bun-compiled standalone executable.
*
* Primary check: Bun.embeddedFiles (present in compiled binaries).
* Fallback: BUNDLED_MODE compile-time constant injected by compile.ts.
*/
// BUNDLED_MODE is injected at compile time by compile.ts --define flag.
declare const BUNDLED_MODE: string | undefined
export function isInBundledMode(): boolean {
if (typeof BUNDLED_MODE !== 'undefined') return true
return (
typeof Bun !== 'undefined' &&
Array.isArray(Bun.embeddedFiles) &&
Bun.embeddedFiles.length > 0
)
}