import { dirname } from "node:path"; import { fileURLToPath } from "node:url"; export function isCompiledBinary(execPath = process.execPath, metaUrl = import.meta.url): boolean { if (metaUrl.includes("/$bunfs/") || metaUrl.includes("\\$bunfs\\")) { return true; } const lower = execPath.toLowerCase().replace(/\\/g, "/"); return !lower.endsWith("/bun") && !lower.endsWith("/bun.exe"); } export function resolveAppRoot(entryFile?: string, isCompiled = isCompiledBinary()): string { if (isCompiled) { return process.cwd(); } const file = entryFile || fileURLToPath(import.meta.url); return dirname(dirname(file)); } export type LauncherConfig = { command: string; args?: string[]; }; export function resolveDefaultLauncher( entryFile: string, isCompiled = isCompiledBinary(), execPath = process.execPath ): LauncherConfig { if (isCompiled) { return { command: execPath, args: [], }; } return { command: execPath, args: [entryFile], }; }