Skip to content

Commit 89ffa37

Browse files
committed
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)
1 parent 43fd7bc commit 89ffa37

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

packages/react-dev-utils/getProcessForPort.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function isProcessAReactApp(processCommand) {
88
return /^node .*react-scripts\/scripts\/start\.js\s?$/.test(processCommand);
99
}
1010

11-
function getProcessIdsOnPort(port) {
12-
return execSync('lsof -i:' + port + ' -P -t', execOptions).match(/(\S+)/g);
11+
function getProcessIdOnPort(port) {
12+
return execSync('lsof -i:' + port + ' -P -t -sTCP:LISTEN', execOptions).trim();
1313
}
1414

1515
function getPackageNameInDirectory(directory) {
@@ -36,20 +36,15 @@ function getProcessCommand(processId, processDirectory) {
3636
}
3737

3838
function getDirectoryOfProcessById(processId) {
39-
return execSync('lsof -p '+ processId + ' | grep cwd | awk \'{print $9}\'', execOptions);
39+
return execSync('lsof -p '+ processId + ' | grep cwd | awk \'{print $9}\'', execOptions).trim();
4040
}
4141

4242
function getProcessForPort(port) {
4343
try {
44-
var processIds = getProcessIdsOnPort(port);
45-
46-
var processCommandsAndDirectories = processIds.map(function(processId) {
47-
var directory = getDirectoryOfProcessById(processId);
48-
var command = getProcessCommand(processId, directory);
49-
return chalk.cyan(command) + chalk.blue(' in ') + chalk.cyan(directory);
50-
});
51-
52-
return processCommandsAndDirectories.join('\n ');
44+
var processId = getProcessIdOnPort(port);
45+
var directory = getDirectoryOfProcessById(processId);
46+
var command = getProcessCommand(processId, directory);
47+
return chalk.cyan(command) + chalk.blue(' in ') + chalk.cyan(directory);
5348
} catch(e) {
5449
return null;
5550
}

0 commit comments

Comments
 (0)