* Checks if the IDE connection is responding by testing if the port is open * @param host Host to connect to * @param port Port to connect to * @param timeout Optional timeout in milliseconds (defaults to 500ms) * @returns true if the port is open, false otherwise
( host: string, port: number, timeout = 500, )
| 400 | * @returns true if the port is open, false otherwise |
| 401 | */ |
| 402 | async function checkIdeConnection( |
| 403 | host: string, |
| 404 | port: number, |
| 405 | timeout = 500, |
| 406 | ): Promise<boolean> { |
| 407 | try { |
| 408 | return new Promise(resolve => { |
| 409 | const socket = createConnection({ |
| 410 | host: host, |
| 411 | port: port, |
| 412 | timeout: timeout, |
| 413 | }) |
| 414 | |
| 415 | socket.on('connect', () => { |
| 416 | socket.destroy() |
| 417 | void resolve(true) |
| 418 | }) |
| 419 | |
| 420 | socket.on('error', () => { |
| 421 | void resolve(false) |
| 422 | }) |
| 423 | |
| 424 | socket.on('timeout', () => { |
| 425 | socket.destroy() |
| 426 | void resolve(false) |
| 427 | }) |
| 428 | }) |
| 429 | } catch (_) { |
| 430 | // Invalid URL or other errors |
| 431 | return false |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Resolve the Windows USERPROFILE path. WSL often doesn't pass USERPROFILE |
no test coverage detected