(port, hosts)
| 60 | * @returns {Promise<number>} resolved port |
| 61 | */ |
| 62 | const getAvailablePort = async (port, hosts) => { |
| 63 | /** |
| 64 | * Errors that mean that host is not available. |
| 65 | * @type {Set<string | undefined>} |
| 66 | */ |
| 67 | const nonExistentInterfaceErrors = new Set(["EADDRNOTAVAIL", "EINVAL"]); |
| 68 | /* Check if the post is available on every local host name */ |
| 69 | for (const host of hosts) { |
| 70 | try { |
| 71 | await checkAvailablePort(port, host); |
| 72 | } catch (error) { |
| 73 | /* We throw an error only if the interface exists */ |
| 74 | if ( |
| 75 | !nonExistentInterfaceErrors.has( |
| 76 | /** @type {NodeJS.ErrnoException} */ (error).code, |
| 77 | ) |
| 78 | ) { |
| 79 | throw error; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return port; |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * @param {number} basePort base port |
no test coverage detected
searching dependent graphs…