-
Notifications
You must be signed in to change notification settings - Fork 928
Description
Describe the Feature
Running new app should work no matter if there has been other apps running (with packager) - ideally they would not collide.
Currently if you have an app already running in debug, it has it's packager running (by default in port 8081). When you try to run a second app, it will not spawn a launcher due to finding 8081 part having a packager already running. This will try to run the second app in the first apps packager, which will fail with an error:
This is unnecessary friction and requires manually killing the terminal each time you are switching to dev another application (or define the port yourself).
Possible Implementations
I did a twitter poll to see the expectations, here are the results
This confirmed my own feeling: Best option would be not to mess with the already running app. Instead, we would find a new port to run it.
I did some experimentations and based on those here is my proposed solution:
- If
--port
is used and is not the default (8081) try to use the specified port. If it is in use, we don't launch packager - you are manually requesting the port and we don't want to change it - If default port, we check for running processes listening in TCP range 8081-8089 (for example)
- We check if any of those is packager instance for the app we want to run (for example, slight modification for /status that stores also the project root). If yes, we don't launch a new packager, but use the existing one
- Find first free port in the range (again, 8081-8089 for example) and launch packager there
This would replace the current logic:
- If defined port (default 8081) is in use and it's status is
running
, don't do anything - Otherwise try launching a new packager in the port - fail if not able to
POC
I have a POC for iOS locally very close to working, but I wanted to make sure this would be something that is wanted before going forward and finishing it. Android side of implementation is pending still as well.
Changes required so far:
- Slight modification for
cli-server-api
statusMiddleWare (/status
), so it returns JSON with running status and projectRoot (so we can later check if the running packager is for the current project or not) - Start packager bin/sh script changes to do steps 1-4 listed in the proposed solution
Any comments on the proposed solution? Some reasons why it wouldn't work or not wanted to have in the first place? Any changes requested / required? Good to go? If all is good, I'll keep working on this and make a PR out of it.