( url: string, platform: NodeJS.Platform, override?: string )
| 25 | * without launching anything. |
| 26 | */ |
| 27 | export function browserOpenCommand( |
| 28 | url: string, |
| 29 | platform: NodeJS.Platform, |
| 30 | override?: string |
| 31 | ): OpenCommand | null { |
| 32 | if (override !== undefined) { |
| 33 | const trimmed = override.trim(); |
| 34 | if (SUPPRESS_VALUES.has(trimmed.toLowerCase())) return null; |
| 35 | // Windows: go through `cmd /c` rather than spawning the override directly. |
| 36 | // `spawn` there is CreateProcess, which only ever launches a real .exe — a |
| 37 | // `.cmd`/`.bat` browser shim (how most Windows wrappers are written) fails |
| 38 | // outright, and an extension-less name only resolves because CreateProcess |
| 39 | // appends `.exe`. Routing through cmd makes .exe, .cmd and .bat all work, |
| 40 | // and node quotes each argument, so a path with spaces survives. Caught on |
| 41 | // the Windows VM, where the direct spawn silently launched nothing. |
| 42 | if (platform === 'win32') return { command: 'cmd', args: ['/c', trimmed, url] }; |
| 43 | return { command: trimmed, args: [url] }; |
| 44 | } |
| 45 | if (platform === 'darwin') return { command: 'open', args: [url] }; |
| 46 | if (platform === 'win32') { |
| 47 | // `start` is a cmd builtin, not an executable. The empty string is the |
| 48 | // window title — without it `start` treats a quoted URL as the title and |
| 49 | // opens a blank console instead. |
| 50 | return { command: 'cmd', args: ['/c', 'start', '', url] }; |
| 51 | } |
| 52 | return { command: 'xdg-open', args: [url] }; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Open `url` in the user's default browser, best effort. |
no test coverage detected