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: correctly list ios devices and simulators #1823

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions packages/cli-platform-ios/src/commands/buildIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import {Device} from '../../types';
import {BuildFlags, buildProject} from './buildProject';
import {getDestinationSimulator} from '../../tools/getDestinationSimulator';
import {selectFromInteractiveMode} from '../../tools/selectFromInteractiveMode';
import {getDevices} from '../../tools/getDevices';
import {getProjectInfo} from '../../tools/getProjectInfo';
import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists';
import {getConfigurationScheme} from '../../tools/getConfigurationScheme';
import listIOSDevices from '../../tools/listIOSDevices';

export interface FlagsT extends BuildFlags {
configuration?: string;
Expand Down Expand Up @@ -136,7 +136,7 @@ async function buildIOS(_: Array<string>, ctx: Config, args: FlagsT) {
);
}

const devices = getDevices();
const devices = await listIOSDevices();

if (args.udid) {
const device = devices.find((d) => d.udid === args.udid);
Expand Down
24 changes: 16 additions & 8 deletions packages/cli-platform-ios/src/commands/runIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {logger, CLIError} from '@react-native-community/cli-tools';
import {BuildFlags, buildProject} from '../buildIOS/buildProject';
import {iosBuildOptions} from '../buildIOS';
import {Device} from '../../types';
import listIOSDevices from './listIOSDevices';
import listIOSDevices from '../../tools/listIOSDevices';
import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists';
import {getProjectInfo} from '../../tools/getProjectInfo';
import {getConfigurationScheme} from '../../tools/getConfigurationScheme';
Expand Down Expand Up @@ -110,6 +110,8 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
} "${chalk.bold(xcodeProject.name)}"`,
);

const availableDevices = await listIOSDevices();

if (args.listDevices) {
if (args.device || args.udid) {
logger.warn(
Expand All @@ -118,7 +120,6 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
} and "list-devices" parameters were passed to "run" command. We will list available devices and let you choose from one.`,
);
}
const availableDevices = await listIOSDevices();
const selectedDevice = await promptForDeviceSelection(availableDevices);
if (!selectedDevice) {
throw new CLIError(
Expand All @@ -132,10 +133,10 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
}
}

const devices = await listIOSDevices();

if (!args.device && !args.udid && !args.simulator) {
const bootedDevices = devices.filter(({type}) => type === 'device');
const bootedDevices = availableDevices.filter(
({type, isAvailable}) => type === 'device' && isAvailable,
);

const simulators = getSimulators();
const bootedSimulators = Object.keys(simulators.devices)
Expand Down Expand Up @@ -169,12 +170,12 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
}

if (args.udid) {
const device = devices.find((d) => d.udid === args.udid);
const device = availableDevices.find((d) => d.udid === args.udid);
if (!device) {
return logger.error(
`Could not find a device with udid: "${chalk.bold(
args.udid,
)}". ${printFoundDevices(devices)}`,
)}". ${printFoundDevices(availableDevices)}`,
);
}
if (device.type === 'simulator') {
Expand All @@ -183,7 +184,9 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
return runOnDevice(device, scheme, xcodeProject, modifiedArgs);
}
} else if (args.device) {
const physicalDevices = devices.filter((d) => d.type !== 'simulator');
const physicalDevices = availableDevices.filter(
(d) => d.type !== 'simulator',
adamTrz marked this conversation as resolved.
Show resolved Hide resolved
);
const device = matchingDevice(physicalDevices, args.device);
if (device) {
return runOnDevice(device, scheme, xcodeProject, modifiedArgs);
Expand Down Expand Up @@ -590,5 +593,10 @@ export default {
description:
'Path relative to project root where pre-built .app binary lives.',
},
{
name: '--list-devices',
description:
'List all available iOS devices and simulators and let you choose one to run the app. ',
},
],
};
26 changes: 0 additions & 26 deletions packages/cli-platform-ios/src/commands/runIOS/listIOSDevices.ts

This file was deleted.

221 changes: 0 additions & 221 deletions packages/cli-platform-ios/src/tools/__tests__/getDevices.test.ts

This file was deleted.

Loading