@@ -14,7 +14,6 @@ import path from 'path';
1414
1515import type { ConfigT } from '../../../../cli/src/tools/config/types.flow' ;
1616
17- import { isPackagerRunning } from '@react-native-community/cli-tools' ;
1817import findXcodeProject from './findXcodeProject' ;
1918import parseIOSDevicesList from './parseIOSDevicesList' ;
2019import findMatchingSimulator from './findMatchingSimulator' ;
@@ -30,6 +29,7 @@ type FlagsT = {
3029 packager : boolean ,
3130 verbose : boolean ,
3231 port : number ,
32+ terminal : string | typeof undefined ,
3333} ;
3434
3535function runIOS ( _ : Array < string > , ctx : ConfigT , args : FlagsT ) {
@@ -78,7 +78,7 @@ function runIOS(_: Array<string>, ctx: ConfigT, args: FlagsT) {
7878 args . packager ,
7979 args . verbose ,
8080 args . port ,
81- ctx ,
81+ args . terminal ,
8282 ) ;
8383 }
8484 if ( devices && devices . length > 0 ) {
@@ -90,18 +90,17 @@ Choose one of the following:${printFoundDevices(devices)}`);
9090 }
9191 } else if ( args . udid ) {
9292 // $FlowIssue: args.udid is defined in this context
93- return runOnDeviceByUdid ( args , scheme , xcodeProject , devices , ctx ) ;
93+ return runOnDeviceByUdid ( args , scheme , xcodeProject , devices ) ;
9494 }
9595
96- return runOnSimulator ( xcodeProject , args , scheme , ctx ) ;
96+ return runOnSimulator ( xcodeProject , args , scheme ) ;
9797}
9898
9999function runOnDeviceByUdid (
100100 args : FlagsT & { udid : string } ,
101101 scheme ,
102102 xcodeProject ,
103103 devices ,
104- ctx ,
105104) {
106105 const selectedDevice = matchingDeviceByUdid ( devices , args . udid ) ;
107106
@@ -115,7 +114,6 @@ function runOnDeviceByUdid(
115114 args . verbose ,
116115 args . port ,
117116 args . terminal ,
118- ctx ,
119117 ) ;
120118 return ;
121119 }
@@ -129,46 +127,7 @@ Choose one of the following:\n${printFoundDevices(devices)}`);
129127 }
130128}
131129
132- async function runPackager ( { packager : shouldLaunchPackager , ...args } , ctx ) {
133- if ( ! shouldLaunchPackager ) {
134- return ;
135- }
136-
137- const terminal =
138- args . terminal || process . env . TERM_PROGRAM || process . env . REACT_TERMINAL ;
139- const packagerStatus = await isPackagerRunning ( args . port ) ;
140-
141- if ( packagerStatus === 'running' ) {
142- return logger . info ( 'JS server already running.' ) ;
143- }
144-
145- if ( packagerStatus === 'unrecognized' ) {
146- return logger . warn ( 'JS server not recognized, continuing with build...' ) ;
147- }
148-
149- const launchPackagerScript = path . join (
150- ctx . reactNativePath ,
151- 'scripts/launchPackager.command' ,
152- ) ;
153- const scriptsDir = path . dirname ( launchPackagerScript ) ;
154- const packagerEnvFile = path . join ( scriptsDir , '.packager.env' ) ;
155-
156- /**
157- * Ensure we overwrite file by passing the `w` flag
158- */
159- fs . writeFileSync ( packagerEnvFile , `export RCT_METRO_PORT=${ args . port } ` , {
160- encoding : 'utf8' ,
161- flag : 'w' ,
162- } ) ;
163-
164- return child_process . spawnSync (
165- 'open' ,
166- [ '-a' , terminal , launchPackagerScript ] ,
167- { cwd : scriptsDir } ,
168- ) ;
169- }
170-
171- async function runOnSimulator ( xcodeProject , args , scheme , ctx ) {
130+ async function runOnSimulator ( xcodeProject , args , scheme ) {
172131 let simulators ;
173132 try {
174133 simulators = JSON . parse (
@@ -215,8 +174,6 @@ async function runOnSimulator(xcodeProject, args, scheme, ctx) {
215174 bootSimulator ( selectedSimulator ) ;
216175 }
217176
218- await runPackager ( args , ctx ) ;
219-
220177 const appName = await buildProject (
221178 xcodeProject ,
222179 selectedSimulator . udid ,
@@ -225,6 +182,7 @@ async function runOnSimulator(xcodeProject, args, scheme, ctx) {
225182 args . packager ,
226183 args . verbose ,
227184 args . port ,
185+ args . terminal ,
228186 ) ;
229187
230188 const appPath = getBuildPath ( args . configuration , appName , false , scheme ) ;
@@ -259,7 +217,6 @@ async function runOnSimulator(xcodeProject, args, scheme, ctx) {
259217 ) ;
260218}
261219
262- // TODO: work on this one
263220async function runOnDevice (
264221 selectedDevice ,
265222 scheme ,
@@ -269,7 +226,6 @@ async function runOnDevice(
269226 verbose ,
270227 port ,
271228 terminal ,
272- ctx ,
273229) {
274230 const appName = await buildProject (
275231 xcodeProject ,
@@ -279,10 +235,9 @@ async function runOnDevice(
279235 launchPackager ,
280236 verbose ,
281237 port ,
238+ terminal ,
282239 ) ;
283240
284- await runPackager ( { terminal, launchPackager} , ctx ) ;
285-
286241 const iosDeployInstallArgs = [
287242 '--bundle' ,
288243 getBuildPath ( configuration , appName , true , scheme ) ,
@@ -316,6 +271,7 @@ function buildProject(
316271 launchPackager = false ,
317272 verbose ,
318273 port ,
274+ terminal = process . env . REACT_TERMINAL || process . env . TERM_PROGRAM ,
319275) {
320276 return new Promise ( ( resolve , reject ) => {
321277 const xcodebuildArgs = [
@@ -342,7 +298,7 @@ function buildProject(
342298 const buildProcess = child_process . spawn (
343299 'xcodebuild' ,
344300 xcodebuildArgs ,
345- getProcessOptions ( launchPackager , port ) ,
301+ getProcessOptions ( launchPackager , port , terminal ) ,
346302 ) ;
347303 let buildOutput = '' ;
348304 let errorOutput = '' ;
@@ -469,15 +425,17 @@ function printFoundDevices(devices) {
469425 return output;
470426}
471427
472- function getProcessOptions(launchPackager, port) {
428+ function getProcessOptions(launchPackager, port, terminal) {
429+ const env = {...process.env, RCT_TERMINAL: terminal};
430+
473431 if (launchPackager) {
474432 return {
475- env: {...process. env, RCT_METRO_PORT: port},
433+ env: {...env, RCT_METRO_PORT: port},
476434 };
477435 }
478436
479437 return {
480- env: {...process. env, RCT_NO_LAUNCH_PACKAGER: true},
438+ env: {...env, RCT_NO_LAUNCH_PACKAGER: true},
481439 };
482440}
483441
0 commit comments