@open-mercato/cli 0.6.5-develop.4718.1.56d834bb34 → 0.6.5-develop.4734.1.dd8285dd2e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -753,10 +753,17 @@ async function shouldRebuildBuildArtifacts(ttlSeconds, logPrefix, options = {})
753
753
  return !await shouldReuseBuildArtifacts(ttlSeconds, logPrefix, options);
754
754
  }
755
755
  async function getFreePort() {
756
- return new Promise((resolve, reject) => {
756
+ const tryListen = (host) => new Promise((resolve, reject) => {
757
757
  const server = createServer();
758
- server.on("error", reject);
759
- server.listen(0, "127.0.0.1", () => {
758
+ server.on("error", (error) => {
759
+ const errorCode = error.code;
760
+ if (errorCode === "EAFNOSUPPORT") {
761
+ resolve(null);
762
+ return;
763
+ }
764
+ reject(error);
765
+ });
766
+ server.listen(0, host, () => {
760
767
  const address = server.address();
761
768
  if (!address || typeof address === "string") {
762
769
  server.close();
@@ -773,6 +780,7 @@ async function getFreePort() {
773
780
  });
774
781
  });
775
782
  });
783
+ return await tryListen("::") ?? await tryListen("127.0.0.1") ?? Promise.reject(new Error("Unable to allocate free port"));
776
784
  }
777
785
  async function isPortAvailable(port) {
778
786
  const canBind = (host) => new Promise((resolve) => {
@@ -791,15 +799,15 @@ async function isPortAvailable(port) {
791
799
  });
792
800
  });
793
801
  });
794
- const ipv4Availability = await canBind("127.0.0.1");
795
- if (ipv4Availability === false) {
802
+ const wildcardIpv6Availability = await canBind("::");
803
+ if (wildcardIpv6Availability === false) {
796
804
  return false;
797
805
  }
798
- const ipv6Availability = await canBind("::1");
799
- if (ipv6Availability === false) {
806
+ const ipv4Availability = await canBind("127.0.0.1");
807
+ if (ipv4Availability === false) {
800
808
  return false;
801
809
  }
802
- return ipv4Availability === true || ipv6Availability === true;
810
+ return wildcardIpv6Availability === true || ipv4Availability === true;
803
811
  }
804
812
  async function getPreferredPort(preferredPort) {
805
813
  if (await isPortAvailable(preferredPort)) {