@phren/cli 0.3.57 → 0.3.58
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/bridge/computer-identity.d.ts +4 -2
- package/dist/bridge/computer-identity.js +7 -3
- package/dist/bridge/conductor-group.d.ts +1 -1
- package/dist/bridge/conductor-group.js +2 -2
- package/dist/bridge/conductor-sets.d.ts +6 -0
- package/dist/bridge/conductor-sets.js +8 -2
- package/dist/bridge/server-routes.d.ts +1 -0
- package/dist/bridge/server-routes.js +1 -1
- package/dist/bridge/server.js +6 -1
- package/dist/bridge/simulator-stream.d.ts +118 -0
- package/dist/bridge/simulator-stream.js +284 -0
- package/dist/bridge/simulators.d.ts +12 -0
- package/dist/bridge/simulators.js +32 -26
- package/dist/bridge-hook.mjs +1039 -667
- package/dist/modules/registry.js +2 -2
- package/package.json +1 -1
|
@@ -5,8 +5,12 @@ import path from "node:path";
|
|
|
5
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
7
|
import { BridgeError, bridgeRoot } from "./protocol.js";
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
/** Every simulator child is killed outright at its timeout. SIGTERM, the
|
|
10
|
+
* default, let one that ignored it hold its promise, and with it a stream's
|
|
11
|
+
* slot, for good. */
|
|
12
|
+
const exec = (file, args, options) => execFileAsync(file, args, { ...options, killSignal: "SIGKILL", encoding: "utf8" });
|
|
13
|
+
export const SIMULATOR_UDID = /^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/i;
|
|
10
14
|
/** The iOS simulators booted on this Mac, from `simctl`; none elsewhere. */
|
|
11
15
|
export async function bootedSimulators() {
|
|
12
16
|
if (process.platform !== "darwin")
|
|
@@ -24,7 +28,7 @@ export async function bootedSimulators() {
|
|
|
24
28
|
// com.apple.CoreSimulator.SimRuntime.iOS-26-1 → iOS 26.1
|
|
25
29
|
const runtime = runtimeID.replace(/^.*SimRuntime\./, "").replace(/-(\d+)-(\d+)$/, " $1.$2").replace(/-/g, " ");
|
|
26
30
|
for (const device of devices ?? []) {
|
|
27
|
-
if (device.state !== "Booted" || !device.udid || !
|
|
31
|
+
if (device.state !== "Booted" || !device.udid || !SIMULATOR_UDID.test(device.udid))
|
|
28
32
|
continue;
|
|
29
33
|
list.push({ udid: device.udid.toUpperCase(), name: String(device.name ?? "Simulator").slice(0, 120), runtime });
|
|
30
34
|
if (list.length >= 16)
|
|
@@ -35,7 +39,7 @@ export async function bootedSimulators() {
|
|
|
35
39
|
}
|
|
36
40
|
/** A PNG of one booted simulator's screen. */
|
|
37
41
|
export async function simulatorScreenshot(udid) {
|
|
38
|
-
if (!
|
|
42
|
+
if (!SIMULATOR_UDID.test(udid))
|
|
39
43
|
throw new BridgeError(400, "Invalid simulator identifier.");
|
|
40
44
|
if (process.platform !== "darwin")
|
|
41
45
|
throw new BridgeError(404, "Simulators run on macOS only.");
|
|
@@ -53,22 +57,24 @@ export async function simulatorScreenshot(udid) {
|
|
|
53
57
|
await unlink(file).catch(() => undefined);
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
const HELPER_LABEL = { simtap: "simulator input helper", simcast: "simulator stream helper" };
|
|
61
|
+
const building = new Map();
|
|
62
|
+
function helper(name) {
|
|
63
|
+
let build = building.get(name);
|
|
64
|
+
if (!build) {
|
|
65
|
+
build = buildHelper(name).finally(() => building.delete(name));
|
|
66
|
+
building.set(name, build);
|
|
67
|
+
}
|
|
68
|
+
return build;
|
|
69
|
+
}
|
|
70
|
+
async function helperSource(name) {
|
|
71
|
+
const bundled = name === "simtap" ? (typeof SIMTAP_SOURCE === "string" ? SIMTAP_SOURCE : undefined) : (typeof SIMCAST_SOURCE === "string" ? SIMCAST_SOURCE : undefined);
|
|
72
|
+
return bundled ?? await readFile(new URL(`./native/${name}.swift`, import.meta.url), "utf8");
|
|
67
73
|
}
|
|
68
|
-
async function buildHelper() {
|
|
74
|
+
async function buildHelper(name) {
|
|
69
75
|
const dir = path.join(bridgeRoot(), "native");
|
|
70
|
-
const binary = path.join(dir,
|
|
71
|
-
const code =
|
|
76
|
+
const binary = path.join(dir, name);
|
|
77
|
+
const code = await helperSource(name);
|
|
72
78
|
const digest = createHash("sha256").update(code).digest("hex");
|
|
73
79
|
// Rebuilt only when the source changes: the Accessibility grant is tied
|
|
74
80
|
// to this binary, and a needless rebuild would make macOS ask again.
|
|
@@ -76,12 +82,12 @@ async function buildHelper() {
|
|
|
76
82
|
if (await stat(binary).catch(() => undefined) && saved?.sourceSha === digest)
|
|
77
83
|
return binary;
|
|
78
84
|
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
79
|
-
const temporary = path.join(dir,
|
|
85
|
+
const temporary = path.join(dir, `${name}.${randomUUID()}`), source = temporary + ".swift";
|
|
80
86
|
const sidecar = temporary + ".sha256";
|
|
81
87
|
try {
|
|
82
88
|
await writeFile(source, code, { mode: 0o600, flag: "wx" });
|
|
83
89
|
await exec("/usr/bin/swiftc", ["-O", "-o", temporary, source], { timeout: 180_000 }).catch(() => {
|
|
84
|
-
throw new BridgeError(409,
|
|
90
|
+
throw new BridgeError(409, `Couldn't build the ${HELPER_LABEL[name]} (needs Xcode's swiftc).`);
|
|
85
91
|
});
|
|
86
92
|
await chmod(temporary, 0o700);
|
|
87
93
|
const binarySha = createHash("sha256").update(await readFile(temporary)).digest("hex");
|
|
@@ -100,13 +106,13 @@ function simtap(name, ...args) {
|
|
|
100
106
|
inputQueue = task;
|
|
101
107
|
return task;
|
|
102
108
|
}
|
|
103
|
-
/**
|
|
104
|
-
async function verifiedHelper() {
|
|
105
|
-
const binary = await helper();
|
|
109
|
+
/** A helper, hashed again right before it runs. */
|
|
110
|
+
export async function verifiedHelper(name = "simtap") {
|
|
111
|
+
const binary = await helper(name);
|
|
106
112
|
const saved = await readFile(binary + ".sha256", "utf8").then(JSON.parse).catch(() => undefined);
|
|
107
113
|
const binarySha = createHash("sha256").update(await readFile(binary)).digest("hex");
|
|
108
114
|
if (!saved || saved.binarySha !== binarySha)
|
|
109
|
-
throw new BridgeError(409,
|
|
115
|
+
throw new BridgeError(409, `${HELPER_LABEL[name][0].toUpperCase()}${HELPER_LABEL[name].slice(1)} integrity check failed.`);
|
|
110
116
|
return binary;
|
|
111
117
|
}
|
|
112
118
|
async function executeSimtap(name, ...args) {
|
|
@@ -148,7 +154,7 @@ const ACCESSIBILITY_PANE = "x-apple.systempreferences:com.apple.preference.secur
|
|
|
148
154
|
// macOS virtual key codes.
|
|
149
155
|
const KEY_H = "4", KEY_L = "37";
|
|
150
156
|
export async function simulatorAct(udid, request) {
|
|
151
|
-
if (!
|
|
157
|
+
if (!SIMULATOR_UDID.test(udid))
|
|
152
158
|
throw new BridgeError(400, "Invalid simulator identifier.");
|
|
153
159
|
if (!["boot", "shutdown", "launch", "openurl", "home", "lock", "type", "tap", "screenshot-ready", "accessibility-settings"].includes(request.action))
|
|
154
160
|
throw new BridgeError(400, "Unknown simulator action.");
|
|
@@ -216,7 +222,7 @@ async function deviceName(udid) {
|
|
|
216
222
|
}
|
|
217
223
|
/** The apps a simulator has, for the launcher. */
|
|
218
224
|
export async function simulatorApps(udid) {
|
|
219
|
-
if (!
|
|
225
|
+
if (!SIMULATOR_UDID.test(udid))
|
|
220
226
|
throw new BridgeError(400, "Invalid simulator identifier.");
|
|
221
227
|
if (process.platform !== "darwin")
|
|
222
228
|
return [];
|