| 145 | } |
| 146 | |
| 147 | async function waitForPort(port: number, timeoutMs: number): Promise<boolean> { |
| 148 | const deadline = Date.now() + timeoutMs; |
| 149 | while (Date.now() < deadline) { |
| 150 | try { |
| 151 | const res = await fetch(`http://127.0.0.1:${port}/`, { method: "HEAD" }); |
| 152 | // Any HTTP response means vite's listening. |
| 153 | if (res) return true; |
| 154 | } catch { |
| 155 | // Connection refused — keep waiting. |
| 156 | } |
| 157 | await new Promise((r) => setTimeout(r, 150)); |
| 158 | } |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | function openInBrowser(url: string): void { |
| 163 | const platform = process.platform; |