Skip to content

Commit 4b93420

Browse files
committed
filter devices by platform
1 parent 6644379 commit 4b93420

File tree

5 files changed

+76
-33
lines changed

5 files changed

+76
-33
lines changed

packages/plugin-platform-apple/src/lib/commands/run/createRun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const createRun = async (
7474

7575
const loader = spinner();
7676
loader.start('Looking for available devices and simulators');
77-
const devices = await listDevicesAndSimulators();
77+
const devices = await listDevicesAndSimulators(platformName);
7878
if (devices.length === 0) {
7979
return logger.error(
8080
`${platformReadableName} devices or simulators not detected. Install simulators via Xcode or connect a physical ${platformReadableName} device`

packages/plugin-platform-apple/src/lib/types/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export type ApplePlatform = ObjectValues<typeof supportedPlatforms>;
77
export interface Device {
88
name: string;
99
udid: string;
10-
version: string;
10+
version: string; // e.g. visionOS 2.0
11+
platform: ApplePlatform | undefined;
1112
type: DeviceType;
12-
state?: 'Booted' | 'Shutdown';
13+
state: 'Booted' | 'Shutdown';
1314
}
1415

1516
export type DeviceType = 'simulator' | 'device';

packages/plugin-platform-apple/src/lib/utils/__tests__/listDevices.test.ts

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,113 +361,140 @@ const xcrunSimctlOutput = `
361361
`;
362362

363363
describe('listDevices', () => {
364-
it('outputs a list of available devices and simulators', async () => {
365-
const devices = await listDevicesAndSimulators();
364+
it('outputs a list of available devices and simulators for iOS platform', async () => {
365+
const devices = await listDevicesAndSimulators('ios');
366366
expect(devices).toEqual([
367367
{
368368
name: 'iPhone SE (3rd generation)',
369+
platform: 'ios',
369370
udid: '3339B733-4E3C-4916-AF02-1C43E1C769B2',
370371
version: 'iOS 18.0',
371372
state: 'Shutdown',
372373
type: 'simulator',
373374
},
374375
{
375376
name: 'iPhone 16 Pro',
377+
platform: 'ios',
376378
udid: '8E64D38C-2345-434D-AD46-DF092B4E2FDB',
377379
version: 'iOS 18.0',
378380
state: 'Booted',
379381
type: 'simulator',
380382
},
381383
{
382384
name: 'iPhone 16 Pro Max',
385+
platform: 'ios',
383386
udid: '848948C1-8494-4331-B7DE-FB380E30B310',
384387
version: 'iOS 18.0',
385388
state: 'Shutdown',
386389
type: 'simulator',
387390
},
388391
{
389392
name: 'iPhone 16',
393+
platform: 'ios',
390394
udid: 'DAF2A92E-0762-4443-9A1F-B06CAC58216D',
391395
version: 'iOS 18.0',
392396
state: 'Shutdown',
393397
type: 'simulator',
394398
},
395399
{
396400
name: 'iPhone 16 Plus',
401+
platform: 'ios',
397402
udid: '2F1CFD88-6581-4425-9902-F452EF2CB5A1',
398403
version: 'iOS 18.0',
399404
state: 'Shutdown',
400405
type: 'simulator',
401406
},
402407
{
403408
name: 'iPad (10th generation)',
409+
platform: 'ios',
404410
udid: '371F39BD-DFB4-41C8-A9BD-90527EED67E2',
405411
version: 'iOS 18.0',
406412
state: 'Shutdown',
407413
type: 'simulator',
408414
},
409415
{
410416
name: 'iPad mini (6th generation)',
417+
platform: 'ios',
411418
udid: '229FF073-6A31-4F03-85D0-4D5DE02192E2',
412419
version: 'iOS 18.0',
413420
state: 'Shutdown',
414421
type: 'simulator',
415422
},
416423
{
417424
name: 'iPad Air 13-inch (M2)',
425+
platform: 'ios',
418426
udid: '386C48E3-EAB5-47CA-9EA8-AD3A2A4AAB7F',
419427
version: 'iOS 18.0',
420428
state: 'Shutdown',
421429
type: 'simulator',
422430
},
423431
{
424432
name: 'iPad Pro 13-inch (M4)',
433+
platform: 'ios',
425434
udid: '0C80D473-0072-4932-9C51-5E0ADB7ACE06',
426435
version: 'iOS 18.0',
427436
state: 'Shutdown',
428437
type: 'simulator',
429438
},
439+
{
440+
name: 'my-iphone',
441+
platform: 'ios',
442+
udid: '00008110-00015D4E1439801E',
443+
version: 'iOS 18.1.1',
444+
state: 'Booted',
445+
type: 'device',
446+
},
447+
]);
448+
});
449+
450+
it('outputs a list of available devices and simulators for tvOS platform', async () => {
451+
const devices = await listDevicesAndSimulators('tvos');
452+
expect(devices).toEqual([
430453
{
431454
name: 'Apple TV',
432-
udid: 'EF1F361A-F7B7-4859-BF4F-877BAF4836F2',
433-
version: 'tvOS 18.0',
455+
platform: 'tvos',
434456
state: 'Shutdown',
435457
type: 'simulator',
458+
udid: 'EF1F361A-F7B7-4859-BF4F-877BAF4836F2',
459+
version: 'tvOS 18.0',
436460
},
437461
{
438462
name: 'Apple TV 4K (3rd generation)',
439-
udid: '9D35F2F1-CA5B-4B17-8F7C-4D12308FB482',
440-
version: 'tvOS 18.0',
463+
platform: 'tvos',
441464
state: 'Shutdown',
442465
type: 'simulator',
466+
udid: '9D35F2F1-CA5B-4B17-8F7C-4D12308FB482',
467+
version: 'tvOS 18.0',
443468
},
444469
{
445470
name: 'Apple TV 4K (3rd generation) (at 1080p)',
446-
udid: '02A843C5-225C-456D-BFC1-F5B1F5565FDD',
447-
version: 'tvOS 18.0',
471+
platform: 'tvos',
448472
state: 'Shutdown',
449473
type: 'simulator',
474+
udid: '02A843C5-225C-456D-BFC1-F5B1F5565FDD',
475+
version: 'tvOS 18.0',
450476
},
477+
]);
478+
});
479+
480+
it('outputs a list of available devices and simulators for visionOS platform', async () => {
481+
const devices = await listDevicesAndSimulators('visionos');
482+
expect(devices).toEqual([
451483
{
452484
name: 'Apple Vision Pro',
453-
udid: '8F741C32-632F-4E2F-B7D8-4CB8DDB8B888',
454-
version: 'visionOS 2.0',
485+
platform: 'visionos',
455486
state: 'Shutdown',
456487
type: 'simulator',
488+
udid: '8F741C32-632F-4E2F-B7D8-4CB8DDB8B888',
489+
version: 'visionOS 2.0',
457490
},
458491
{
459492
name: 'Apple Vision Pro',
460-
udid: '00008112-000C18C00C41A01E',
461-
version: 'xrOS 1.2',
493+
platform: 'visionos',
462494
state: 'Shutdown',
463495
type: 'device',
464-
},
465-
{
466-
name: 'my-iphone',
467-
udid: '00008110-00015D4E1439801E',
468-
version: 'iOS 18.1.1',
469-
state: 'Booted',
470-
type: 'device',
496+
udid: '00008112-000C18C00C41A01E',
497+
version: 'xrOS 1.2',
471498
},
472499
]);
473500
});

packages/plugin-platform-apple/src/lib/utils/getPlatformInfo.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,30 @@ import { ApplePlatform } from '../types/index.js';
22

33
interface PlatformInfo {
44
readableName: string;
5-
sdkNames: string[];
65
}
76

87
/**
9-
* Returns platform readable name and list of SDKs for given platform.
10-
* We can get list of SDKs from `xcodebuild -showsdks` command.
11-
*
8+
* Returns platform readable name.
129
* Falls back to iOS if platform is not supported.
1310
*/
1411
export function getPlatformInfo(platform: ApplePlatform): PlatformInfo {
1512
switch (platform) {
1613
case 'tvos':
1714
return {
1815
readableName: 'tvOS',
19-
sdkNames: ['appletvsimulator', 'appletvos'],
2016
};
2117
case 'visionos':
2218
return {
2319
readableName: 'visionOS',
24-
sdkNames: ['xrsimulator', 'xros'],
2520
};
2621
case 'macos':
2722
return {
2823
readableName: 'macOS',
29-
sdkNames: ['macosx'],
3024
};
3125
case 'ios':
3226
default:
3327
return {
3428
readableName: 'iOS',
35-
sdkNames: ['iphonesimulator', 'iphoneos'],
3629
};
3730
}
3831
}

packages/plugin-platform-apple/src/lib/utils/listDevices.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'node:os';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import spawn from 'nano-spawn';
5-
import type { Device } from '../types/index.js';
5+
import type { ApplePlatform, Device } from '../types/index.js';
66

77
type DevicectlOutput = {
88
capabilities: object[];
@@ -47,6 +47,7 @@ function parseDevicectlList(devicectlOutput: DevicectlOutput[]): Device[] {
4747
name: device.deviceProperties.name,
4848
udid: device.hardwareProperties.udid,
4949
version: `${device.hardwareProperties.platform} ${device.deviceProperties.osVersionNumber}`,
50+
platform: getPlatformFromOsVersion(device.hardwareProperties.platform),
5051
state:
5152
device.deviceProperties.bootState === 'booted' ? 'Booted' : 'Shutdown',
5253
type: 'device',
@@ -72,10 +73,12 @@ async function getSimulators() {
7273
return parseSimctlOutput(output);
7374
}
7475

75-
export async function listDevicesAndSimulators() {
76+
export async function listDevicesAndSimulators(platform: ApplePlatform) {
7677
const simulators = await getSimulators();
7778
const devices = await getDevices();
78-
return [...simulators, ...devices];
79+
return [...simulators, ...devices].filter(
80+
(device) => device.platform === platform
81+
);
7982
}
8083

8184
function parseSimctlOutput(input: string): Device[] {
@@ -100,6 +103,7 @@ function parseSimctlOutput(input: string): Device[] {
100103
name: deviceMatch[deviceNameIdx].trim(),
101104
udid: deviceMatch[identifierIdx],
102105
version: osVersion,
106+
platform: getPlatformFromOsVersion(osVersion.split(' ')[0]),
103107
state: deviceMatch[deviceStateIdx] as 'Booted' | 'Shutdown',
104108
type: 'simulator',
105109
});
@@ -108,3 +112,21 @@ function parseSimctlOutput(input: string): Device[] {
108112

109113
return devices;
110114
}
115+
116+
function getPlatformFromOsVersion(
117+
osVersion: string
118+
): ApplePlatform | undefined {
119+
switch (osVersion) {
120+
case 'iOS':
121+
return 'ios';
122+
case 'tvOS':
123+
return 'tvos';
124+
case 'macOS':
125+
return 'macos';
126+
case 'xrOS':
127+
case 'visionOS':
128+
return 'visionos';
129+
default:
130+
return undefined;
131+
}
132+
}

0 commit comments

Comments
 (0)