( env: Record<string, string | undefined> = process.env, metaDir: string = import.meta.dir, execPath: string = process.execPath )
| 24 | const MAX_START_WAIT = IS_WINDOWS ? 15000 : (process.env.CI ? 30000 : 8000); // Node+Chromium takes longer on Windows |
| 25 | |
| 26 | export function resolveServerScript( |
| 27 | env: Record<string, string | undefined> = process.env, |
| 28 | metaDir: string = import.meta.dir, |
| 29 | execPath: string = process.execPath |
| 30 | ): string { |
| 31 | if (env.BROWSE_SERVER_SCRIPT) { |
| 32 | return env.BROWSE_SERVER_SCRIPT; |
| 33 | } |
| 34 | |
| 35 | // Dev mode: cli.ts runs directly from browse/src |
| 36 | // On macOS/Linux, import.meta.dir starts with / |
| 37 | // On Windows, it starts with a drive letter (e.g., C:\...) |
| 38 | if (!metaDir.includes('$bunfs')) { |
| 39 | const direct = path.resolve(metaDir, 'server.ts'); |
| 40 | if (fs.existsSync(direct)) { |
| 41 | return direct; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Compiled binary: derive the source tree from browse/dist/browse |
| 46 | if (execPath) { |
| 47 | const adjacent = path.resolve(path.dirname(execPath), '..', 'src', 'server.ts'); |
| 48 | if (fs.existsSync(adjacent)) { |
| 49 | return adjacent; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | throw new Error( |
| 54 | 'Cannot find server.ts. Set BROWSE_SERVER_SCRIPT env or run from the browse source tree.' |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | const SERVER_SCRIPT = resolveServerScript(); |
| 59 |
no outgoing calls
no test coverage detected