| 221 | |
| 222 | /** True when an error (or any nested cause) is an EADDRINUSE bind failure. */ |
| 223 | export const isAddrInUse = (error: unknown): boolean => { |
| 224 | for (let cursor: unknown = error; cursor instanceof Error; cursor = cursor.cause) { |
| 225 | if ((cursor as NodeJS.ErrnoException).code === "EADDRINUSE") return true; |
| 226 | // The emulate/vite boot glue wraps the OS error in a plain Error whose |
| 227 | // message carries the code, so match the text too. |
| 228 | if (/EADDRINUSE/.test(cursor.message)) return true; |
| 229 | } |
| 230 | return false; |
| 231 | }; |
| 232 | |
| 233 | /** |
| 234 | * Claim a port block and boot the services that bind it, retrying on EADDRINUSE. |