attio 0.0.1-experimental.20241007 → 0.0.1-experimental.20241007.1
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.
- package/lib/util/find-available-port.js +23 -18
- package/package.json +1 -1
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import net from "net";
|
|
2
|
-
|
|
3
|
-
return new Promise((resolve
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
server.listen(port);
|
|
18
|
-
};
|
|
19
|
-
tryPort(startPort);
|
|
2
|
+
async function isPortAvailable(port) {
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
const tester = net.createConnection(port, "127.0.0.1");
|
|
5
|
+
tester.once("error", (err) => {
|
|
6
|
+
if (err.code === "ECONNREFUSED") {
|
|
7
|
+
resolve(true);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
resolve(false);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
tester.once("connect", () => {
|
|
14
|
+
tester.end();
|
|
15
|
+
resolve(false);
|
|
16
|
+
});
|
|
20
17
|
});
|
|
21
18
|
}
|
|
19
|
+
export async function findAvailablePort(startPort, maxAttempts = 100) {
|
|
20
|
+
for (let port = startPort; port < startPort + maxAttempts; port++) {
|
|
21
|
+
if (await isPortAvailable(port)) {
|
|
22
|
+
return port;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Could not find an available port after ${maxAttempts} attempts`);
|
|
26
|
+
}
|