MCPcopy
hub / github.com/web-infra-dev/rsbuild / getRandomPort

Function getRandomPort

e2e/helper/utils.ts:62–71  ·  view source on GitHub ↗
(defaultPort = Math.ceil(Math.random() * 30000) + 15000)

Source from the content-addressed store, hash-verified

60 * so we use `15000` ~ `45000`.
61 */
62export async function getRandomPort(defaultPort = Math.ceil(Math.random() * 30000) + 15000) {
63 let port = defaultPort;
64 while (true) {
65 if (!portMap.get(port) && (await isPortAvailable(port))) {
66 portMap.set(port, 1);
67 return port;
68 }
69 port++;
70 }
71}
72
73// fast-glob only accepts posix path
74// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath

Callers 15

index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
occupyPortFunction · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90

Calls 1

isPortAvailableFunction · 0.85

Tested by 2

occupyPortFunction · 0.72
occupyPortFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…