Skip to content

Commit e8d0053

Browse files
committed
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
1 parent c08a9e1 commit e8d0053

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/react-scripts/scripts/start.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,17 @@ function run(port) {
261261

262262
function getProcessNameOnPort(port) {
263263
var execOptions = { encoding: 'utf8' };
264-
var processesCommand = 'lsof -i:' + port + ' -P -t'
265264

266265
try {
267-
var processIds = execSync(processesCommand, execOptions).match(/(\S+)/g);
266+
var processIds = execSync('lsof -i:' + port + ' -P -t', execOptions).match(/(\S+)/g);
268267

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);
268+
var processCommandsAndDirectories = processIds.map(function(processId) {
269+
var processCommand = execSync('ps -o command -p ' + processId + ' | sed -n 2p', execOptions);
270+
var processDirectory = execSync('lsof -p '+ processId + ' | grep cwd | awk \'{print " in " $9}\'', execOptions);
271+
return chalk.blue(processCommand) + chalk.cyan(processDirectory);
272272
});
273273

274-
return namedProcesses.join(',\n ');
274+
return processCommandsAndDirectories.join('\n ');
275275
} catch(e) {
276276
return null;
277277
}
@@ -289,7 +289,7 @@ detect(DEFAULT_PORT).then(port => {
289289
var existingProcess = getProcessNameOnPort(DEFAULT_PORT);
290290
var question =
291291
chalk.yellow('Something is already running on port ' + DEFAULT_PORT + '.' +
292-
((existingProcess) ? ' Probably:\n ' + chalk.cyan(existingProcess) : '')) +
292+
((existingProcess) ? ' Probably:\n ' + existingProcess : '')) +
293293
'\n\nWould you like to run the app on another port instead?';
294294

295295
prompt(question, true).then(shouldChangePort => {

0 commit comments

Comments
 (0)