Skip to content

Commit 3d92d2c

Browse files
jamschaleclarson
authored andcommitted
Add missing "--terminal" argument to run-android (facebook#20584)
Summary: Commit 79e498b claims that "--terminal" has been added as an argument to the "run-android" script which it hasn't. Instead it adds a new environment variable "process.env.REACT_TERMINAL" which seems to be undocumented and nowhere else in the repository. This commit now allows Linux and OSX users to specify their custom terminal : react-native run-android --terminal=x-terminal-emulator Additionally the metro bundler child process "detached" option has been set to false if no terminal has been specified on Linux which fixes an issue where the packager would be running in the background and would have to manually be closed by finding the process. Fixes facebook#18122 Pull Request resolved: facebook#20584 Differential Revision: D9234990 Pulled By: hramos fbshipit-source-id: 60e4cc57b2790c419d5a4f9027add04313ddf6f8
1 parent 35a5933 commit 3d92d2c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Diff for: local-cli/runAndroid/runAndroid.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function runAndroid(argv, config, args) {
6060
} else {
6161
// result == 'not_running'
6262
console.log(chalk.bold('Starting JS server...'));
63-
startServerInNewWindow(args.port);
63+
startServerInNewWindow(args.port, args.terminal);
6464
}
6565
return buildAndRun(args);
6666
});
@@ -348,7 +348,7 @@ function runOnAllDevices(
348348
}
349349
}
350350

351-
function startServerInNewWindow(port) {
351+
function startServerInNewWindow(port, terminal = process.env.REACT_TERMINAL) {
352352
// set up OS-specific filenames and commands
353353
const isWindows = /^win/.test(process.platform);
354354
const scriptFile = isWindows
@@ -363,7 +363,6 @@ function startServerInNewWindow(port) {
363363
const scriptsDir = path.resolve(__dirname, '..', '..', 'scripts');
364364
const launchPackagerScript = path.resolve(scriptsDir, scriptFile);
365365
const procConfig = {cwd: scriptsDir};
366-
const terminal = process.env.REACT_TERMINAL;
367366

368367
// set up the .packager.(env|bat) file to ensure the packager starts on the right port
369368
const packagerEnvFile = path.join(
@@ -390,14 +389,16 @@ function startServerInNewWindow(port) {
390389
}
391390
return child_process.spawnSync('open', [launchPackagerScript], procConfig);
392391
} else if (process.platform === 'linux') {
393-
procConfig.detached = true;
394392
if (terminal) {
393+
procConfig.detached = true;
395394
return child_process.spawn(
396395
terminal,
397396
['-e', 'sh ' + launchPackagerScript],
398397
procConfig,
399398
);
400399
}
400+
// By default, the child shell process will be attached to the parent
401+
procConfig.detached = false;
401402
return child_process.spawn('sh', [launchPackagerScript], procConfig);
402403
} else if (/^win/.test(process.platform)) {
403404
procConfig.detached = true;
@@ -474,5 +475,11 @@ module.exports = {
474475
default: process.env.RCT_METRO_PORT || 8081,
475476
parse: (val: string) => Number(val),
476477
},
478+
{
479+
command: '--terminal [string]',
480+
description:
481+
'Launches the Metro Bundler in a new window using the specified terminal path.',
482+
default: '',
483+
},
477484
],
478485
};

0 commit comments

Comments
 (0)