Skip to content

Commit 52dea5d

Browse files
joaogranadofacebook-github-bot
authored andcommitted
Add no-packager option to run-android and run-ios commands
Summary: Currently, while running `react-native run-android` command, React Native's packager is launched, and there is not any way to disable the current behaviour. This is handled somehow on iOS by adding an environment variable `RCT_NO_LAUNCH_PACKAGER` (see facebook#6180). This is a cross-platform solution that adds the `--no-packager` option both to `run-ios` and `run-android`, which prevents the packager from being launched. This was tested by building with and without the option, on both environments (Android and iOS) using the device and simulator, working as expected. Closes facebook#11735 Differential Revision: D4392170 Pulled By: ericvicenti fbshipit-source-id: 1c31f109f18715b84cd5ab1b6d5fd758cd0a6efb
1 parent 5542756 commit 52dea5d

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

local-cli/runAndroid/runAndroid.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function runAndroid(argv, config, args) {
3131
return;
3232
}
3333

34+
if (!args.packager) {
35+
return buildAndRun(args);
36+
}
37+
3438
return isPackagerRunning().then(result => {
3539
if (result === 'running') {
3640
console.log(chalk.bold('JS server already running.'));
@@ -286,5 +290,8 @@ module.exports = {
286290
command: '--deviceId [string]',
287291
description: 'builds your app and starts it on a specific device/simulator with the ' +
288292
'given device id (listed by running "adb devices" on the command line).',
293+
}, {
294+
command: '--no-packager',
295+
description: 'Do not launch packager while building',
289296
}],
290297
};

local-cli/runIOS/runIOS.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function runIOS(argv, config, args) {
3434
if (args.device) {
3535
const selectedDevice = matchingDevice(devices, args.device);
3636
if (selectedDevice){
37-
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration);
37+
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager);
3838
} else {
3939
if (devices){
4040
console.log('Could not find device with the name: "' + args.device + '".');
@@ -54,7 +54,7 @@ function runIOS(argv, config, args) {
5454
function runOnDeviceByUdid(args, scheme, xcodeProject, devices) {
5555
const selectedDevice = matchingDeviceByUdid(devices, args.udid);
5656
if (selectedDevice){
57-
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration);
57+
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager);
5858
} else {
5959
if (devices){
6060
console.log('Could not find device with the udid: "' + args.udid + '".');
@@ -91,7 +91,7 @@ function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){
9191
}
9292
resolve(selectedSimulator.udid)
9393
})
94-
.then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration))
94+
.then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration, args.packager))
9595
.then((appName) => {
9696
if (!appName) {
9797
appName = inferredSchemeName;
@@ -111,8 +111,8 @@ function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){
111111
})
112112
}
113113

114-
function runOnDevice(selectedDevice, scheme, xcodeProject, configuration){
115-
return buildProject(xcodeProject, selectedDevice.udid, scheme, configuration)
114+
function runOnDevice(selectedDevice, scheme, xcodeProject, configuration, launchPackager) {
115+
return buildProject(xcodeProject, selectedDevice.udid, scheme, configuration, launchPackager)
116116
.then((appName) => {
117117
if (!appName) {
118118
appName = scheme;
@@ -135,7 +135,7 @@ function runOnDevice(selectedDevice, scheme, xcodeProject, configuration){
135135
});
136136
}
137137

138-
function buildProject(xcodeProject, udid, scheme, configuration = 'Debug') {
138+
function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launchPackager = false) {
139139
return new Promise((resolve,reject) =>
140140
{
141141
var xcodebuildArgs = [
@@ -146,7 +146,7 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug') {
146146
'-derivedDataPath', 'build',
147147
];
148148
console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`);
149-
const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs);
149+
const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, getProcessOptions(launchPackager));
150150
let buildOutput = "";
151151
buildProcess.stdout.on('data', function(data) {
152152
console.log(data.toString());
@@ -197,6 +197,16 @@ function printFoundDevices(devices){
197197
}
198198
}
199199

200+
function getProcessOptions(launchPackager) {
201+
if (launchPackager) {
202+
return {};
203+
}
204+
205+
return {
206+
env: Object.assign({}, process.env, { RCT_NO_LAUNCH_PACKAGER: true }),
207+
};
208+
}
209+
200210
module.exports = {
201211
name: 'run-ios',
202212
description: 'builds your app and starts it on iOS simulator',
@@ -233,8 +243,11 @@ module.exports = {
233243
}, {
234244
command: '--device [string]',
235245
description: 'Explicitly set device to use by name. The value is not required if you have a single device connected.',
236-
},{
246+
}, {
237247
command: '--udid [string]',
238248
description: 'Explicitly set device to use by udid',
239-
}]
249+
}, {
250+
command: '--no-packager',
251+
description: 'Do not launch packager while building',
252+
}],
240253
};

0 commit comments

Comments
 (0)