feat(smartnetwork): Add exclude option to findFreePort and skip excluded ports during search

This commit is contained in:
2025-09-12 18:26:56 +00:00
parent 6e59f0f5c0
commit 0f79773985
4 changed files with 37 additions and 1 deletions

View File

@@ -99,6 +99,19 @@ const findFreePort = async () => {
// Find a random free port in range (useful to avoid port conflicts)
const randomPort = await network.findFreePort(3000, 3100, { randomize: true });
console.log(`🎲 Random free port: ${randomPort}`);
// Exclude specific ports from the search
const portWithExclusions = await network.findFreePort(3000, 3100, {
exclude: [3000, 3001, 3005] // Skip these ports even if they're free
});
console.log(`🚫 Free port (excluding specific ports): ${portWithExclusions}`);
// Combine randomize with exclude options
const randomWithExclusions = await network.findFreePort(3000, 3100, {
randomize: true,
exclude: [3000, 3001, 3005]
});
console.log(`🎲🚫 Random free port (with exclusions): ${randomWithExclusions}`);
};
```
@@ -333,6 +346,7 @@ interface SmartNetworkOptions {
interface IFindFreePortOptions {
randomize?: boolean; // If true, returns a random free port instead of the first one
exclude?: number[]; // Array of port numbers to exclude from the search
}
interface Hop {