Skip to content

Commit c08a9e1

Browse files
author
Ian McNally
committed
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.
1 parent abeca8a commit c08a9e1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/react-scripts/scripts/start.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,18 @@ function run(port) {
260260
}
261261

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

266266
try {
267-
return execSync(command, execOptions);
267+
var processIds = execSync(processesCommand, execOptions).match(/(\S+)/g);
268+
269+
var namedProcesses = processIds.map(function(processId) {
270+
var command = 'ps -o command -p ' + processId + ' | sed -n 2p | tr -d "\n"';
271+
return execSync(command, execOptions);
272+
});
273+
274+
return namedProcesses.join(',\n ');
268275
} catch(e) {
269276
return null;
270277
}

0 commit comments

Comments
 (0)