-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Port in use checking for development server (#6437)
* Initial port in use check implementation * Added suggested port, initial prompt and ensured consistent logging styles * Removed excess style import * Changed to use node-portfinder, tidied console logging and added initial port suggestion usage * fix(deps): pin portfinder and dedupe yarn.lock * Improved conditionals Co-authored-by: Dominic Saadi <[email protected]> * Added port flag to the watch api-server * Added working port checking * Made ports consistently a number type, fixed typo in port use warning and removed stray console log * Added default port options to mock config and updated inline snapshot to include --port flag * Apply suggestions from code review Co-authored-by: Dominic Saadi <[email protected]> * Applying more suggestions from code review * Changed to a simple error warning * style: remove "=" after flag this is valid but we don't do it for debugPort so just chasing consistency * fix: substring test and snapshot * Apply suggestions from code review Co-authored-by: Dominic Saadi <[email protected]> * Remove unused function Co-authored-by: Dominic Saadi <[email protected]>
- Loading branch information
1 parent
e607f1e
commit 8f9cbd7
Showing
6 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import portfinder from 'portfinder' | ||
|
||
/** | ||
* Finds a free port | ||
* @param {[number]} requestedPort Port to start searching from | ||
* @param {[number[]]} excludePorts Array of port numbers to exclude | ||
* @return {[number]} A free port equal or higher than requestedPort but not within excludePorts. If no port can be found then returns -1 | ||
*/ | ||
export async function getFreePort(requestedPort, excludePorts = []) { | ||
try { | ||
let freePort = await portfinder.getPortPromise({ | ||
port: requestedPort, | ||
}) | ||
if (excludePorts.includes(freePort)) { | ||
freePort = await getFreePort(freePort + 1, excludePorts) | ||
} | ||
return freePort | ||
} catch (error) { | ||
return -1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters