MCPcopy Index your code
hub / github.com/webpack/webpack-dev-server / getAvailablePort

Function getAvailablePort

lib/getPort.js:62–85  ·  view source on GitHub ↗
(port, hosts)

Source from the content-addressed store, hash-verified

60 * @returns {Promise<number>} resolved port
61 */
62const 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

Callers 1

getPortsFunction · 0.85

Calls 1

checkAvailablePortFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…