Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: open Metro in the correct terminal #310

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3787169
Put `isPackagerRunning` function on `cli-tools` to share between iOS …
lucasbento Apr 11, 2019
8c7fb99
Fix `terminal` argument not working when not being provided
lucasbento Apr 11, 2019
fd41e95
Fallback to the default terminal of the machine when starting the pac…
lucasbento Apr 11, 2019
27d0792
Delete `isPackagerRunning` as it was moved to `tools`
lucasbento Apr 11, 2019
fb1b91b
Add `terminal` argument to `run-ios`
lucasbento Apr 11, 2019
9a18d84
Launch Metro from within the `runIOS` command
lucasbento Apr 11, 2019
753b606
Remove code & add `—terminal` argument
lucasbento Apr 12, 2019
ac9b684
Try using `REACT_TERMINAL` before the default terminal
lucasbento Apr 12, 2019
119900a
Put `isPackagerRunning` function on `cli-tools` to share between iOS …
lucasbento Apr 11, 2019
485e6fb
Fix `terminal` argument not working when not being provided
lucasbento Apr 11, 2019
4249a49
Fallback to the default terminal of the machine when starting the pac…
lucasbento Apr 11, 2019
29edba4
Delete `isPackagerRunning` as it was moved to `tools`
lucasbento Apr 11, 2019
3c1500a
Add `terminal` argument to `run-ios`
lucasbento Apr 11, 2019
97263a7
Launch Metro from within the `runIOS` command
lucasbento Apr 11, 2019
9f54934
Remove code & add `—terminal` argument
lucasbento Apr 12, 2019
e273506
Try using `REACT_TERMINAL` before the default terminal
lucasbento Apr 12, 2019
5577cc3
Add tool function to get the default user terminal
lucasbento Apr 17, 2019
5c9e283
Fix `terminal` arg type
lucasbento Apr 17, 2019
e397a82
Remove spread and specify entry twice instead
lucasbento Apr 17, 2019
62ca068
Merge branch 'feature/correct-terminal' of https://github.com/lucasbe…
lucasbento Apr 17, 2019
c396b63
Improve `args` being passed through functions
lucasbento Apr 17, 2019
aa6375e
Reduce code duplication
lucasbento Apr 17, 2019
c4bb670
Put `device` and `udid` variable up in the scope
lucasbento Apr 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/platform-android/src/commands/runAndroid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {ConfigT} from '../../../../cli/src/tools/config/types.flow';

import adb from './adb';
import runOnAllDevices from './runOnAllDevices';
import isPackagerRunning from './isPackagerRunning';
import {isPackagerRunning} from '@react-native-community/cli-tools';
import tryRunAdbReverse from './tryRunAdbReverse';
import tryLaunchAppOnDevice from './tryLaunchAppOnDevice';
import getAdbPath from './getAdbPath';
Expand Down Expand Up @@ -228,7 +228,7 @@ function installAndLaunchOnDevice(

function startServerInNewWindow(
port,
terminal = process.env.REACT_TERMINAL,
terminal = process.env.REACT_TERMINAL || process.env.TERM_PROGRAM,
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
reactNativePath,
) {
/**
Expand Down Expand Up @@ -359,7 +359,7 @@ export default {
command: '--terminal [string]',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: '',
default: undefined,
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
},
],
};
25 changes: 20 additions & 5 deletions packages/platform-ios/src/commands/runIOS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type FlagsT = {
packager: boolean,
verbose: boolean,
port: number,
terminal: string | typeof undefined,
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
};

function runIOS(_: Array<string>, ctx: ConfigT, args: FlagsT) {
Expand Down Expand Up @@ -77,6 +78,7 @@ function runIOS(_: Array<string>, ctx: ConfigT, args: FlagsT) {
args.packager,
args.verbose,
args.port,
args.terminal,
);
}
if (devices && devices.length > 0) {
Expand Down Expand Up @@ -111,6 +113,7 @@ function runOnDeviceByUdid(
args.packager,
args.verbose,
args.port,
args.terminal,
);
return;
}
Expand Down Expand Up @@ -179,6 +182,7 @@ async function runOnSimulator(xcodeProject, args, scheme) {
args.packager,
args.verbose,
args.port,
args.terminal,
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
);

const appPath = getBuildPath(args.configuration, appName, false, scheme);
Expand Down Expand Up @@ -221,6 +225,7 @@ async function runOnDevice(
launchPackager,
verbose,
port,
terminal,
) {
const appName = await buildProject(
xcodeProject,
Expand All @@ -230,6 +235,7 @@ async function runOnDevice(
launchPackager,
verbose,
port,
terminal,
);

const iosDeployInstallArgs = [
Expand All @@ -240,7 +246,7 @@ async function runOnDevice(
'--justlaunch',
];

logger.info(`installing and launching your app on ${selectedDevice.name}...`);
logger.info(`Installing and launching your app on ${selectedDevice.name}...`);

const iosDeployOutput = child_process.spawnSync(
'ios-deploy',
Expand All @@ -265,6 +271,7 @@ function buildProject(
launchPackager = false,
verbose,
port,
terminal = process.env.REACT_TERMINAL || process.env.TERM_PROGRAM,
) {
return new Promise((resolve, reject) => {
const xcodebuildArgs = [
Expand All @@ -291,7 +298,7 @@ function buildProject(
const buildProcess = child_process.spawn(
'xcodebuild',
xcodebuildArgs,
getProcessOptions(launchPackager, port),
getProcessOptions(launchPackager, port, terminal),
);
let buildOutput = '';
let errorOutput = '';
Expand Down Expand Up @@ -418,15 +425,17 @@ function printFoundDevices(devices) {
return output;
}

function getProcessOptions(launchPackager, port) {
function getProcessOptions(launchPackager, port, terminal) {
const env = {...process.env, RCT_TERMINAL: terminal};
lucasbento marked this conversation as resolved.
Show resolved Hide resolved

if (launchPackager) {
return {
env: {...process.env, RCT_METRO_PORT: port},
env: {...env, RCT_METRO_PORT: port},
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
};
}

return {
env: {...process.env, RCT_NO_LAUNCH_PACKAGER: true},
env: {...env, RCT_NO_LAUNCH_PACKAGER: true},
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down Expand Up @@ -499,5 +508,11 @@ export default {
default: process.env.RCT_METRO_PORT || 8081,
parse: (val: string) => Number(val),
},
{
command: '--terminal [string]',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: undefined,
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
lucasbento marked this conversation as resolved.
Show resolved Hide resolved
},
],
};
1 change: 1 addition & 0 deletions packages/tools/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*/
export {default as logger} from './logger';
export {default as groupFilesByType} from './groupFilesByType';
export {default as isPackagerRunning} from './isPackagerRunning';

export * from './errors';