(
flags: ResolveDeviceFlags,
options: ResolveTargetDeviceOptions = {},
)
| 120 | } |
| 121 | |
| 122 | export async function resolveTargetDevice( |
| 123 | flags: ResolveDeviceFlags, |
| 124 | options: ResolveTargetDeviceOptions = {}, |
| 125 | ): Promise<DeviceInfo> { |
| 126 | const inventoryRequest = buildDeviceInventoryRequestFromFlags(flags); |
| 127 | const { iosSimulatorSetPath, ...selector } = inventoryRequest; |
| 128 | const cacheKey = buildResolveTargetDeviceCacheKey(inventoryRequest, options); |
| 129 | const selectionContext = { |
| 130 | simulatorSetPath: iosSimulatorSetPath, |
| 131 | allowStoppedAndroidAvdPlaceholders: options.allowStoppedAndroidAvdPlaceholders, |
| 132 | }; |
| 133 | const diagnosticData = { |
| 134 | platform: inventoryRequest.platform, |
| 135 | target: flags.target, |
| 136 | cacheHit: false, |
| 137 | }; |
| 138 | return await withDiagnosticTimer( |
| 139 | 'resolve_target_device', |
| 140 | async () => { |
| 141 | const cached = readResolveTargetDeviceCache(cacheKey); |
| 142 | if (cached) { |
| 143 | diagnosticData.cacheHit = true; |
| 144 | return cached; |
| 145 | } |
| 146 | const injectedDevices = await readInjectedDeviceInventory(inventoryRequest); |
| 147 | if (injectedDevices) { |
| 148 | if (isAppleResolutionSelector(selector)) { |
| 149 | return cacheResolvedTargetDevice( |
| 150 | cacheKey, |
| 151 | await resolveAppleDevice(injectedDevices, selector as AppleDeviceSelector, { |
| 152 | simulatorSetPath: iosSimulatorSetPath, |
| 153 | }), |
| 154 | ); |
| 155 | } |
| 156 | return cacheResolvedTargetDevice( |
| 157 | cacheKey, |
| 158 | await resolveDevice(injectedDevices, selector, selectionContext), |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | const devices = await listLocalDeviceInventory(inventoryRequest); |
| 163 | |
| 164 | if (isAppleResolutionSelector(selector)) { |
| 165 | return cacheResolvedTargetDevice( |
| 166 | cacheKey, |
| 167 | await resolveAppleDevice(devices, selector as AppleDeviceSelector, { |
| 168 | simulatorSetPath: iosSimulatorSetPath, |
| 169 | }), |
| 170 | ); |
| 171 | } |
| 172 | |
| 173 | return cacheResolvedTargetDevice( |
| 174 | cacheKey, |
| 175 | await resolveDevice(devices, selector, selectionContext), |
| 176 | ); |
| 177 | }, |
| 178 | diagnosticData, |
| 179 | ); |
no test coverage detected