-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add logging of existing default port process on start #816
add logging of existing default port process on start #816
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
965a68c
to
626c8d0
Compare
Let's keep the message intact but add a colon at the end and print the process name indented with two spaces on next line? This way the line wouldn't be so long. What do you think? |
Yeah, I think that's better. The original wording, taken from #454, felt a little off with the whole line. Changing now. Thanks! |
I would try to make second line of different color (cyan?). Also, if the command matches our own (so we know it's a CRA repo), is there any way to figure out which directory it is running from? It would be nice to just display the repo name/directory instead if we know for sure this is another CRA instance. |
- With the currently process filtering, if multiple processes are returned as running on port 3000, this command would fail. This splits apart the process IDing and the process naming, to support multiple processes. - One curious thing about the bash command to get processes, is that it'll include browsers with a window open on localhost:3000. May want to reconsider that.
Hey Dan, In abeca8a I add coloring to the process name, as requested: That uncovered a couple things, mentioned in the last commit:
So, as far as wrapping this ticket up, I'm wondering what you consider the MVP. Could we live with this as is, and refine both the repo/directory identification and the browser-caught-as-a-process? Or would you like to see one or both of them solved before merging this in? |
Wanted to leave a note here. I did get something working for getting the working directory of a process. Maybe we can solicit feedback on it? With CRA already running:
Based on my Googling, lsof with grep is the only mac-compatible way to search for the directory. |
hey @gaearon, based on my notes above, I added the command's directory in the output in 504efb6: I thought coloring them differently would help readability, but I guessed on colors. Let me know what you think. The only remaining quirk is that this'll show your browser if you're on localhost:3000. Wondering if that's an acceptable tradeoff and we can ? |
- also moved terminal coloring up, when getting the process, to be able to distinguish the process command from the directory
504efb6
to
e8d0053
Compare
Pushed a slight tweak in e3dcaaf to only color "in" since it's our wording. And keeping the process command and directory in the same color visually links them. E.g., |
- better reflects its broadened scope (both command and directory)
aa899b6
to
9c2e3aa
Compare
backed off the custom CRA message (above) since a CRA-based app doesn't have the same access to CRA's package.json. |
I don't see a commit that backs it off, did you push it? Can you clarify in more detail why it didn't work? |
} | ||
|
||
function getProcessIdsOnPort(port) { | ||
return execSync('lsof -i:' + port + ' -P -t', execOptions).match(/(\S+)/g); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's modify the command so that we only get listening processes. Adding -sTCP:LISTEN
should do the trick.
Otherwise looks great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excellent find, thanks @fson. i'll add it in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to detect/support Windows here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to not support Windows for "niceties" like this as long as there's a reasonable fallback and it doesn't crash.
Somebody can then add Windows-specific code in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, just want to make sure it doesn't crash.
- Removed the handling of multiple process IDs since you can filtering by listening process (and not have the browser in the list of processes) - Trimmed the terminal outputs for better matching (process id) and better terminal output (directory of process)
Won't this break for any Windows user trying to run |
I don't think so, there's a try/catch there. |
We could probably fix that by ignoring the error stream (stderr) from the child process. |
@existentialism FYI, you should get an invitation to be a repo collaborator for your PRs and help reviewing changes. |
CI is failing with the error:
Anyone seen that before? Update: look like some flakiness in the build. Back to green! |
- Make sure any potential errors don't leak to the user
Nice work, thank you @ianmcnally! 👍 |
@ianmcnally nice work! |
* add logging of existing port process on start * Move port process wording in start command on to next line * Color the named processes as cyan in terminal output * Add handling for multiple processes on a part - With the currently process filtering, if multiple processes are returned as running on port 3000, this command would fail. This splits apart the process IDing and the process naming, to support multiple processes. - One curious thing about the bash command to get processes, is that it'll include browsers with a window open on localhost:3000. May want to reconsider that. * Add process directory to existing port warning - also moved terminal coloring up, when getting the process, to be able to distinguish the process command from the directory * Change output color to all cyan, except "in" * Rename getProcessNameOnPort -> getProcessForPort - better reflects its broadened scope (both command and directory) * Add checking if process is a CRA instance, to customize port running message - moved from using package.json to a regex, for reliability * Move getProcessForPort to react-dev-utils - also allowed for breakdown of commands into helper methods * Add documentation for getProcessForPort * Add getProcessForPort to list of dev-scripts files * Use app's package name when CRA app is running on another port * Filter port process by those listening - Removed the handling of multiple process IDs since you can filtering by listening process (and not have the browser in the list of processes) - Trimmed the terminal outputs for better matching (process id) and better terminal output (directory of process) * Update README on port helpers, to specify only one port returned * Add ignore of stderr when executing process commands - Make sure any potential errors don't leak to the user
* add logging of existing port process on start * Move port process wording in start command on to next line * Color the named processes as cyan in terminal output * Add handling for multiple processes on a part - With the currently process filtering, if multiple processes are returned as running on port 3000, this command would fail. This splits apart the process IDing and the process naming, to support multiple processes. - One curious thing about the bash command to get processes, is that it'll include browsers with a window open on localhost:3000. May want to reconsider that. * Add process directory to existing port warning - also moved terminal coloring up, when getting the process, to be able to distinguish the process command from the directory * Change output color to all cyan, except "in" * Rename getProcessNameOnPort -> getProcessForPort - better reflects its broadened scope (both command and directory) * Add checking if process is a CRA instance, to customize port running message - moved from using package.json to a regex, for reliability * Move getProcessForPort to react-dev-utils - also allowed for breakdown of commands into helper methods * Add documentation for getProcessForPort * Add getProcessForPort to list of dev-scripts files * Use app's package name when CRA app is running on another port * Filter port process by those listening - Removed the handling of multiple process IDs since you can filtering by listening process (and not have the browser in the list of processes) - Trimmed the terminal outputs for better matching (process id) and better terminal output (directory of process) * Update README on port helpers, to specify only one port returned * Add ignore of stderr when executing process commands - Make sure any potential errors don't leak to the user
* add logging of existing port process on start * Move port process wording in start command on to next line * Color the named processes as cyan in terminal output * Add handling for multiple processes on a part - With the currently process filtering, if multiple processes are returned as running on port 3000, this command would fail. This splits apart the process IDing and the process naming, to support multiple processes. - One curious thing about the bash command to get processes, is that it'll include browsers with a window open on localhost:3000. May want to reconsider that. * Add process directory to existing port warning - also moved terminal coloring up, when getting the process, to be able to distinguish the process command from the directory * Change output color to all cyan, except "in" * Rename getProcessNameOnPort -> getProcessForPort - better reflects its broadened scope (both command and directory) * Add checking if process is a CRA instance, to customize port running message - moved from using package.json to a regex, for reliability * Move getProcessForPort to react-dev-utils - also allowed for breakdown of commands into helper methods * Add documentation for getProcessForPort * Add getProcessForPort to list of dev-scripts files * Use app's package name when CRA app is running on another port * Filter port process by those listening - Removed the handling of multiple process IDs since you can filtering by listening process (and not have the browser in the list of processes) - Trimmed the terminal outputs for better matching (process id) and better terminal output (directory of process) * Update README on port helpers, to specify only one port returned * Add ignore of stderr when executing process commands - Make sure any potential errors don't leak to the user
Hello awesome contributors,
In #441, there are was a request to guess the name of the existing process running on the default port when starting CRA. So, building on the incomplete yet solid work done in #454, this PR aims to complete that feature.
with a CRA app process found
It shows the app's name and directory.
Note:
my-test-app
is the name of a CRA app in~/dev/test2
with a non-CRA process found
It shows the command name and directory.
without a process found
It shows the original, generic message.