diff --git a/package-lock.json b/package-lock.json index ec65974..41ad76b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ }, "devDependencies": { "eslint": "^8.36.0", - "get-port": "^6.1.2", "rollup": "^4.9.5", "tap": "^18.4.2" }, @@ -2702,18 +2701,6 @@ "node": "6.* || 8.* || >= 10.*" } }, - "node_modules/get-port": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", - "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", - "dev": true, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -7605,12 +7592,6 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, - "get-port": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", - "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", - "dev": true - }, "glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", diff --git a/package.json b/package.json index b372d53..653b56d 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ }, "devDependencies": { "eslint": "^8.36.0", - "get-port": "^6.1.2", "rollup": "^4.9.5", "tap": "^18.4.2" } diff --git a/rollup.config.mjs b/rollup.config.mjs index 0058dee..d895f0f 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -77,7 +77,6 @@ function walkTest(config) { }, external: [ 'node:dgram', - 'get-port', 'node-osc', 'osc-min', 'tap', diff --git a/test/util.mjs b/test/util.mjs index 3d2bac1..4210f4f 100644 --- a/test/util.mjs +++ b/test/util.mjs @@ -1,8 +1,29 @@ -async function bootstrap(t) { - const {default: getPorts, portNumbers} = await import('get-port'); - const port = await getPorts({ - port: portNumbers(3000, 3500) +import { createSocket } from 'node:dgram'; + +// A custom getPort function that returns a promise that resolves with a random port within a range that is available +function getPort(min = 3000, max = 3500) { + return new Promise((resolve) => { + // Create a socket + const socket = createSocket('udp4'); + // Generate a random port within the range + const port = Math.floor(Math.random() * (max - min + 1)) + min; + // Try to bind the socket to the port + socket.bind(port, (err) => { + if (err) { + // If there is an error, try again with a different port + socket.close(); + resolve(getPort(min, max)); + } else { + // If successful, close the socket and resolve the promise with the port + socket.close(); + resolve(port); + } + }); }); +} + +async function bootstrap(t) { + const port = await getPort(3000, 3500); t.context = { port };