File tree Expand file tree Collapse file tree 2 files changed +21
-25
lines changed
packages/cli-platform-apple/src Expand file tree Collapse file tree 2 files changed +21
-25
lines changed Original file line number Diff line number Diff line change @@ -149,14 +149,32 @@ const createRun =
149
149
return ;
150
150
}
151
151
152
- const devices = await listDevices ( sdkNames ) ;
152
+ let devices = await listDevices ( sdkNames ) ;
153
153
154
154
if ( devices . length === 0 ) {
155
155
return logger . error (
156
156
`${ platformReadableName } devices or simulators not detected. Install simulators via Xcode or connect a physical ${ platformReadableName } device` ,
157
157
) ;
158
158
}
159
159
160
+ const packageJson = getPackageJson ( ctx . root ) ;
161
+
162
+ const preferredDevice = cacheManager . get (
163
+ packageJson . name ,
164
+ 'lastUsedIOSDeviceId' ,
165
+ ) ;
166
+
167
+ if ( preferredDevice ) {
168
+ const preferredDeviceIndex = devices . findIndex (
169
+ ( { udid} ) => udid === preferredDevice ,
170
+ ) ;
171
+
172
+ if ( preferredDeviceIndex > - 1 ) {
173
+ const [ device ] = devices . splice ( preferredDeviceIndex , 1 ) ;
174
+ devices . unshift ( device ) ;
175
+ }
176
+ }
177
+
160
178
const fallbackSimulator =
161
179
platformName === 'ios' ? getFallbackSimulator ( args ) : devices [ 0 ] ;
162
180
@@ -169,16 +187,7 @@ const createRun =
169
187
) ;
170
188
}
171
189
172
- const packageJson = getPackageJson ( ctx . root ) ;
173
- const preferredDevice = cacheManager . get (
174
- packageJson . name ,
175
- 'lastUsedIOSDeviceId' ,
176
- ) ;
177
-
178
- const selectedDevice = await promptForDeviceSelection (
179
- devices ,
180
- preferredDevice ,
181
- ) ;
190
+ const selectedDevice = await promptForDeviceSelection ( devices ) ;
182
191
183
192
if ( ! selectedDevice ) {
184
193
throw new CLIError (
Original file line number Diff line number Diff line change @@ -40,25 +40,12 @@ export async function promptForConfigurationSelection(
40
40
41
41
export async function promptForDeviceSelection (
42
42
devices : Device [ ] ,
43
- lastUsedIOSDeviceId ?: string ,
44
43
) : Promise < Device | undefined > {
45
- const sortedDevices = [ ...devices ] ;
46
- const devicesIds = sortedDevices . map ( ( { udid} ) => udid ) ;
47
-
48
- if ( lastUsedIOSDeviceId ) {
49
- const preferredDeviceIndex = devicesIds . indexOf ( lastUsedIOSDeviceId ) ;
50
-
51
- if ( preferredDeviceIndex > - 1 ) {
52
- const [ preferredDevice ] = sortedDevices . splice ( preferredDeviceIndex , 1 ) ;
53
- sortedDevices . unshift ( preferredDevice ) ;
54
- }
55
- }
56
-
57
44
const { device} = await prompt ( {
58
45
type : 'select' ,
59
46
name : 'device' ,
60
47
message : 'Select the device you want to use' ,
61
- choices : sortedDevices
48
+ choices : devices
62
49
. filter ( ( { type} ) => type === 'device' || type === 'simulator' )
63
50
. map ( ( d ) => {
64
51
const availability =
You can’t perform that action at this time.
0 commit comments