* @param {Port} port port * @param {string} host host * @returns {Promise } free port
(port, host)
| 521 | * @returns {Promise<number | string>} free port |
| 522 | */ |
| 523 | static async getFreePort(port, host) { |
| 524 | if (typeof port !== "undefined" && port !== null && port !== "auto") { |
| 525 | return port; |
| 526 | } |
| 527 | |
| 528 | const { default: pRetry } = await import("p-retry"); |
| 529 | const { default: getPort } = await import("./getPort.js"); |
| 530 | |
| 531 | const basePort = |
| 532 | typeof process.env.WEBPACK_DEV_SERVER_BASE_PORT !== "undefined" |
| 533 | ? Number.parseInt(process.env.WEBPACK_DEV_SERVER_BASE_PORT, 10) |
| 534 | : 8080; |
| 535 | |
| 536 | // Try to find unused port and listen on it for 3 times, |
| 537 | // if port is not specified in options. |
| 538 | const defaultPortRetry = |
| 539 | typeof process.env.WEBPACK_DEV_SERVER_PORT_RETRY !== "undefined" |
| 540 | ? Number.parseInt(process.env.WEBPACK_DEV_SERVER_PORT_RETRY, 10) |
| 541 | : 3; |
| 542 | |
| 543 | return pRetry(() => getPort(basePort, host), { |
| 544 | retries: defaultPortRetry, |
| 545 | }); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * @returns {string} path to cache dir |
no outgoing calls
no test coverage detected