import net from 'net';
function tryPort(port) {
    return new Promise((resolve) => {
        const server = net.createServer();
        server.once('error', () => resolve(false));
        server.once('listening', () => server.close(() => resolve(true)));
        server.listen(port, '0.0.0.0');
    });
}
export async function findFreePort(start, maxAttempts = 20) {
    for (let offset = 0; offset < maxAttempts; offset++) {
        if (await tryPort(start + offset))
            return start + offset;
    }
    throw new Error(`No free port found between ${start} and ${start + maxAttempts - 1}`);
}
//# sourceMappingURL=find-free-port.js.map