* 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, )
| 421 | * @returns true if the port is open, false otherwise |
| 422 | */ |
| 423 | async function checkIdeConnection( |
| 424 | host: string, |
| 425 | port: number, |
| 426 | timeout = 500, |
| 427 | ): Promise<boolean> { |
| 428 | try { |
| 429 | return new Promise(resolve => { |
| 430 | const socket = createConnection({ |
| 431 | host: host, |
| 432 | port: port, |
| 433 | timeout: timeout, |
| 434 | }) |
| 435 | |
| 436 | socket.on('connect', () => { |
| 437 | socket.destroy() |
| 438 | void resolve(true) |
| 439 | }) |
| 440 | |
| 441 | socket.on('error', () => { |
| 442 | void resolve(false) |
| 443 | }) |
| 444 | |
| 445 | socket.on('timeout', () => { |
| 446 | socket.destroy() |
| 447 | void resolve(false) |
| 448 | }) |
| 449 | }) |
| 450 | } catch (_) { |
| 451 | // Invalid URL or other errors |
| 452 | return false |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Resolve the Windows USERPROFILE path. WSL often doesn't pass USERPROFILE |
no test coverage detected