@expo/serve-sim 0.1.51 → 0.1.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/middleware.js +39 -39
- package/dist/serve-sim.js +74 -74
- package/package.json +1 -1
- package/src/middleware.ts +28 -4
package/package.json
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
resolveDeviceKitChrome,
|
|
38
38
|
serveDeviceKitChromeAsset,
|
|
39
39
|
serveDevicePlaceholderAsset,
|
|
40
|
+
type DeviceKitChromeDescriptor,
|
|
40
41
|
} from "./devicekit-chrome";
|
|
41
42
|
import { createExecWebSocketHandler, type UiRequestHandler } from "./exec-ws";
|
|
42
43
|
import { claimHelperHidSocket, type UpgradeHandlerWebSocket } from "./middleware-utils";
|
|
@@ -102,7 +103,10 @@ type CdpHttpListEntry = {
|
|
|
102
103
|
type CdpHttpVersion = { Browser?: string };
|
|
103
104
|
|
|
104
105
|
type SimctlBootedList = {
|
|
105
|
-
devices: Record<
|
|
106
|
+
devices: Record<
|
|
107
|
+
string,
|
|
108
|
+
Array<{ udid: string; state: string; name: string; deviceTypeIdentifier?: string }>
|
|
109
|
+
>;
|
|
106
110
|
};
|
|
107
111
|
|
|
108
112
|
type SimctlAllList = {
|
|
@@ -253,10 +257,16 @@ export function matchInstalledAppByDisplayName(
|
|
|
253
257
|
// Cache simctl's booted-device set briefly so per-request cost stays bounded.
|
|
254
258
|
// The middleware runs inside the user's dev server (Metro etc.) and
|
|
255
259
|
// readServeSimStates() is called on every /api and every page load.
|
|
256
|
-
let bootedSnapshot: {
|
|
260
|
+
let bootedSnapshot: {
|
|
261
|
+
at: number;
|
|
262
|
+
booted: Set<string> | null;
|
|
263
|
+
names: Map<string, string>;
|
|
264
|
+
deviceTypes: Map<string, string>;
|
|
265
|
+
} = {
|
|
257
266
|
at: 0,
|
|
258
267
|
booted: null,
|
|
259
268
|
names: new Map(),
|
|
269
|
+
deviceTypes: new Map(),
|
|
260
270
|
};
|
|
261
271
|
async function getBootedUdids(): Promise<Set<string> | null> {
|
|
262
272
|
const now = Date.now();
|
|
@@ -281,6 +291,7 @@ async function getBootedUdids(): Promise<Set<string> | null> {
|
|
|
281
291
|
const data = JSON.parse(stdout) as SimctlBootedList;
|
|
282
292
|
const booted = new Set<string>();
|
|
283
293
|
const names = new Map<string, string>();
|
|
294
|
+
const deviceTypes = new Map<string, string>();
|
|
284
295
|
for (const runtime of Object.values(data.devices)) {
|
|
285
296
|
for (const device of runtime) {
|
|
286
297
|
if (device.state === "Booted") {
|
|
@@ -288,10 +299,11 @@ async function getBootedUdids(): Promise<Set<string> | null> {
|
|
|
288
299
|
const udid = device.udid.toUpperCase();
|
|
289
300
|
booted.add(udid);
|
|
290
301
|
names.set(udid, device.name);
|
|
302
|
+
if (device.deviceTypeIdentifier) deviceTypes.set(udid, device.deviceTypeIdentifier);
|
|
291
303
|
}
|
|
292
304
|
}
|
|
293
305
|
}
|
|
294
|
-
bootedSnapshot = { at: now, booted, names };
|
|
306
|
+
bootedSnapshot = { at: now, booted, names, deviceTypes };
|
|
295
307
|
return booted;
|
|
296
308
|
} catch {
|
|
297
309
|
return null;
|
|
@@ -312,6 +324,15 @@ function bootedDeviceName(udid: string): string | undefined {
|
|
|
312
324
|
return deviceNameFromBootedNames(bootedSnapshot.names, udid);
|
|
313
325
|
}
|
|
314
326
|
|
|
327
|
+
function bootedDeviceChrome(udid: string): DeviceKitChromeDescriptor | null {
|
|
328
|
+
const name = bootedDeviceName(udid);
|
|
329
|
+
if (!name) return null;
|
|
330
|
+
return resolveDeviceKitChrome({
|
|
331
|
+
name,
|
|
332
|
+
deviceTypeIdentifier: bootedSnapshot.deviceTypes.get(udid.toUpperCase()),
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
315
336
|
// The device the user most recently opened in Simulator.app, regardless of
|
|
316
337
|
// which tool launched it. Simulator.app persists this as CurrentDeviceUDID, so
|
|
317
338
|
// it's the best signal for "the device this user actually cares about" — we
|
|
@@ -962,6 +983,8 @@ export function previewConfigForState(
|
|
|
962
983
|
gridMemoryEndpoint: string;
|
|
963
984
|
previewEndpoint: string;
|
|
964
985
|
execToken: string;
|
|
986
|
+
/** Inlined so the first paint has the bezel instead of reflowing into it. */
|
|
987
|
+
chrome: DeviceKitChromeDescriptor | null;
|
|
965
988
|
/** @deprecated Use streamSettings. */
|
|
966
989
|
codec?: string;
|
|
967
990
|
streamSettings?: StreamSettings;
|
|
@@ -994,6 +1017,7 @@ export function previewConfigForState(
|
|
|
994
1017
|
gridMemoryEndpoint: gridApiBase + "/memory",
|
|
995
1018
|
previewEndpoint: base === "" ? "/" : base,
|
|
996
1019
|
execToken,
|
|
1020
|
+
chrome: bootedDeviceChrome(state.device),
|
|
997
1021
|
...(legacyCodec ? { codec: legacyCodec } : {}),
|
|
998
1022
|
...(streamSettings ? { streamSettings } : {}),
|
|
999
1023
|
...(proxyHelpers ? { proxyHelpers: true } : {}),
|
|
@@ -1876,7 +1900,7 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
1876
1900
|
closeDeviceSession(udid);
|
|
1877
1901
|
// Drop the snapshot so the next status sample re-queries simctl
|
|
1878
1902
|
// and prunes any helper bound to this now-shutdown device.
|
|
1879
|
-
bootedSnapshot = { at: 0, booted: null, names: new Map() };
|
|
1903
|
+
bootedSnapshot = { at: 0, booted: null, names: new Map(), deviceTypes: new Map() };
|
|
1880
1904
|
execFile("xcrun", ["simctl", "shutdown", udid], { timeout: 30_000 }, (err, _stdout, stderr) => {
|
|
1881
1905
|
if (err) {
|
|
1882
1906
|
res.writeHead(500, { "Content-Type": "application/json" });
|