Skip to content

Commit

Permalink
Add handling for multiple processes on a part
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Ian McNally committed Oct 4, 2016
1 parent abeca8a commit c08a9e1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/react-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,18 @@ function run(port) {
}

function getProcessNameOnPort(port) {
var command = 'ps -o command -p "$(lsof -i:' + port + ' -P -t)" | sed -n 2p | tr -d "\n"';
var execOptions = { encoding: 'utf8' };
var processesCommand = 'lsof -i:' + port + ' -P -t'

try {
return execSync(command, execOptions);
var processIds = execSync(processesCommand, execOptions).match(/(\S+)/g);

var namedProcesses = processIds.map(function(processId) {
var command = 'ps -o command -p ' + processId + ' | sed -n 2p | tr -d "\n"';
return execSync(command, execOptions);
});

return namedProcesses.join(',\n ');
} catch(e) {
return null;
}
Expand Down

0 comments on commit c08a9e1

Please sign in to comment.