checkAvailablePort = (basePort, host) =>
  new Promise((resolve, reject) => {
    const server = net.createServer();
    server.unref();
    server.on("error", reject);

    server.listen(basePort, host, () => {
      // Next line should return AddressInfo because we're calling it after listen() and before close()
      const { port } = /** @type {import("net").AddressInfo} */ (
        server.address()
      );
      server.close(() => {
        resolve(port);
      });
    });
  })
@param {number} basePort
@param {string | undefined} host
@return {Promise<number>}