@rootnative/loupe 0.0.0-alpha.1 → 0.0.0-alpha.2
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/CHANGELOG.md +22 -1
- package/README.md +15 -2
- package/dist/bin.js +2 -2
- package/dist/{chunk-JDX6L5K6.js → chunk-HWVQXYQ3.js} +1361 -326
- package/dist/index.d.ts +10 -2
- package/dist/index.js +1 -1
- package/dist/{server-BTS4TOGF.js → server-567FSCAH.js} +2 -2
- package/package.json +1 -1
- package/skills/loupe/SKILL.md +47 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@rootnative/loupe",
|
|
4
|
-
version: "0.0.0-alpha.
|
|
4
|
+
version: "0.0.0-alpha.2",
|
|
5
5
|
description: "loupe by Root Native: layout checks for iOS and Android, built for AI agents. Drive simulators and emulators, and measure every screen to the point.",
|
|
6
6
|
license: "MIT",
|
|
7
7
|
author: "Root Native",
|
|
@@ -160,6 +160,7 @@ var ERROR_CODES = [
|
|
|
160
160
|
"element_not_found",
|
|
161
161
|
"element_ambiguous",
|
|
162
162
|
"no_handler",
|
|
163
|
+
"no_server",
|
|
163
164
|
"cancelled",
|
|
164
165
|
"internal"
|
|
165
166
|
];
|
|
@@ -376,6 +377,10 @@ var uiNodeSchema = z4.object({
|
|
|
376
377
|
return z4.array(uiNodeSchema).optional();
|
|
377
378
|
}
|
|
378
379
|
});
|
|
380
|
+
var EXPO_GO = "host.exp.exponent";
|
|
381
|
+
function isExpoGoOverlay(node, app) {
|
|
382
|
+
return app === EXPO_GO && !node.type.startsWith("android.");
|
|
383
|
+
}
|
|
379
384
|
function scrollAxisOf(node) {
|
|
380
385
|
return /HorizontalScrollView|ViewPager/.test(node.type) ? "x" : "y";
|
|
381
386
|
}
|
|
@@ -768,6 +773,22 @@ function parseWindowDisplays(text, displayId = 0) {
|
|
|
768
773
|
focusId: focus?.[1]
|
|
769
774
|
};
|
|
770
775
|
}
|
|
776
|
+
var INPUT_FOCUS_HEADER = /^\s*FocusedWindows:(.*)$/m;
|
|
777
|
+
var INPUT_FOCUS_ENTRY = /^\s*displayId=(-?\d+), name='(.*)'\s*$/;
|
|
778
|
+
var INPUT_WINDOW_HASH = /^(?:Window\{)?([0-9a-f]+) /;
|
|
779
|
+
function parseInputFocus(text, displayId = 0) {
|
|
780
|
+
const header = INPUT_FOCUS_HEADER.exec(text);
|
|
781
|
+
if (!header) return void 0;
|
|
782
|
+
if (header[1]?.includes("<none>")) return null;
|
|
783
|
+
const after = text.slice(header.index + header[0].length).split(/\r?\n/);
|
|
784
|
+
for (const line of after.slice(1)) {
|
|
785
|
+
const entry = INPUT_FOCUS_ENTRY.exec(line);
|
|
786
|
+
if (!entry) break;
|
|
787
|
+
if (Number(entry[1]) !== displayId) continue;
|
|
788
|
+
return INPUT_WINDOW_HASH.exec(entry[2] ?? "")?.[1];
|
|
789
|
+
}
|
|
790
|
+
return null;
|
|
791
|
+
}
|
|
771
792
|
function parseWindowList(text) {
|
|
772
793
|
return text.split(/\n(?=\s*Window #\d+ Window\{)/).flatMap((block) => {
|
|
773
794
|
const header = /^\s*Window #\d+ Window\{(\S+) u\d+ (.+)\}:\s*$/m.exec(
|
|
@@ -1161,6 +1182,19 @@ async function backgroundAndroid(target, app, forMs, timing = {}) {
|
|
|
1161
1182
|
const back = await foregroundAndroid(target, inFront, timing);
|
|
1162
1183
|
return { app: inFront, away, back };
|
|
1163
1184
|
}
|
|
1185
|
+
var STOP_LIMIT = 2e3;
|
|
1186
|
+
var STOP_INTERVAL = 100;
|
|
1187
|
+
async function forceStopAndroid(target, app, limit = STOP_LIMIT) {
|
|
1188
|
+
await target.adb.run(["shell", "am", "force-stop", app]);
|
|
1189
|
+
const start = Date.now();
|
|
1190
|
+
while (await appRuns(target, app) && Date.now() - start < limit) {
|
|
1191
|
+
await sleep3(STOP_INTERVAL);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
async function appRuns(target, app) {
|
|
1195
|
+
const { stdout } = await target.adb.result(["shell", "pidof", app]);
|
|
1196
|
+
return /\d/.test(stdout.toString("utf8"));
|
|
1197
|
+
}
|
|
1164
1198
|
|
|
1165
1199
|
// src/drivers/android/sdk-tool.ts
|
|
1166
1200
|
import path2 from "path";
|
|
@@ -2421,13 +2455,11 @@ var screenCheckSchema = displaySchema.extend({
|
|
|
2421
2455
|
results: z11.array(ruleResultSchema),
|
|
2422
2456
|
warnings: z11.array(z11.string())
|
|
2423
2457
|
});
|
|
2424
|
-
var EXPO_GO = "host.exp.exponent";
|
|
2425
2458
|
function place(screen) {
|
|
2426
|
-
const skipOwn = screen.app === EXPO_GO;
|
|
2427
2459
|
const placed = [];
|
|
2428
2460
|
const walk = (nodes, scrollAxes) => {
|
|
2429
2461
|
for (const node of nodes) {
|
|
2430
|
-
if (
|
|
2462
|
+
if (isExpoGoOverlay(node, screen.app)) continue;
|
|
2431
2463
|
placed.push({ node, siblings: nodes, scrollAxes });
|
|
2432
2464
|
const inner = node.scrollable ? /* @__PURE__ */ new Set([...scrollAxes, scrollAxisOf(node)]) : scrollAxes;
|
|
2433
2465
|
walk(node.children ?? [], inner);
|
|
@@ -3426,6 +3458,27 @@ async function tapWait(target, display) {
|
|
|
3426
3458
|
async function sendKey(target, key2) {
|
|
3427
3459
|
await target.adb.run(["shell", "input", "keyevent", key2]);
|
|
3428
3460
|
}
|
|
3461
|
+
var CLOSED_WITHOUT_KEY = /* @__PURE__ */ new Set([
|
|
3462
|
+
"notification-shade",
|
|
3463
|
+
"not-responding",
|
|
3464
|
+
"stylus-sheet"
|
|
3465
|
+
]);
|
|
3466
|
+
async function untilInputFocus(target, front, { display }, { limit, interval }) {
|
|
3467
|
+
if (!display.focusId) return;
|
|
3468
|
+
const start = Date.now();
|
|
3469
|
+
for (; ; ) {
|
|
3470
|
+
const dump = await target.adb.text(["shell", "dumpsys", "input"]);
|
|
3471
|
+
const focus = parseInputFocus(dump);
|
|
3472
|
+
if (focus === void 0 || focus === display.focusId) return;
|
|
3473
|
+
if (Date.now() - start >= limit) {
|
|
3474
|
+
throw new LoupeError(
|
|
3475
|
+
"timeout",
|
|
3476
|
+
`The input focus didn't move to ${LAYER_NAMES[front.layer]} within ${limit} ms, so loupe sent no key: it could reach another window. Try again in a moment.`
|
|
3477
|
+
);
|
|
3478
|
+
}
|
|
3479
|
+
await sleep5(interval);
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3429
3482
|
async function close(target, front, screen) {
|
|
3430
3483
|
switch (front.layer) {
|
|
3431
3484
|
case "notification-shade":
|
|
@@ -3506,6 +3559,9 @@ async function dismissAndroid(target, app, { all = false, limit = 5e3, interval
|
|
|
3506
3559
|
if (closed.length >= (all ? MAX_LAYERS : 1)) {
|
|
3507
3560
|
return { app, closed, next: front.layer };
|
|
3508
3561
|
}
|
|
3562
|
+
if (!CLOSED_WITHOUT_KEY.has(front.layer)) {
|
|
3563
|
+
await untilInputFocus(target, front, screen, options);
|
|
3564
|
+
}
|
|
3509
3565
|
const start = Date.now();
|
|
3510
3566
|
const way = await close(target, front, screen);
|
|
3511
3567
|
const after = await untilGone(target, front, options);
|
|
@@ -4088,12 +4144,866 @@ var dragCommand = defineCommand({
|
|
|
4088
4144
|
)
|
|
4089
4145
|
});
|
|
4090
4146
|
|
|
4091
|
-
// src/commands/
|
|
4147
|
+
// src/commands/expo-open.ts
|
|
4148
|
+
import { z as z20 } from "zod";
|
|
4149
|
+
|
|
4150
|
+
// src/drivers/android/expo.ts
|
|
4151
|
+
import { setTimeout as sleep7 } from "timers/promises";
|
|
4152
|
+
|
|
4153
|
+
// src/expo/expo-go.ts
|
|
4154
|
+
var EXPO_GO2 = "host.exp.exponent";
|
|
4155
|
+
var CLOSE_BUTTON = {
|
|
4156
|
+
onboarding: { by: "text", value: "Continue" },
|
|
4157
|
+
"dev-menu": { by: "label", value: "Close" }
|
|
4158
|
+
};
|
|
4159
|
+
function* eachNode(nodes) {
|
|
4160
|
+
for (const node of nodes) {
|
|
4161
|
+
yield node;
|
|
4162
|
+
yield* eachNode(node.children ?? []);
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
function expoGoScreenOf(nodes) {
|
|
4166
|
+
const all = [...eachNode(nodes)];
|
|
4167
|
+
const has = (test) => all.some(test);
|
|
4168
|
+
if (has((node) => node.text === "Continue") && has((node) => node.text?.startsWith("This is the developer menu") === true)) {
|
|
4169
|
+
return "onboarding";
|
|
4170
|
+
}
|
|
4171
|
+
if (has((node) => node.text === "Go home") && has((node) => node.label === "Close")) {
|
|
4172
|
+
return "dev-menu";
|
|
4173
|
+
}
|
|
4174
|
+
if (has((node) => node.id === "host.exp.exponent:id/progressBar")) {
|
|
4175
|
+
return "loading";
|
|
4176
|
+
}
|
|
4177
|
+
return void 0;
|
|
4178
|
+
}
|
|
4179
|
+
function hasAppContent(nodes) {
|
|
4180
|
+
return nodes.some(
|
|
4181
|
+
(node) => node.type.startsWith("android.") && ((node.text || node.label || node.clickable || node.longClickable) && node.frame.width > 0 && node.frame.height > 0 || hasAppContent(node.children ?? []))
|
|
4182
|
+
);
|
|
4183
|
+
}
|
|
4184
|
+
function normalRoute(route) {
|
|
4185
|
+
const path8 = route.split(/[?#]/)[0] ?? "";
|
|
4186
|
+
return `/${path8.replace(/^\/+|\/+$/g, "")}`;
|
|
4187
|
+
}
|
|
4188
|
+
function routeOfLink(link) {
|
|
4189
|
+
if (!/^exps?:\/\//.test(link)) return void 0;
|
|
4190
|
+
const at = link.indexOf("/--/");
|
|
4191
|
+
return at === -1 ? "/" : normalRoute(link.slice(at + 3));
|
|
4192
|
+
}
|
|
4193
|
+
function expoLink(port, route = "/") {
|
|
4194
|
+
const path8 = route.replace(/^\/+/, "");
|
|
4195
|
+
return path8 ? `exp://127.0.0.1:${port}/--/${path8}` : `exp://127.0.0.1:${port}`;
|
|
4196
|
+
}
|
|
4197
|
+
var majorOf = (version2) => version2.split(".")[0] ?? "";
|
|
4198
|
+
function sdkWarning(expoGo, sdk) {
|
|
4199
|
+
if (!expoGo || !sdk || majorOf(expoGo) === majorOf(sdk)) return void 0;
|
|
4200
|
+
return `Expo Go ${expoGo} is for SDK ${majorOf(expoGo)}, and the app is on SDK ${sdk}, so Expo Go shows an error, not the app. Ask the user to install the Expo Go of SDK ${majorOf(sdk)}: press "a" in "npx expo start".`;
|
|
4201
|
+
}
|
|
4202
|
+
|
|
4203
|
+
// src/drivers/android/open-url.ts
|
|
4204
|
+
async function openUrlAndroid(target, url, app) {
|
|
4205
|
+
if (!app && target.kind === "device") {
|
|
4206
|
+
throw new LoupeError(
|
|
4207
|
+
"invalid_input",
|
|
4208
|
+
`${target.serial} is a real device, so loupe needs the "app" option: the package of the app under test. Then only that app opens the link.`
|
|
4209
|
+
);
|
|
4210
|
+
}
|
|
4211
|
+
const result = await target.adb.result([
|
|
4212
|
+
"shell",
|
|
4213
|
+
"am",
|
|
4214
|
+
"start",
|
|
4215
|
+
"-W",
|
|
4216
|
+
"-a",
|
|
4217
|
+
"android.intent.action.VIEW",
|
|
4218
|
+
"-d",
|
|
4219
|
+
shellQuote(url),
|
|
4220
|
+
...app ? ["-p", app] : []
|
|
4221
|
+
]);
|
|
4222
|
+
const start = parseAmStart(
|
|
4223
|
+
`${result.stdout.toString("utf8")}
|
|
4224
|
+
${result.stderr.toString("utf8")}`
|
|
4225
|
+
);
|
|
4226
|
+
if (start.unresolved) {
|
|
4227
|
+
throw new LoupeError(
|
|
4228
|
+
"no_handler",
|
|
4229
|
+
app ? `${app} doesn't open ${url} on ${target.serial}.` : `No app on ${target.serial} opens ${url}.`
|
|
4230
|
+
);
|
|
4231
|
+
}
|
|
4232
|
+
if (start.status !== "ok") {
|
|
4233
|
+
throw new LoupeError(
|
|
4234
|
+
"tool_failed",
|
|
4235
|
+
start.error ? `am start failed on ${target.serial}: ${start.error}` : `am start failed on ${target.serial} with exit code ${result.code}.`
|
|
4236
|
+
);
|
|
4237
|
+
}
|
|
4238
|
+
return {
|
|
4239
|
+
url,
|
|
4240
|
+
activity: start.activity,
|
|
4241
|
+
launchState: start.launchState?.toLowerCase(),
|
|
4242
|
+
totalTime: start.totalTime
|
|
4243
|
+
};
|
|
4244
|
+
}
|
|
4245
|
+
|
|
4246
|
+
// src/drivers/android/expo.ts
|
|
4247
|
+
var OPEN_AGAIN_MS = 2e4;
|
|
4248
|
+
var READ_INTERVAL = 500;
|
|
4249
|
+
async function readExpoGoVersion(target) {
|
|
4250
|
+
const installed = await target.adb.result(["shell", "pm", "path", EXPO_GO2]);
|
|
4251
|
+
if (installed.code !== 0 || !installed.stdout.toString("utf8").includes("package:")) {
|
|
4252
|
+
throw new LoupeError(
|
|
4253
|
+
"no_handler",
|
|
4254
|
+
`Expo Go isn't on ${target.serial}. Ask the user to install it: press "a" in "npx expo start", and the Expo CLI installs the Expo Go of the app's SDK.`
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
const dump = await target.adb.text(["shell", "dumpsys", "package", EXPO_GO2]);
|
|
4258
|
+
return /versionName=(\S+)/.exec(dump)?.[1];
|
|
4259
|
+
}
|
|
4260
|
+
function forceStopExpoGo(target, limit) {
|
|
4261
|
+
return forceStopAndroid(target, EXPO_GO2, limit);
|
|
4262
|
+
}
|
|
4263
|
+
async function reverseAndroid(target, port) {
|
|
4264
|
+
await target.adb.run(["reverse", `tcp:${port}`, `tcp:${port}`]);
|
|
4265
|
+
}
|
|
4266
|
+
async function readExpoGo(target) {
|
|
4267
|
+
try {
|
|
4268
|
+
return await readAndroidUi(target, EXPO_GO2);
|
|
4269
|
+
} catch (error) {
|
|
4270
|
+
if (error instanceof LoupeError && error.code === "not_idle") {
|
|
4271
|
+
return "not_idle";
|
|
4272
|
+
}
|
|
4273
|
+
if (error instanceof LoupeError && error.code === "app_not_in_front") {
|
|
4274
|
+
return void 0;
|
|
4275
|
+
}
|
|
4276
|
+
throw error;
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
var treeOf2 = (read) => typeof read === "object" ? read : void 0;
|
|
4280
|
+
async function probeRouteInExpoGo(target) {
|
|
4281
|
+
return treeOf2(await readExpoGo(target))?.probe?.report?.route;
|
|
4282
|
+
}
|
|
4283
|
+
async function showInExpoGo(target, { link, route, direction, timeout, openAgain = OPEN_AGAIN_MS }) {
|
|
4284
|
+
const start = Date.now();
|
|
4285
|
+
const opened = await openUrlAndroid(target, link, EXPO_GO2);
|
|
4286
|
+
let opens = 1;
|
|
4287
|
+
let openedAt = start;
|
|
4288
|
+
const reopens = [];
|
|
4289
|
+
const closed = [];
|
|
4290
|
+
let last = "nothing yet";
|
|
4291
|
+
let notIdle = false;
|
|
4292
|
+
while (Date.now() - start < timeout) {
|
|
4293
|
+
throwIfCancelled(target.signal);
|
|
4294
|
+
const { focus } = await readWindowDisplay(target);
|
|
4295
|
+
const inExperience = isAppWindow(focus, EXPO_GO2) && !focus?.includes("LauncherActivity");
|
|
4296
|
+
let appShows = false;
|
|
4297
|
+
if (!inExperience) {
|
|
4298
|
+
notIdle = false;
|
|
4299
|
+
if (notRespondingPackage(focus) !== void 0) {
|
|
4300
|
+
await readInFront(target, EXPO_GO2);
|
|
4301
|
+
}
|
|
4302
|
+
last = isAppWindow(focus, EXPO_GO2) ? "Expo Go's home screen" : target.kind === "device" ? "another window in front" : `${focus ?? "no window"} in front`;
|
|
4303
|
+
} else {
|
|
4304
|
+
const read = await readExpoGo(target);
|
|
4305
|
+
notIdle = read === "not_idle";
|
|
4306
|
+
const ui = treeOf2(read);
|
|
4307
|
+
const screen = ui && expoGoScreenOf(ui.nodes);
|
|
4308
|
+
if (!ui) {
|
|
4309
|
+
last = "Expo Go's screen, which didn't keep still for uiautomator";
|
|
4310
|
+
} else if (screen === "onboarding" || screen === "dev-menu") {
|
|
4311
|
+
const { point } = findElement(
|
|
4312
|
+
ui.nodes,
|
|
4313
|
+
CLOSE_BUTTON[screen],
|
|
4314
|
+
ui.display.size
|
|
4315
|
+
);
|
|
4316
|
+
await tapAndroid(target, point, EXPO_GO2);
|
|
4317
|
+
closed.push(screen);
|
|
4318
|
+
last = `Expo Go's ${screen === "onboarding" ? "onboarding sheet" : "developer menu"}`;
|
|
4319
|
+
} else if (screen === "loading") {
|
|
4320
|
+
last = "Expo Go's loading screen";
|
|
4321
|
+
} else if (!ui.probe?.report && !hasAppContent(ui.nodes)) {
|
|
4322
|
+
last = "a screen with no text, label or touch yet";
|
|
4323
|
+
} else if (!ui.probe?.report) {
|
|
4324
|
+
appShows = true;
|
|
4325
|
+
const remaining = Math.max(0, timeout - (Date.now() - start));
|
|
4326
|
+
if (await stillAppInExpoGo(target, remaining)) {
|
|
4327
|
+
return { opened, opens, reopens, closed, ms: Date.now() - start };
|
|
4328
|
+
}
|
|
4329
|
+
last = "the app with no probe, then another screen";
|
|
4330
|
+
} else {
|
|
4331
|
+
const probe = ui.probe.report;
|
|
4332
|
+
appShows = true;
|
|
4333
|
+
const onRoute = route === void 0 || probe.route === void 0 || normalRoute(probe.route) === normalRoute(route);
|
|
4334
|
+
const inDirection = direction === void 0 || probe.direction === direction;
|
|
4335
|
+
if (onRoute && inDirection) {
|
|
4336
|
+
return {
|
|
4337
|
+
opened,
|
|
4338
|
+
opens,
|
|
4339
|
+
reopens,
|
|
4340
|
+
closed,
|
|
4341
|
+
ms: Date.now() - start,
|
|
4342
|
+
probe
|
|
4343
|
+
};
|
|
4344
|
+
}
|
|
4345
|
+
last = onRoute ? `the app in ${probe.direction}` : `the app on ${probe.route}`;
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4348
|
+
const stuck = !inExperience || appShows;
|
|
4349
|
+
if (stuck && Date.now() - openedAt >= openAgain) {
|
|
4350
|
+
await openUrlAndroid(target, link, EXPO_GO2);
|
|
4351
|
+
opens += 1;
|
|
4352
|
+
reopens.push(last);
|
|
4353
|
+
openedAt = Date.now();
|
|
4354
|
+
}
|
|
4355
|
+
await sleep7(READ_INTERVAL);
|
|
4356
|
+
}
|
|
4357
|
+
if (notIdle) {
|
|
4358
|
+
throw new LoupeError(
|
|
4359
|
+
"not_idle",
|
|
4360
|
+
`Expo Go shows a screen after loupe opened ${link}, but it didn't keep still in ${Math.round(timeout / 1e3)} s, so uiautomator can't read it. An animation that never stops, or a long one, can cause this. Take a screenshot to see the screen, wait until the animation ends, or open a route with no such animation.`
|
|
4361
|
+
);
|
|
4362
|
+
}
|
|
4363
|
+
throw new LoupeError(
|
|
4364
|
+
"timeout",
|
|
4365
|
+
`Expo Go didn't show the app in ${Math.round(timeout / 1e3)} s after loupe opened ${link} (${opens === 1 ? "once" : `${opens} times`}). The last read: ${last}.`
|
|
4366
|
+
);
|
|
4367
|
+
}
|
|
4368
|
+
async function stillAppInExpoGo(target, timeout) {
|
|
4369
|
+
await waitStillInExpoGo(target, timeout);
|
|
4370
|
+
const again = treeOf2(await readExpoGo(target));
|
|
4371
|
+
return again !== void 0 && expoGoScreenOf(again.nodes) === void 0 && !again.probe?.report && hasAppContent(again.nodes);
|
|
4372
|
+
}
|
|
4373
|
+
async function waitStillInExpoGo(target, timeout) {
|
|
4374
|
+
const still = await waitStillAndroid(target, EXPO_GO2, {
|
|
4375
|
+
timeout,
|
|
4376
|
+
interval: READ_INTERVAL
|
|
4377
|
+
});
|
|
4378
|
+
if (!still.still) {
|
|
4379
|
+
throw new LoupeError(
|
|
4380
|
+
"timeout",
|
|
4381
|
+
`The app shows in Expo Go, but its screen didn't keep still in ${Math.round(timeout / 1e3)} s.`
|
|
4382
|
+
);
|
|
4383
|
+
}
|
|
4384
|
+
}
|
|
4385
|
+
|
|
4386
|
+
// src/expo/metro.ts
|
|
4387
|
+
import { createHash } from "crypto";
|
|
4388
|
+
import { setTimeout as sleep8 } from "timers/promises";
|
|
4092
4389
|
import { z as z19 } from "zod";
|
|
4390
|
+
var DEFAULT_PORT = 8081;
|
|
4391
|
+
var DEFAULT_BUNDLE_TIMEOUT = 3e5;
|
|
4392
|
+
var REQUEST_TIMEOUT = 1e4;
|
|
4393
|
+
var portField = z19.number().int().min(1).max(65535).optional().describe(
|
|
4394
|
+
`The port of Metro on this machine (npx expo start). ${DEFAULT_PORT} by default.`
|
|
4395
|
+
);
|
|
4396
|
+
var metroBase = (port) => `http://127.0.0.1:${port}`;
|
|
4397
|
+
var MANIFEST_HEADERS = {
|
|
4398
|
+
"expo-platform": "android",
|
|
4399
|
+
accept: "application/expo+json,application/json"
|
|
4400
|
+
};
|
|
4401
|
+
var manifestSchema = z19.object({
|
|
4402
|
+
launchAsset: z19.object({ url: z19.string() }),
|
|
4403
|
+
extra: z19.object({
|
|
4404
|
+
expoClient: z19.object({
|
|
4405
|
+
name: z19.string().optional(),
|
|
4406
|
+
slug: z19.string().optional(),
|
|
4407
|
+
sdkVersion: z19.string().optional(),
|
|
4408
|
+
// Read with type checks in `readExpoApp`: Expo CLI sends
|
|
4409
|
+
// `_internal.dynamicConfigPath` as `{}` when the app has no
|
|
4410
|
+
// dynamic config, and a field of another type must not drop the
|
|
4411
|
+
// whole manifest.
|
|
4412
|
+
extra: z19.unknown().optional(),
|
|
4413
|
+
_internal: z19.unknown().optional()
|
|
4414
|
+
}).optional(),
|
|
4415
|
+
expoGo: z19.object({
|
|
4416
|
+
developer: z19.object({ projectRoot: z19.string().optional() }).optional()
|
|
4417
|
+
}).optional()
|
|
4418
|
+
}).optional()
|
|
4419
|
+
});
|
|
4420
|
+
function fieldsOf(value) {
|
|
4421
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
4422
|
+
}
|
|
4423
|
+
var noServer = (port) => `Nothing answers on port ${port}. Ask the user to start Metro with "npx expo start" in the folder of the app, or give the port of Metro.`;
|
|
4424
|
+
function isRefused(error) {
|
|
4425
|
+
const cause = error instanceof Error ? error.cause : void 0;
|
|
4426
|
+
return error instanceof TypeError && typeof cause === "object" && cause !== null && "code" in cause && cause.code === "ECONNREFUSED";
|
|
4427
|
+
}
|
|
4428
|
+
async function askMetro(context, { port, path: path8, what, timeout, headers }, read) {
|
|
4429
|
+
throwIfCancelled(context.signal);
|
|
4430
|
+
const limit = AbortSignal.timeout(timeout);
|
|
4431
|
+
const signal = context.signal ? AbortSignal.any([limit, context.signal]) : limit;
|
|
4432
|
+
try {
|
|
4433
|
+
const response = await context.fetch(`${metroBase(port)}${path8}`, {
|
|
4434
|
+
headers,
|
|
4435
|
+
signal
|
|
4436
|
+
});
|
|
4437
|
+
return await read(response);
|
|
4438
|
+
} catch (error) {
|
|
4439
|
+
if (error instanceof LoupeError) throw error;
|
|
4440
|
+
throwIfCancelled(context.signal);
|
|
4441
|
+
if (limit.aborted) {
|
|
4442
|
+
throw new LoupeError(
|
|
4443
|
+
"timeout",
|
|
4444
|
+
`Metro on port ${port} didn't give ${what} in ${Math.round(timeout / 1e3)} s.`
|
|
4445
|
+
);
|
|
4446
|
+
}
|
|
4447
|
+
if (isRefused(error)) throw new LoupeError("no_server", noServer(port));
|
|
4448
|
+
throw new LoupeError(
|
|
4449
|
+
"tool_failed",
|
|
4450
|
+
`loupe couldn't get ${what} from Metro on port ${port}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4451
|
+
{ cause: error }
|
|
4452
|
+
);
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
async function readMetroStatus(context, port) {
|
|
4456
|
+
const status = await askMetro(
|
|
4457
|
+
context,
|
|
4458
|
+
{ port, path: "/status", what: "its status", timeout: REQUEST_TIMEOUT },
|
|
4459
|
+
(response) => response.text()
|
|
4460
|
+
);
|
|
4461
|
+
if (!status.includes("packager-status:running")) {
|
|
4462
|
+
throw new LoupeError(
|
|
4463
|
+
"no_server",
|
|
4464
|
+
`Something answers on port ${port}, but it isn't Metro. Give the port that "npx expo start" prints.`
|
|
4465
|
+
);
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
4468
|
+
async function readExpoApp(context, port) {
|
|
4469
|
+
const manifest = await askMetro(
|
|
4470
|
+
context,
|
|
4471
|
+
{
|
|
4472
|
+
port,
|
|
4473
|
+
path: "/",
|
|
4474
|
+
what: "the manifest",
|
|
4475
|
+
timeout: REQUEST_TIMEOUT,
|
|
4476
|
+
headers: MANIFEST_HEADERS
|
|
4477
|
+
},
|
|
4478
|
+
async (response) => {
|
|
4479
|
+
const text = await response.text();
|
|
4480
|
+
if (!response.ok) return void 0;
|
|
4481
|
+
try {
|
|
4482
|
+
return manifestSchema.safeParse(JSON.parse(text)).data;
|
|
4483
|
+
} catch {
|
|
4484
|
+
return void 0;
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
);
|
|
4488
|
+
if (!manifest) {
|
|
4489
|
+
throw new LoupeError(
|
|
4490
|
+
"unsupported",
|
|
4491
|
+
`Metro on port ${port} gives no Expo manifest. The Expo commands need the dev server of the Expo CLI: "npx expo start".`
|
|
4492
|
+
);
|
|
4493
|
+
}
|
|
4494
|
+
const client = manifest.extra?.expoClient;
|
|
4495
|
+
const bundle = new URL(manifest.launchAsset.url, metroBase(port));
|
|
4496
|
+
const extra = fieldsOf(client?.extra);
|
|
4497
|
+
const dynamicConfigPath = fieldsOf(client?._internal).dynamicConfigPath;
|
|
4498
|
+
return {
|
|
4499
|
+
name: client?.name,
|
|
4500
|
+
slug: client?.slug,
|
|
4501
|
+
sdkVersion: client?.sdkVersion,
|
|
4502
|
+
projectRoot: manifest.extra?.expoGo?.developer?.projectRoot,
|
|
4503
|
+
dynamicConfigPath: typeof dynamicConfigPath === "string" ? dynamicConfigPath : void 0,
|
|
4504
|
+
rtl: {
|
|
4505
|
+
supports: extra.supportsRTL === true,
|
|
4506
|
+
forces: extra.forcesRTL === true
|
|
4507
|
+
},
|
|
4508
|
+
bundlePath: `${bundle.pathname}${bundle.search}`
|
|
4509
|
+
};
|
|
4510
|
+
}
|
|
4511
|
+
var MANIFEST_LIMIT = 1e4;
|
|
4512
|
+
var MANIFEST_INTERVAL = 250;
|
|
4513
|
+
async function untilManifestRtl(context, port, forces, timeout = MANIFEST_LIMIT) {
|
|
4514
|
+
const limit = Math.min(timeout, MANIFEST_LIMIT);
|
|
4515
|
+
const start = Date.now();
|
|
4516
|
+
for (; ; ) {
|
|
4517
|
+
const app = await readExpoApp(context, port);
|
|
4518
|
+
if (app.rtl.forces === forces) return;
|
|
4519
|
+
if (Date.now() - start >= limit) {
|
|
4520
|
+
throw new LoupeError(
|
|
4521
|
+
"unsupported",
|
|
4522
|
+
`loupe wrote app.json, but after ${Math.round(limit / 1e3)} s the manifest of Metro still gives forcesRTL ${app.rtl.forces}. ${app.dynamicConfigPath?.split(/[\\/]/).pop() ?? "A dynamic config"} can replace extra: it must keep the extra of app.json ("...config.extra").`
|
|
4523
|
+
);
|
|
4524
|
+
}
|
|
4525
|
+
throwIfCancelled(context.signal);
|
|
4526
|
+
await sleep8(MANIFEST_INTERVAL);
|
|
4527
|
+
}
|
|
4528
|
+
}
|
|
4529
|
+
function bundleError(status, text) {
|
|
4530
|
+
let detail = text;
|
|
4531
|
+
try {
|
|
4532
|
+
const json = JSON.parse(text);
|
|
4533
|
+
if (typeof json === "object" && json !== null) {
|
|
4534
|
+
detail = ["type", "message"].map((key2) => json[key2]).filter((value) => typeof value === "string").join(": ");
|
|
4535
|
+
}
|
|
4536
|
+
} catch {
|
|
4537
|
+
}
|
|
4538
|
+
const line = detail.split("\n").map((part) => part.trim()).find(Boolean);
|
|
4539
|
+
return `Metro couldn't build the bundle (HTTP ${status})${line ? `: ${line.slice(0, 500)}` : "."} Fix the code of the app, then run expo-warm again.`;
|
|
4540
|
+
}
|
|
4541
|
+
async function fetchBundle(context, port, path8, timeout) {
|
|
4542
|
+
const start = performance.now();
|
|
4543
|
+
return askMetro(
|
|
4544
|
+
context,
|
|
4545
|
+
{ port, path: path8, what: "the bundle", timeout },
|
|
4546
|
+
async (response) => {
|
|
4547
|
+
if (!response.ok) {
|
|
4548
|
+
throw new LoupeError(
|
|
4549
|
+
"tool_failed",
|
|
4550
|
+
bundleError(response.status, await response.text())
|
|
4551
|
+
);
|
|
4552
|
+
}
|
|
4553
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
4554
|
+
return {
|
|
4555
|
+
ms: Math.round(performance.now() - start),
|
|
4556
|
+
bytes: body.length,
|
|
4557
|
+
sha256: createHash("sha256").update(body).digest("hex")
|
|
4558
|
+
};
|
|
4559
|
+
}
|
|
4560
|
+
);
|
|
4561
|
+
}
|
|
4562
|
+
async function warmExpo(context, { port = DEFAULT_PORT, timeout = DEFAULT_BUNDLE_TIMEOUT }, total = 3) {
|
|
4563
|
+
await readMetroStatus(context, port);
|
|
4564
|
+
context.progress?.({ progress: 1, total, message: "Metro runs." });
|
|
4565
|
+
const app = await readExpoApp(context, port);
|
|
4566
|
+
context.progress?.({
|
|
4567
|
+
progress: 2,
|
|
4568
|
+
total,
|
|
4569
|
+
message: "Metro builds the bundle."
|
|
4570
|
+
});
|
|
4571
|
+
const bundle = await fetchBundle(context, port, app.bundlePath, timeout);
|
|
4572
|
+
context.progress?.({ progress: 3, total });
|
|
4573
|
+
return {
|
|
4574
|
+
server: metroBase(port),
|
|
4575
|
+
link: `exp://127.0.0.1:${port}`,
|
|
4576
|
+
app: { name: app.name, slug: app.slug, sdkVersion: app.sdkVersion },
|
|
4577
|
+
projectRoot: app.projectRoot,
|
|
4578
|
+
bundle: { path: app.bundlePath, ...bundle }
|
|
4579
|
+
};
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
// src/commands/expo-open.ts
|
|
4583
|
+
var DEFAULT_SHOW_TIMEOUT = 12e4;
|
|
4584
|
+
var STEPS = 5;
|
|
4585
|
+
var showTimeoutField = z20.number().int().min(1e3).max(6e5).optional().describe(
|
|
4586
|
+
`How long to wait for the app after the open, in ms. ${DEFAULT_SHOW_TIMEOUT} by default.`
|
|
4587
|
+
);
|
|
4588
|
+
var shownSchema = z20.object({
|
|
4589
|
+
link: z20.string().describe("The link that loupe opened in Expo Go."),
|
|
4590
|
+
app: z20.object({
|
|
4591
|
+
name: z20.string().optional(),
|
|
4592
|
+
slug: z20.string().optional(),
|
|
4593
|
+
sdkVersion: z20.string().optional()
|
|
4594
|
+
}),
|
|
4595
|
+
expoGo: z20.string().optional().describe("The version of Expo Go on the device."),
|
|
4596
|
+
launchState: z20.string().optional().describe("cold, warm or hot, as Android measured the first open."),
|
|
4597
|
+
opens: z20.number().describe(
|
|
4598
|
+
"How many times loupe opened the link. Expo Go can lose a link while it starts."
|
|
4599
|
+
),
|
|
4600
|
+
reopens: z20.array(z20.string()).describe(
|
|
4601
|
+
"What the last read saw before each time that loupe opened the link again."
|
|
4602
|
+
),
|
|
4603
|
+
closed: z20.array(z20.enum(["onboarding", "dev-menu"])).describe(
|
|
4604
|
+
"The Expo Go sheets that loupe closed: the onboarding sheet of the first open, and the developer menu."
|
|
4605
|
+
),
|
|
4606
|
+
ms: z20.number().describe("From the open until the app showed, in ms."),
|
|
4607
|
+
route: z20.string().optional().describe("The route that the app's probe shows."),
|
|
4608
|
+
direction: z20.enum(["ltr", "rtl"]).optional().describe("The layout direction that the app's probe shows."),
|
|
4609
|
+
probe: z20.boolean().describe(
|
|
4610
|
+
"True when the app has the probe. With no probe, loupe waited until the screen had text, a label or a touch, kept still, and then still showed no Expo Go screen."
|
|
4611
|
+
),
|
|
4612
|
+
warnings: z20.array(z20.string())
|
|
4613
|
+
});
|
|
4614
|
+
async function showApp(context, {
|
|
4615
|
+
route,
|
|
4616
|
+
port = DEFAULT_PORT,
|
|
4617
|
+
timeout = DEFAULT_SHOW_TIMEOUT,
|
|
4618
|
+
device
|
|
4619
|
+
}, { reload = false, prepare } = {}) {
|
|
4620
|
+
const target = await selectAndroidDevice(context, device);
|
|
4621
|
+
const expoGo = await readExpoGoVersion(target);
|
|
4622
|
+
const warmed = await warmExpo(context, { port }, STEPS);
|
|
4623
|
+
const direction = await prepare?.();
|
|
4624
|
+
const warnings = [];
|
|
4625
|
+
const sdk = sdkWarning(expoGo, warmed.app.sdkVersion);
|
|
4626
|
+
if (sdk) warnings.push(sdk);
|
|
4627
|
+
await reverseAndroid(target, port);
|
|
4628
|
+
const openRoute = reload ? route ?? await probeRouteInExpoGo(target) : route;
|
|
4629
|
+
context.progress?.({
|
|
4630
|
+
progress: 4,
|
|
4631
|
+
total: STEPS,
|
|
4632
|
+
message: reload ? "Expo Go stops, then opens the app again." : "Expo Go opens the app."
|
|
4633
|
+
});
|
|
4634
|
+
if (reload) await forceStopExpoGo(target);
|
|
4635
|
+
const link = expoLink(port, openRoute);
|
|
4636
|
+
const start = Date.now();
|
|
4637
|
+
const shown = await showInExpoGo(target, {
|
|
4638
|
+
link,
|
|
4639
|
+
route: openRoute,
|
|
4640
|
+
direction,
|
|
4641
|
+
timeout
|
|
4642
|
+
});
|
|
4643
|
+
context.progress?.({ progress: STEPS, total: STEPS });
|
|
4644
|
+
const { launchState } = shown.opened;
|
|
4645
|
+
const proved = direction !== void 0 && shown.probe?.direction === direction;
|
|
4646
|
+
if (reload && launchState !== void 0 && launchState !== "cold" && !proved) {
|
|
4647
|
+
warnings.push(
|
|
4648
|
+
`Android gave the launch state ${launchState} after the force-stop, not cold, so Expo Go can still have run. Check that the app shows your change.`
|
|
4649
|
+
);
|
|
4650
|
+
}
|
|
4651
|
+
return {
|
|
4652
|
+
link,
|
|
4653
|
+
app: warmed.app,
|
|
4654
|
+
expoGo,
|
|
4655
|
+
launchState,
|
|
4656
|
+
opens: shown.opens,
|
|
4657
|
+
reopens: shown.reopens,
|
|
4658
|
+
closed: shown.closed,
|
|
4659
|
+
ms: Date.now() - start,
|
|
4660
|
+
route: shown.probe?.route,
|
|
4661
|
+
direction: shown.probe?.direction,
|
|
4662
|
+
probe: shown.probe !== void 0,
|
|
4663
|
+
warnings
|
|
4664
|
+
};
|
|
4665
|
+
}
|
|
4666
|
+
function describeShown(lead, { app, opens, reopens, closed, ms, route, direction, warnings }) {
|
|
4667
|
+
return [
|
|
4668
|
+
[
|
|
4669
|
+
`${lead}: ${app.name ?? app.slug ?? "the app"} shows`,
|
|
4670
|
+
...route ? [` on ${route}`] : [],
|
|
4671
|
+
...direction ? [` in ${direction.toUpperCase()}`] : [],
|
|
4672
|
+
` after ${ms} ms`,
|
|
4673
|
+
...closed.length ? [`; closed ${closed.join(", ")}`] : [],
|
|
4674
|
+
...opens > 1 ? [`; opened ${opens} times, again after: ${reopens.join("; ")}`] : [],
|
|
4675
|
+
"."
|
|
4676
|
+
].join(""),
|
|
4677
|
+
...warnings.map((warning) => `Warning: ${warning}`)
|
|
4678
|
+
].join("\n");
|
|
4679
|
+
}
|
|
4680
|
+
var expoOpenCommand = defineCommand({
|
|
4681
|
+
name: "expo-open",
|
|
4682
|
+
summary: "Open the app in Expo Go on the device, at a route, and wait until it shows",
|
|
4683
|
+
input: z20.object({
|
|
4684
|
+
route: z20.string().optional().describe(
|
|
4685
|
+
"The route to open, for example /settings. The root by default. When the app has the probe, loupe waits until the probe shows this route."
|
|
4686
|
+
),
|
|
4687
|
+
port: portField,
|
|
4688
|
+
timeout: showTimeoutField,
|
|
4689
|
+
device: deviceField
|
|
4690
|
+
}),
|
|
4691
|
+
positionals: ["route"],
|
|
4692
|
+
output: shownSchema,
|
|
4693
|
+
run: (input, context) => showApp(context, input),
|
|
4694
|
+
format: (shown) => describeShown(
|
|
4695
|
+
`Opened ${shown.link} in Expo Go${shown.expoGo ? ` ${shown.expoGo}` : ""}`,
|
|
4696
|
+
shown
|
|
4697
|
+
)
|
|
4698
|
+
});
|
|
4699
|
+
|
|
4700
|
+
// src/commands/expo-reload.ts
|
|
4701
|
+
import { z as z21 } from "zod";
|
|
4702
|
+
var expoReloadCommand = defineCommand({
|
|
4703
|
+
name: "expo-reload",
|
|
4704
|
+
summary: "Stop Expo Go and open the app again, so its JavaScript starts again, and wait until it shows",
|
|
4705
|
+
input: z21.object({
|
|
4706
|
+
route: z21.string().optional().describe(
|
|
4707
|
+
"The route to open after the stop, for example /settings. By default the route that the probe shows before the stop, else the root."
|
|
4708
|
+
),
|
|
4709
|
+
port: portField,
|
|
4710
|
+
timeout: showTimeoutField,
|
|
4711
|
+
device: deviceField
|
|
4712
|
+
}),
|
|
4713
|
+
positionals: ["route"],
|
|
4714
|
+
output: shownSchema,
|
|
4715
|
+
run: (input, context) => showApp(context, input, { reload: true }),
|
|
4716
|
+
format: (shown) => describeShown(
|
|
4717
|
+
`Stopped Expo Go${shown.expoGo ? ` ${shown.expoGo}` : ""} and opened ${shown.link} again`,
|
|
4718
|
+
shown
|
|
4719
|
+
)
|
|
4720
|
+
});
|
|
4721
|
+
|
|
4722
|
+
// src/commands/expo-rtl.ts
|
|
4723
|
+
import { z as z23 } from "zod";
|
|
4724
|
+
|
|
4725
|
+
// src/expo/app-config.ts
|
|
4726
|
+
import { mkdir as mkdir2, readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
4727
|
+
import path5 from "path";
|
|
4728
|
+
import { z as z22 } from "zod";
|
|
4729
|
+
var KEYS2 = ["supportsRTL", "forcesRTL"];
|
|
4730
|
+
var RECORD_PATH = path5.join(".expo", "loupe-rtl.json");
|
|
4731
|
+
var recordSchema = z22.object({ original: z22.string(), written: z22.string() });
|
|
4732
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4733
|
+
function parseAppJson(text, file) {
|
|
4734
|
+
let json;
|
|
4735
|
+
try {
|
|
4736
|
+
json = JSON.parse(text);
|
|
4737
|
+
} catch {
|
|
4738
|
+
json = void 0;
|
|
4739
|
+
}
|
|
4740
|
+
if (!isObject(json)) {
|
|
4741
|
+
throw new LoupeError(
|
|
4742
|
+
"unsupported",
|
|
4743
|
+
`${file} isn't a JSON object, so loupe can't edit it.`
|
|
4744
|
+
);
|
|
4745
|
+
}
|
|
4746
|
+
return json;
|
|
4747
|
+
}
|
|
4748
|
+
var expoConfigOf = (json) => isObject(json.expo) ? json.expo : json;
|
|
4749
|
+
function formatLike(json, like) {
|
|
4750
|
+
const indent = /^[^\n]*\n([ \t]+)\S/.exec(like)?.[1] ?? " ";
|
|
4751
|
+
const text = `${JSON.stringify(json, null, indent)}${like.endsWith("\n") ? "\n" : ""}`;
|
|
4752
|
+
return like.includes("\r\n") ? text.replace(/\n/g, "\r\n") : text;
|
|
4753
|
+
}
|
|
4754
|
+
function withRtl(text, file) {
|
|
4755
|
+
const json = parseAppJson(text, file);
|
|
4756
|
+
const config = expoConfigOf(json);
|
|
4757
|
+
const extra = isObject(config.extra) ? config.extra : {};
|
|
4758
|
+
if (extra.supportsRTL === true && extra.forcesRTL === true) return text;
|
|
4759
|
+
config.extra = { ...extra, supportsRTL: true, forcesRTL: true };
|
|
4760
|
+
return formatLike(json, text);
|
|
4761
|
+
}
|
|
4762
|
+
function withKeysOf(text, original, file) {
|
|
4763
|
+
const json = parseAppJson(text, file);
|
|
4764
|
+
const config = expoConfigOf(json);
|
|
4765
|
+
const before = expoConfigOf(parseAppJson(original, file)).extra;
|
|
4766
|
+
const extra = isObject(config.extra) ? { ...config.extra } : {};
|
|
4767
|
+
for (const key2 of KEYS2) {
|
|
4768
|
+
if (isObject(before) && key2 in before) extra[key2] = before[key2];
|
|
4769
|
+
else delete extra[key2];
|
|
4770
|
+
}
|
|
4771
|
+
if (Object.keys(extra).length === 0 && !isObject(before)) delete config.extra;
|
|
4772
|
+
else config.extra = extra;
|
|
4773
|
+
const unchanged = JSON.stringify(json) === JSON.stringify(parseAppJson(text, file));
|
|
4774
|
+
return unchanged ? text : formatLike(json, text);
|
|
4775
|
+
}
|
|
4776
|
+
function rtlOf(text, file) {
|
|
4777
|
+
const extra = expoConfigOf(parseAppJson(text, file)).extra;
|
|
4778
|
+
return {
|
|
4779
|
+
supports: isObject(extra) && extra.supportsRTL === true,
|
|
4780
|
+
forces: isObject(extra) && extra.forcesRTL === true
|
|
4781
|
+
};
|
|
4782
|
+
}
|
|
4783
|
+
async function readText(file) {
|
|
4784
|
+
try {
|
|
4785
|
+
return await readFile2(file, "utf8");
|
|
4786
|
+
} catch (error) {
|
|
4787
|
+
if (error.code === "ENOENT") return void 0;
|
|
4788
|
+
throw error;
|
|
4789
|
+
}
|
|
4790
|
+
}
|
|
4791
|
+
async function readRecord(file) {
|
|
4792
|
+
const text = await readText(file);
|
|
4793
|
+
if (text === void 0) return void 0;
|
|
4794
|
+
let record;
|
|
4795
|
+
try {
|
|
4796
|
+
record = recordSchema.safeParse(JSON.parse(text)).data;
|
|
4797
|
+
} catch {
|
|
4798
|
+
record = void 0;
|
|
4799
|
+
}
|
|
4800
|
+
if (!record) {
|
|
4801
|
+
throw new LoupeError(
|
|
4802
|
+
"unsupported",
|
|
4803
|
+
`${file} isn't a record of loupe, so loupe can't put app.json back. Compare app.json with the version in git, then delete the record.`
|
|
4804
|
+
);
|
|
4805
|
+
}
|
|
4806
|
+
return record;
|
|
4807
|
+
}
|
|
4808
|
+
async function writeRecord(file, record) {
|
|
4809
|
+
await mkdir2(path5.dirname(file), { recursive: true });
|
|
4810
|
+
await writeFile2(file, `${JSON.stringify(record, null, 2)}
|
|
4811
|
+
`);
|
|
4812
|
+
}
|
|
4813
|
+
async function requireAppJson(projectRoot, mode, dynamicConfigPath) {
|
|
4814
|
+
const file = path5.resolve(projectRoot, "app.json");
|
|
4815
|
+
const text = await readText(file);
|
|
4816
|
+
if (text === void 0) {
|
|
4817
|
+
const config = dynamicConfigPath?.split(/[\\/]/).pop() ?? "app.config.js";
|
|
4818
|
+
throw new LoupeError(
|
|
4819
|
+
"unsupported",
|
|
4820
|
+
`loupe edits only app.json, and ${projectRoot} has none. Ask the user to ${mode === "on" ? 'add "supportsRTL: true" and "forcesRTL: true" to' : 'remove "supportsRTL" and "forcesRTL" from'} the extra of ${config}, then run expo-reload.`
|
|
4821
|
+
);
|
|
4822
|
+
}
|
|
4823
|
+
return { file, text };
|
|
4824
|
+
}
|
|
4825
|
+
async function setRtl(projectRoot, mode, dynamicConfigPath) {
|
|
4826
|
+
const { file, text } = await requireAppJson(
|
|
4827
|
+
projectRoot,
|
|
4828
|
+
mode,
|
|
4829
|
+
dynamicConfigPath
|
|
4830
|
+
);
|
|
4831
|
+
const recordFile = path5.resolve(projectRoot, RECORD_PATH);
|
|
4832
|
+
const record = await readRecord(recordFile);
|
|
4833
|
+
let next = text;
|
|
4834
|
+
let nextRecord = record;
|
|
4835
|
+
if (mode === "on") {
|
|
4836
|
+
next = withRtl(text, file);
|
|
4837
|
+
if (record) nextRecord = { ...record, written: next };
|
|
4838
|
+
else if (next !== text) nextRecord = { original: text, written: next };
|
|
4839
|
+
} else if (record) {
|
|
4840
|
+
next = text === record.written ? record.original : withKeysOf(text, record.original, file);
|
|
4841
|
+
nextRecord = void 0;
|
|
4842
|
+
} else if (rtlOf(text, file).forces) {
|
|
4843
|
+
throw new LoupeError(
|
|
4844
|
+
"unsupported",
|
|
4845
|
+
`${file} sets forcesRTL, and loupe didn't set it, so loupe doesn't change it. Ask the user.`
|
|
4846
|
+
);
|
|
4847
|
+
}
|
|
4848
|
+
if (nextRecord) await writeRecord(recordFile, nextRecord);
|
|
4849
|
+
if (next !== text) await writeFile2(file, next);
|
|
4850
|
+
if (!nextRecord && record) await rm(recordFile, { force: true });
|
|
4851
|
+
return {
|
|
4852
|
+
file,
|
|
4853
|
+
changed: next !== text,
|
|
4854
|
+
...rtlOf(next, file),
|
|
4855
|
+
undo: async () => {
|
|
4856
|
+
if (next !== text) await writeFile2(file, text);
|
|
4857
|
+
if (record) await writeRecord(recordFile, record);
|
|
4858
|
+
else await rm(recordFile, { force: true });
|
|
4859
|
+
}
|
|
4860
|
+
};
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4863
|
+
// src/expo/rtl.ts
|
|
4864
|
+
async function expoProject(context, port) {
|
|
4865
|
+
const app = await readExpoApp(context, port);
|
|
4866
|
+
if (!app.projectRoot) {
|
|
4867
|
+
throw new LoupeError(
|
|
4868
|
+
"unsupported",
|
|
4869
|
+
"The manifest of Metro gives no folder of the app, so loupe can't find app.json."
|
|
4870
|
+
);
|
|
4871
|
+
}
|
|
4872
|
+
return {
|
|
4873
|
+
projectRoot: app.projectRoot,
|
|
4874
|
+
dynamicConfigPath: app.dynamicConfigPath
|
|
4875
|
+
};
|
|
4876
|
+
}
|
|
4877
|
+
async function switchRtl(context, port, rtl, timeout) {
|
|
4878
|
+
const { projectRoot, dynamicConfigPath } = await expoProject(context, port);
|
|
4879
|
+
const change = await setRtl(projectRoot, rtl, dynamicConfigPath);
|
|
4880
|
+
try {
|
|
4881
|
+
await untilManifestRtl(context, port, change.forces, timeout);
|
|
4882
|
+
} catch (error) {
|
|
4883
|
+
await change.undo();
|
|
4884
|
+
throw error;
|
|
4885
|
+
}
|
|
4886
|
+
return change;
|
|
4887
|
+
}
|
|
4888
|
+
function directionOf({
|
|
4889
|
+
forces,
|
|
4890
|
+
supports
|
|
4891
|
+
}) {
|
|
4892
|
+
if (forces) return "rtl";
|
|
4893
|
+
return supports ? void 0 : "ltr";
|
|
4894
|
+
}
|
|
4895
|
+
|
|
4896
|
+
// src/commands/expo-rtl.ts
|
|
4897
|
+
var expoRtlCommand = defineCommand({
|
|
4898
|
+
name: "expo-rtl",
|
|
4899
|
+
summary: "Turn RTL on or off in the app.json of the app in Expo Go, then open the app again in that direction",
|
|
4900
|
+
input: z23.object({
|
|
4901
|
+
rtl: z23.enum(["on", "off"]).describe(
|
|
4902
|
+
`on: supportsRTL and forcesRTL in the extra of app.json; loupe keeps app.json as it was in ${RECORD_PATH}. off: app.json as it was before on.`
|
|
4903
|
+
),
|
|
4904
|
+
route: z23.string().optional().describe(
|
|
4905
|
+
"The route to open after the change, for example /settings. By default the route that the probe shows before it, else the root."
|
|
4906
|
+
),
|
|
4907
|
+
port: portField,
|
|
4908
|
+
timeout: showTimeoutField,
|
|
4909
|
+
device: deviceField
|
|
4910
|
+
}),
|
|
4911
|
+
positionals: ["rtl", "route"],
|
|
4912
|
+
output: shownSchema.extend({
|
|
4913
|
+
rtl: z23.enum(["on", "off"]),
|
|
4914
|
+
file: z23.string().describe("The app.json of the app, as an absolute path."),
|
|
4915
|
+
changed: z23.boolean().describe("True when loupe wrote app.json.")
|
|
4916
|
+
}),
|
|
4917
|
+
run: async ({ rtl, ...input }, context) => {
|
|
4918
|
+
const port = input.port ?? DEFAULT_PORT;
|
|
4919
|
+
const state2 = {};
|
|
4920
|
+
let shown;
|
|
4921
|
+
try {
|
|
4922
|
+
shown = await showApp(context, input, {
|
|
4923
|
+
reload: true,
|
|
4924
|
+
prepare: async () => {
|
|
4925
|
+
state2.change = await switchRtl(context, port, rtl, input.timeout);
|
|
4926
|
+
return directionOf(state2.change);
|
|
4927
|
+
}
|
|
4928
|
+
});
|
|
4929
|
+
} catch (error) {
|
|
4930
|
+
if (rtl === "on" && state2.change?.changed && error instanceof LoupeError) {
|
|
4931
|
+
throw new LoupeError(
|
|
4932
|
+
error.code,
|
|
4933
|
+
`${error.message} app.json keeps RTL on: run expo-rtl off to put it back.`,
|
|
4934
|
+
{ cause: error }
|
|
4935
|
+
);
|
|
4936
|
+
}
|
|
4937
|
+
throw error;
|
|
4938
|
+
}
|
|
4939
|
+
const { file, changed } = state2.change;
|
|
4940
|
+
return {
|
|
4941
|
+
...shown,
|
|
4942
|
+
warnings: shown.probe ? shown.warnings : [
|
|
4943
|
+
...shown.warnings,
|
|
4944
|
+
"The app has no probe, so loupe didn't see the direction on the screen."
|
|
4945
|
+
],
|
|
4946
|
+
rtl,
|
|
4947
|
+
file,
|
|
4948
|
+
changed
|
|
4949
|
+
};
|
|
4950
|
+
},
|
|
4951
|
+
format: ({ rtl, file, changed, ...shown }) => describeShown(
|
|
4952
|
+
`RTL ${rtl}: loupe ${changed ? "wrote" : "didn't change"} ${file}, stopped Expo Go and opened ${shown.link} again`,
|
|
4953
|
+
shown
|
|
4954
|
+
)
|
|
4955
|
+
});
|
|
4956
|
+
|
|
4957
|
+
// src/commands/expo-warm.ts
|
|
4958
|
+
import { z as z24 } from "zod";
|
|
4959
|
+
var expoWarmCommand = defineCommand({
|
|
4960
|
+
name: "expo-warm",
|
|
4961
|
+
summary: "Ask Metro for the app and its bundle, so that the first open in Expo Go is fast, and give the hash of the bundle",
|
|
4962
|
+
readOnly: true,
|
|
4963
|
+
input: z24.object({
|
|
4964
|
+
port: portField,
|
|
4965
|
+
timeout: z24.number().int().min(1e3).max(6e5).optional().describe(
|
|
4966
|
+
`How long to wait for the bundle at most, in ms. ${DEFAULT_BUNDLE_TIMEOUT} by default: a cold bundle of a large app can take minutes.`
|
|
4967
|
+
)
|
|
4968
|
+
}),
|
|
4969
|
+
output: z24.object({
|
|
4970
|
+
server: z24.string().describe("The Metro server that loupe asked."),
|
|
4971
|
+
link: z24.string().describe(
|
|
4972
|
+
"The link that opens the app in Expo Go on Android, after adb reverse of the port."
|
|
4973
|
+
),
|
|
4974
|
+
app: z24.object({
|
|
4975
|
+
name: z24.string().optional(),
|
|
4976
|
+
slug: z24.string().optional(),
|
|
4977
|
+
sdkVersion: z24.string().optional().describe(
|
|
4978
|
+
"The Expo SDK of the app, for example 58.0.0. Expo Go must have the same major version."
|
|
4979
|
+
)
|
|
4980
|
+
}),
|
|
4981
|
+
projectRoot: z24.string().optional().describe("The folder of the app on this machine, as Metro gives it."),
|
|
4982
|
+
bundle: z24.object({
|
|
4983
|
+
path: z24.string().describe("The path and query of the launch bundle on Metro."),
|
|
4984
|
+
ms: z24.number().describe(
|
|
4985
|
+
"How long the bundle took, in ms: seconds when cold, under a second when warm."
|
|
4986
|
+
),
|
|
4987
|
+
bytes: z24.number(),
|
|
4988
|
+
sha256: z24.string().describe(
|
|
4989
|
+
"The SHA-256 of the bundle. After an edit of the app's code, the same hash means that Metro didn't see the edit."
|
|
4990
|
+
)
|
|
4991
|
+
})
|
|
4992
|
+
}),
|
|
4993
|
+
run: (input, context) => warmExpo(context, input),
|
|
4994
|
+
format: ({ server, app, bundle }) => [
|
|
4995
|
+
`Metro at ${server}: ${app.name ?? app.slug ?? "the app"}`,
|
|
4996
|
+
...app.sdkVersion ? [` (SDK ${app.sdkVersion})`] : [],
|
|
4997
|
+
`. The bundle: ${(bundle.bytes / 1e6).toFixed(2)} MB in ${bundle.ms} ms, sha256 ${bundle.sha256.slice(0, 12)}.`
|
|
4998
|
+
].join("")
|
|
4999
|
+
});
|
|
5000
|
+
|
|
5001
|
+
// src/commands/hold.ts
|
|
5002
|
+
import { z as z25 } from "zod";
|
|
4093
5003
|
var holdCommand = defineCommand({
|
|
4094
5004
|
name: "hold",
|
|
4095
5005
|
summary: "Touch one point or element and hold it (a long press), by text, label or id",
|
|
4096
|
-
input:
|
|
5006
|
+
input: z25.object({
|
|
4097
5007
|
x: coordinateField("x").optional(),
|
|
4098
5008
|
y: coordinateField("y").optional(),
|
|
4099
5009
|
...selectorFields,
|
|
@@ -4123,12 +5033,12 @@ var holdCommand = defineCommand({
|
|
|
4123
5033
|
});
|
|
4124
5034
|
|
|
4125
5035
|
// src/commands/insets.ts
|
|
4126
|
-
import { z as
|
|
5036
|
+
import { z as z26 } from "zod";
|
|
4127
5037
|
var insetsCommand = defineCommand({
|
|
4128
5038
|
name: "insets",
|
|
4129
5039
|
summary: "Read the safe-area insets and the cutout of the current orientation",
|
|
4130
5040
|
readOnly: true,
|
|
4131
|
-
input:
|
|
5041
|
+
input: z26.object({
|
|
4132
5042
|
app: appField.describe(
|
|
4133
5043
|
"The package of the app under test, for example host.exp.exponent for Expo Go. loupe then reads the app's probe only while that app is in front. On a real device, loupe reads the probe only with this option."
|
|
4134
5044
|
),
|
|
@@ -4146,7 +5056,7 @@ var insetsCommand = defineCommand({
|
|
|
4146
5056
|
});
|
|
4147
5057
|
|
|
4148
5058
|
// src/commands/key.ts
|
|
4149
|
-
import { z as
|
|
5059
|
+
import { z as z27 } from "zod";
|
|
4150
5060
|
|
|
4151
5061
|
// src/core/keys.ts
|
|
4152
5062
|
var KEY_NAMES = [
|
|
@@ -4221,15 +5131,15 @@ async function pressAndroid(target, key2, app) {
|
|
|
4221
5131
|
var keyCommand = defineCommand({
|
|
4222
5132
|
name: "key",
|
|
4223
5133
|
summary: "Press one key, for example back, home or enter",
|
|
4224
|
-
input:
|
|
4225
|
-
key:
|
|
5134
|
+
input: z27.object({
|
|
5135
|
+
key: z27.enum(KEY_NAMES),
|
|
4226
5136
|
...waitFields,
|
|
4227
5137
|
app: appField,
|
|
4228
5138
|
device: deviceField
|
|
4229
5139
|
}),
|
|
4230
5140
|
positionals: ["key"],
|
|
4231
|
-
output:
|
|
4232
|
-
key:
|
|
5141
|
+
output: z27.object({
|
|
5142
|
+
key: z27.enum(KEY_NAMES),
|
|
4233
5143
|
waited: waitedSchema.optional()
|
|
4234
5144
|
}),
|
|
4235
5145
|
run: async ({ key: key2, app, device, ...wait }, context) => {
|
|
@@ -4242,10 +5152,10 @@ var keyCommand = defineCommand({
|
|
|
4242
5152
|
});
|
|
4243
5153
|
|
|
4244
5154
|
// src/commands/measure.ts
|
|
4245
|
-
import { z as
|
|
5155
|
+
import { z as z29 } from "zod";
|
|
4246
5156
|
|
|
4247
5157
|
// src/core/measure.ts
|
|
4248
|
-
import { z as
|
|
5158
|
+
import { z as z28 } from "zod";
|
|
4249
5159
|
function measureTargetOf(input) {
|
|
4250
5160
|
const targets = [
|
|
4251
5161
|
...input.row === void 0 ? [] : [{ line: { axis: "row", at: input.row } }],
|
|
@@ -4325,12 +5235,12 @@ function joinShortRuns(runs, minLength) {
|
|
|
4325
5235
|
flush();
|
|
4326
5236
|
return out;
|
|
4327
5237
|
}
|
|
4328
|
-
var runSchema =
|
|
4329
|
-
from:
|
|
4330
|
-
to:
|
|
4331
|
-
length:
|
|
4332
|
-
pixels:
|
|
4333
|
-
colour:
|
|
5238
|
+
var runSchema = z28.object({
|
|
5239
|
+
from: z28.number().describe("The start along the line, in dp."),
|
|
5240
|
+
to: z28.number().describe("The end along the line, in dp."),
|
|
5241
|
+
length: z28.number().describe("In dp."),
|
|
5242
|
+
pixels: z28.object({ from: z28.number(), to: z28.number() }).describe("The same run in px: from the first pixel to past the last."),
|
|
5243
|
+
colour: z28.string().optional().describe(
|
|
4334
5244
|
"The mean colour: #rrggbb, or #rrggbbaa when not opaque. Left out for a mix of short runs, for example text."
|
|
4335
5245
|
)
|
|
4336
5246
|
});
|
|
@@ -4343,20 +5253,20 @@ function runInDp(run, scale) {
|
|
|
4343
5253
|
colour: run.colour
|
|
4344
5254
|
};
|
|
4345
5255
|
}
|
|
4346
|
-
var lineSchema =
|
|
4347
|
-
axis:
|
|
4348
|
-
at:
|
|
4349
|
-
pixel:
|
|
4350
|
-
runs:
|
|
5256
|
+
var lineSchema = z28.object({
|
|
5257
|
+
axis: z28.enum(["row", "column"]),
|
|
5258
|
+
at: z28.number().describe("The row (y) or the column (x) in dp, at the whole pixel used."),
|
|
5259
|
+
pixel: z28.number().describe("The row or the column in px."),
|
|
5260
|
+
runs: z28.array(runSchema)
|
|
4351
5261
|
});
|
|
4352
|
-
var elementMeasureSchema =
|
|
5262
|
+
var elementMeasureSchema = z28.object({
|
|
4353
5263
|
toScreen: insetsSchema.describe(
|
|
4354
5264
|
"From each edge of the screen to the element, in dp."
|
|
4355
5265
|
),
|
|
4356
5266
|
toSafeArea: insetsSchema.describe(
|
|
4357
5267
|
"From each edge of the safe area to the element, in dp. Negative: the element reaches into the inset by that much."
|
|
4358
5268
|
),
|
|
4359
|
-
offCentre:
|
|
5269
|
+
offCentre: z28.object({
|
|
4360
5270
|
screen: pointSchema,
|
|
4361
5271
|
safeArea: pointSchema
|
|
4362
5272
|
}).describe(
|
|
@@ -4398,14 +5308,14 @@ function describeRun({ from, to, length, colour }) {
|
|
|
4398
5308
|
// src/commands/measure.ts
|
|
4399
5309
|
var DEFAULT_TOLERANCE = 8;
|
|
4400
5310
|
var DEFAULT_MIN_LENGTH = 1;
|
|
4401
|
-
var lineField = (axis, coordinate) =>
|
|
5311
|
+
var lineField = (axis, coordinate) => z29.number().min(0).optional().describe(
|
|
4402
5312
|
`Measure the colour runs along this ${axis} of a new screenshot: ${coordinate} in dp, from the top-left corner.`
|
|
4403
5313
|
);
|
|
4404
5314
|
var measureCommand = defineCommand({
|
|
4405
5315
|
name: "measure",
|
|
4406
5316
|
summary: "Measure the colour runs along a row or a column, or where an element sits on the screen and in the safe area",
|
|
4407
5317
|
readOnly: true,
|
|
4408
|
-
input:
|
|
5318
|
+
input: z29.object({
|
|
4409
5319
|
row: lineField("row", "y"),
|
|
4410
5320
|
column: lineField("column", "x"),
|
|
4411
5321
|
text: selectorFields.text.describe(
|
|
@@ -4417,10 +5327,10 @@ var measureCommand = defineCommand({
|
|
|
4417
5327
|
id: selectorFields.id.describe(
|
|
4418
5328
|
'Measure the element with this id: the resource-id on Android, or the part after ":id/".'
|
|
4419
5329
|
),
|
|
4420
|
-
tolerance:
|
|
5330
|
+
tolerance: z29.number().int().min(0).max(255).optional().describe(
|
|
4421
5331
|
`For a row or a column: a pixel stays in the run while no colour channel differs from the run's first pixel by more than this (0\u2013255). ${DEFAULT_TOLERANCE} by default.`
|
|
4422
5332
|
),
|
|
4423
|
-
minLength:
|
|
5333
|
+
minLength: z29.number().min(0).optional().describe(
|
|
4424
5334
|
`For a row or a column, in dp: two or more runs in a row that are each shorter than this become one run with no colour, for example text. ${DEFAULT_MIN_LENGTH} by default; 0 keeps each run.`
|
|
4425
5335
|
),
|
|
4426
5336
|
app: appField,
|
|
@@ -4431,9 +5341,9 @@ var measureCommand = defineCommand({
|
|
|
4431
5341
|
"The colour runs, from the left or the top. They cover the whole line."
|
|
4432
5342
|
),
|
|
4433
5343
|
element: elementSchema.extend(elementMeasureSchema.shape).extend({
|
|
4434
|
-
safeAreaSource:
|
|
5344
|
+
safeAreaSource: z29.enum(["probe", "dumpsys"]).describe("Where the safe area comes from, as in `insets`.")
|
|
4435
5345
|
}).optional(),
|
|
4436
|
-
warnings:
|
|
5346
|
+
warnings: z29.array(z29.string())
|
|
4437
5347
|
}),
|
|
4438
5348
|
run: async (input, context) => {
|
|
4439
5349
|
const { tolerance: tolerance2 = DEFAULT_TOLERANCE, minLength = DEFAULT_MIN_LENGTH } = input;
|
|
@@ -4509,57 +5419,12 @@ var measureCommand = defineCommand({
|
|
|
4509
5419
|
});
|
|
4510
5420
|
|
|
4511
5421
|
// src/commands/open-url.ts
|
|
4512
|
-
import { z as
|
|
4513
|
-
|
|
4514
|
-
// src/drivers/android/open-url.ts
|
|
4515
|
-
async function openUrlAndroid(target, url, app) {
|
|
4516
|
-
if (!app && target.kind === "device") {
|
|
4517
|
-
throw new LoupeError(
|
|
4518
|
-
"invalid_input",
|
|
4519
|
-
`${target.serial} is a real device, so loupe needs the "app" option: the package of the app under test. Then only that app opens the link.`
|
|
4520
|
-
);
|
|
4521
|
-
}
|
|
4522
|
-
const result = await target.adb.result([
|
|
4523
|
-
"shell",
|
|
4524
|
-
"am",
|
|
4525
|
-
"start",
|
|
4526
|
-
"-W",
|
|
4527
|
-
"-a",
|
|
4528
|
-
"android.intent.action.VIEW",
|
|
4529
|
-
"-d",
|
|
4530
|
-
shellQuote(url),
|
|
4531
|
-
...app ? ["-p", app] : []
|
|
4532
|
-
]);
|
|
4533
|
-
const start = parseAmStart(
|
|
4534
|
-
`${result.stdout.toString("utf8")}
|
|
4535
|
-
${result.stderr.toString("utf8")}`
|
|
4536
|
-
);
|
|
4537
|
-
if (start.unresolved) {
|
|
4538
|
-
throw new LoupeError(
|
|
4539
|
-
"no_handler",
|
|
4540
|
-
app ? `${app} doesn't open ${url} on ${target.serial}.` : `No app on ${target.serial} opens ${url}.`
|
|
4541
|
-
);
|
|
4542
|
-
}
|
|
4543
|
-
if (start.status !== "ok") {
|
|
4544
|
-
throw new LoupeError(
|
|
4545
|
-
"tool_failed",
|
|
4546
|
-
start.error ? `am start failed on ${target.serial}: ${start.error}` : `am start failed on ${target.serial} with exit code ${result.code}.`
|
|
4547
|
-
);
|
|
4548
|
-
}
|
|
4549
|
-
return {
|
|
4550
|
-
url,
|
|
4551
|
-
activity: start.activity,
|
|
4552
|
-
launchState: start.launchState?.toLowerCase(),
|
|
4553
|
-
totalTime: start.totalTime
|
|
4554
|
-
};
|
|
4555
|
-
}
|
|
4556
|
-
|
|
4557
|
-
// src/commands/open-url.ts
|
|
5422
|
+
import { z as z30 } from "zod";
|
|
4558
5423
|
var openUrlCommand = defineCommand({
|
|
4559
5424
|
name: "open-url",
|
|
4560
5425
|
summary: "Open a link (a deep link or a web page), and wait until it opens",
|
|
4561
|
-
input:
|
|
4562
|
-
url:
|
|
5426
|
+
input: z30.object({
|
|
5427
|
+
url: z30.string().regex(
|
|
4563
5428
|
/^[A-Za-z][A-Za-z0-9+.-]*:\S+$/,
|
|
4564
5429
|
"A URL starts with a scheme, for example https: or exp:, and has no spaces."
|
|
4565
5430
|
),
|
|
@@ -4570,11 +5435,11 @@ var openUrlCommand = defineCommand({
|
|
|
4570
5435
|
device: deviceField
|
|
4571
5436
|
}),
|
|
4572
5437
|
positionals: ["url"],
|
|
4573
|
-
output:
|
|
4574
|
-
url:
|
|
4575
|
-
activity:
|
|
4576
|
-
launchState:
|
|
4577
|
-
totalTime:
|
|
5438
|
+
output: z30.object({
|
|
5439
|
+
url: z30.string(),
|
|
5440
|
+
activity: z30.string().optional().describe("The activity that opened the link: package/activity."),
|
|
5441
|
+
launchState: z30.string().optional().describe("cold, warm or hot."),
|
|
5442
|
+
totalTime: z30.number().optional().describe("Milliseconds, as Android measured the start."),
|
|
4578
5443
|
waited: waitedSchema.optional()
|
|
4579
5444
|
}),
|
|
4580
5445
|
run: async ({ url, app, device, ...wait }, context) => {
|
|
@@ -4594,21 +5459,21 @@ var openUrlCommand = defineCommand({
|
|
|
4594
5459
|
});
|
|
4595
5460
|
|
|
4596
5461
|
// src/commands/pinch.ts
|
|
4597
|
-
import { z as
|
|
5462
|
+
import { z as z32 } from "zod";
|
|
4598
5463
|
|
|
4599
5464
|
// src/core/pinch.ts
|
|
4600
|
-
import { z as
|
|
5465
|
+
import { z as z31 } from "zod";
|
|
4601
5466
|
var pinchFields = {
|
|
4602
|
-
scale:
|
|
5467
|
+
scale: z31.number().positive().default(1).describe(
|
|
4603
5468
|
"The span between the fingers at the end \xF7 the span at the start. Above 1 spreads them (zoom in); below 1 brings them together (zoom out)."
|
|
4604
5469
|
),
|
|
4605
|
-
distance:
|
|
5470
|
+
distance: z31.number().positive().default(200).describe(
|
|
4606
5471
|
"The smaller span between the fingers, in dp: where a spread starts, or where a pinch ends. Android ignores a span under about 170 dp."
|
|
4607
5472
|
),
|
|
4608
|
-
angle:
|
|
5473
|
+
angle: z31.number().min(0).max(180).optional().describe(
|
|
4609
5474
|
"The line between the fingers at the start, in degrees clockwise from across the screen: 0 is across, 90 is down. Default: along the longer side of the screen."
|
|
4610
5475
|
),
|
|
4611
|
-
turn:
|
|
5476
|
+
turn: z31.number().default(0).describe(
|
|
4612
5477
|
"Degrees to turn the fingers around the centre during the gesture, clockwise. A negative value turns them the other way (on the CLI: --turn=-90)."
|
|
4613
5478
|
)
|
|
4614
5479
|
};
|
|
@@ -4651,21 +5516,21 @@ function planPinch(shape, screen, steps) {
|
|
|
4651
5516
|
});
|
|
4652
5517
|
return { angle, span: { from, to }, steps: plan };
|
|
4653
5518
|
}
|
|
4654
|
-
var pinchSchema =
|
|
4655
|
-
orientation:
|
|
5519
|
+
var pinchSchema = z31.object({
|
|
5520
|
+
orientation: z31.enum(ORIENTATIONS),
|
|
4656
5521
|
centre: pointSchema.describe("The centre of the pinch, in dp."),
|
|
4657
5522
|
element: elementSchema.optional().describe("The element that loupe pinched, when the input named one."),
|
|
4658
|
-
fingers:
|
|
4659
|
-
span:
|
|
5523
|
+
fingers: z31.array(z31.object({ from: pointSchema, to: pointSchema })).describe("Where each finger touched and where it lifted, in dp."),
|
|
5524
|
+
span: z31.object({ from: z31.number(), to: z31.number() }).describe(
|
|
4660
5525
|
"The span between the fingers at the start and at the end, in dp."
|
|
4661
5526
|
),
|
|
4662
|
-
scale:
|
|
4663
|
-
angle:
|
|
5527
|
+
scale: z31.number(),
|
|
5528
|
+
angle: z31.number().describe(
|
|
4664
5529
|
"The line between the fingers at the start, in degrees clockwise from across the screen."
|
|
4665
5530
|
),
|
|
4666
|
-
turn:
|
|
4667
|
-
duration:
|
|
4668
|
-
moveTime:
|
|
5531
|
+
turn: z31.number().describe("In degrees, clockwise."),
|
|
5532
|
+
duration: z31.number().describe("In milliseconds."),
|
|
5533
|
+
moveTime: z31.number().describe("Milliseconds that the move took, measured on the host.")
|
|
4669
5534
|
});
|
|
4670
5535
|
function describePinch(pinch) {
|
|
4671
5536
|
const { centre, element, span, turn, orientation, moveTime } = pinch;
|
|
@@ -4712,7 +5577,7 @@ async function pinchAndroid(target, centre, options, app) {
|
|
|
4712
5577
|
var pinchCommand = defineCommand({
|
|
4713
5578
|
name: "pinch",
|
|
4714
5579
|
summary: "Pinch or spread two fingers around a point or an element, and turn them (emulator only)",
|
|
4715
|
-
input:
|
|
5580
|
+
input: z32.object({
|
|
4716
5581
|
x: coordinateField("x").optional(),
|
|
4717
5582
|
y: coordinateField("y").optional(),
|
|
4718
5583
|
...selectorFields,
|
|
@@ -4759,14 +5624,14 @@ var pinchCommand = defineCommand({
|
|
|
4759
5624
|
});
|
|
4760
5625
|
|
|
4761
5626
|
// src/commands/rotate.ts
|
|
4762
|
-
import { z as
|
|
5627
|
+
import { z as z33 } from "zod";
|
|
4763
5628
|
var rotateCommand = defineCommand({
|
|
4764
5629
|
name: "rotate",
|
|
4765
5630
|
summary: "Turn the screen, and wait until it has turned",
|
|
4766
|
-
input:
|
|
4767
|
-
to:
|
|
5631
|
+
input: z33.object({
|
|
5632
|
+
to: z33.enum(["portrait", "landscape-left", "landscape-right"]).describe(orientationDescription),
|
|
4768
5633
|
device: deviceField,
|
|
4769
|
-
timeout:
|
|
5634
|
+
timeout: z33.number().int().min(0).default(5e3).describe("Milliseconds to wait for the screen to turn.")
|
|
4770
5635
|
}),
|
|
4771
5636
|
positionals: ["to"],
|
|
4772
5637
|
output: displaySchema,
|
|
@@ -4775,22 +5640,22 @@ var rotateCommand = defineCommand({
|
|
|
4775
5640
|
});
|
|
4776
5641
|
|
|
4777
5642
|
// src/commands/screenshot.ts
|
|
4778
|
-
import { z as
|
|
5643
|
+
import { z as z34 } from "zod";
|
|
4779
5644
|
var screenshotCommand = defineCommand({
|
|
4780
5645
|
name: "screenshot",
|
|
4781
5646
|
summary: "Save the screen as a PNG file, upright in each orientation",
|
|
4782
5647
|
readOnly: true,
|
|
4783
|
-
input:
|
|
4784
|
-
out:
|
|
5648
|
+
input: z34.object({
|
|
5649
|
+
out: z34.string().min(1).describe(
|
|
4785
5650
|
"The PNG file to write. loupe makes its folder, and replaces a file that is there."
|
|
4786
5651
|
),
|
|
4787
|
-
crop:
|
|
5652
|
+
crop: z34.string().regex(
|
|
4788
5653
|
CROP_PATTERN,
|
|
4789
5654
|
"A crop is x,y,width,height in dp, for example 0,0,411,64."
|
|
4790
5655
|
).optional().describe(
|
|
4791
5656
|
"Save only this part of the screen: x,y,width,height in dp, from the top-left corner of the current orientation. The part outside the screen is left out."
|
|
4792
5657
|
),
|
|
4793
|
-
scale:
|
|
5658
|
+
scale: z34.number().gt(0).max(1).optional().describe(
|
|
4794
5659
|
"Scale the image down by this factor, for example 0.5 for half the width and half the height. A smaller file costs fewer tokens."
|
|
4795
5660
|
),
|
|
4796
5661
|
app: appField,
|
|
@@ -4798,8 +5663,8 @@ var screenshotCommand = defineCommand({
|
|
|
4798
5663
|
}),
|
|
4799
5664
|
positionals: ["out"],
|
|
4800
5665
|
output: displaySchema.extend({
|
|
4801
|
-
file:
|
|
4802
|
-
image:
|
|
5666
|
+
file: z34.string().describe("The PNG file, as an absolute path."),
|
|
5667
|
+
image: z34.object({ width: z34.number(), height: z34.number() }).describe(
|
|
4803
5668
|
"The size of the PNG file, in px: the screen, or the crop, after the scale."
|
|
4804
5669
|
),
|
|
4805
5670
|
crop: rectSchema.optional().describe(
|
|
@@ -4847,7 +5712,7 @@ var screenshotCommand = defineCommand({
|
|
|
4847
5712
|
});
|
|
4848
5713
|
|
|
4849
5714
|
// src/commands/scroll-to.ts
|
|
4850
|
-
import { z as
|
|
5715
|
+
import { z as z35 } from "zod";
|
|
4851
5716
|
|
|
4852
5717
|
// src/core/scroll.ts
|
|
4853
5718
|
var DIRECTIONS = ["down", "up", "left", "right"];
|
|
@@ -4901,19 +5766,21 @@ function scrollStroke(frame, direction, share = SCROLL_SHARE) {
|
|
|
4901
5766
|
const along = (at) => axisOf(direction) === "y" ? { x: frame.x + frame.width / 2, y: frame.y + frame.height * at } : { x: frame.x + frame.width * at, y: frame.y + frame.height / 2 };
|
|
4902
5767
|
return direction === "down" || direction === "right" ? { from: along(start), to: along(end) } : { from: along(end), to: along(start) };
|
|
4903
5768
|
}
|
|
4904
|
-
function viewContent(nodes, frame) {
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
5769
|
+
function viewContent(nodes, frame, app) {
|
|
5770
|
+
const rows = [];
|
|
5771
|
+
const walk = (list) => {
|
|
5772
|
+
for (const node of list) {
|
|
5773
|
+
if (isExpoGoOverlay(node, app)) continue;
|
|
5774
|
+
if (intersection(node.frame, frame) !== null) {
|
|
5775
|
+
const { type, text, label: label2, id } = node;
|
|
5776
|
+
const { x, y, width, height } = node.frame;
|
|
5777
|
+
rows.push([type, text, label2, id, x, y, width, height]);
|
|
5778
|
+
}
|
|
5779
|
+
walk(node.children ?? []);
|
|
5780
|
+
}
|
|
5781
|
+
};
|
|
5782
|
+
walk(nodes);
|
|
5783
|
+
return JSON.stringify(rows);
|
|
4917
5784
|
}
|
|
4918
5785
|
function cutAtIncomingEdge(element, view, direction, tolerance2) {
|
|
4919
5786
|
switch (direction) {
|
|
@@ -4957,12 +5824,12 @@ async function scrollToAndroid(target, selector, options, app) {
|
|
|
4957
5824
|
);
|
|
4958
5825
|
}
|
|
4959
5826
|
view = next;
|
|
4960
|
-
const before = viewContent(ui.nodes, next.frame);
|
|
5827
|
+
const before = viewContent(ui.nodes, next.frame, app);
|
|
4961
5828
|
const { from, to } = scrollStroke(next.frame, direction, share);
|
|
4962
5829
|
await dragAndroid(target, from, to, STROKE, app);
|
|
4963
5830
|
scrolls += 1;
|
|
4964
5831
|
ui = await readAndroidUi(target, app);
|
|
4965
|
-
ended = viewContent(ui.nodes, next.frame) === before;
|
|
5832
|
+
ended = viewContent(ui.nodes, next.frame, app) === before;
|
|
4966
5833
|
};
|
|
4967
5834
|
for (; ; ) {
|
|
4968
5835
|
if (elementsOnScreen(ui.nodes, selector, ui.display.size).length > 0) {
|
|
@@ -5011,11 +5878,11 @@ async function scrollOnceAndroid(target, app) {
|
|
|
5011
5878
|
const ui = await readAndroidUi(target, app);
|
|
5012
5879
|
const view = scrollViewFor(ui.nodes, "down", ui.display.size);
|
|
5013
5880
|
if (!view || scrollAxisOf(view) !== "y") return void 0;
|
|
5014
|
-
const top = viewContent(ui.nodes, view.frame);
|
|
5881
|
+
const top = viewContent(ui.nodes, view.frame, app);
|
|
5015
5882
|
const { from, to } = scrollStroke(view.frame, "down");
|
|
5016
5883
|
await dragAndroid(target, from, to, STROKE, app);
|
|
5017
5884
|
const after = await readAndroidUi(target, app);
|
|
5018
|
-
return viewContent(after.nodes, view.frame) === top ? void 0 : { frame: view.frame, top };
|
|
5885
|
+
return viewContent(after.nodes, view.frame, app) === top ? void 0 : { frame: view.frame, top };
|
|
5019
5886
|
}
|
|
5020
5887
|
async function flingToTopAndroid(target, { frame, top }, app) {
|
|
5021
5888
|
const { from, to } = scrollStroke(frame, "up");
|
|
@@ -5024,7 +5891,11 @@ async function flingToTopAndroid(target, { frame, top }, app) {
|
|
|
5024
5891
|
while (flings < MAX_FLINGS) {
|
|
5025
5892
|
await swipeAndroid(target, from, to, FLING_MS, app);
|
|
5026
5893
|
flings += 1;
|
|
5027
|
-
const now = viewContent(
|
|
5894
|
+
const now = viewContent(
|
|
5895
|
+
(await readAndroidUi(target, app)).nodes,
|
|
5896
|
+
frame,
|
|
5897
|
+
app
|
|
5898
|
+
);
|
|
5028
5899
|
if (now === top) return [];
|
|
5029
5900
|
if (now === shown) break;
|
|
5030
5901
|
shown = now;
|
|
@@ -5039,7 +5910,7 @@ var DEFAULT_MAX_SCROLLS = 20;
|
|
|
5039
5910
|
var scrollToCommand = defineCommand({
|
|
5040
5911
|
name: "scroll-to",
|
|
5041
5912
|
summary: "Scroll until the element with a text, label or id is in view, and give its frame",
|
|
5042
|
-
input:
|
|
5913
|
+
input: z35.object({
|
|
5043
5914
|
text: selectorFields.text.describe(
|
|
5044
5915
|
"Scroll to the element with this text: the whole text, not a part."
|
|
5045
5916
|
),
|
|
@@ -5049,13 +5920,13 @@ var scrollToCommand = defineCommand({
|
|
|
5049
5920
|
id: selectorFields.id.describe(
|
|
5050
5921
|
'Scroll to the element with this id: the resource-id on Android, or the part after ":id/".'
|
|
5051
5922
|
),
|
|
5052
|
-
direction:
|
|
5923
|
+
direction: z35.enum(DIRECTIONS).default("down").describe(
|
|
5053
5924
|
"Where the content to show is: down shows what is below, so the touch moves up."
|
|
5054
5925
|
),
|
|
5055
|
-
maxScrolls:
|
|
5926
|
+
maxScrolls: z35.number().int().min(0).max(200).default(DEFAULT_MAX_SCROLLS).describe(
|
|
5056
5927
|
"The most drags. Each one moves the scroll view by 60 % of its length."
|
|
5057
5928
|
),
|
|
5058
|
-
in:
|
|
5929
|
+
in: z35.string().min(1).optional().describe(
|
|
5059
5930
|
"The id of the scroll view to drag. By default, the innermost scroll view on the screen that scrolls along the direction; the largest one when there are more."
|
|
5060
5931
|
),
|
|
5061
5932
|
app: appField,
|
|
@@ -5063,8 +5934,8 @@ var scrollToCommand = defineCommand({
|
|
|
5063
5934
|
}),
|
|
5064
5935
|
output: displaySchema.extend({
|
|
5065
5936
|
element: elementSchema.describe("The element, as it shows at the end."),
|
|
5066
|
-
direction:
|
|
5067
|
-
scrolls:
|
|
5937
|
+
direction: z35.enum(DIRECTIONS),
|
|
5938
|
+
scrolls: z35.number().describe("The drags that loupe made: 0 when the element was in view."),
|
|
5068
5939
|
scrollView: elementSchema.optional().describe("The scroll view of the last drag. Left out with no drag.")
|
|
5069
5940
|
}),
|
|
5070
5941
|
run: async (input, context) => {
|
|
@@ -5093,12 +5964,12 @@ var scrollToCommand = defineCommand({
|
|
|
5093
5964
|
});
|
|
5094
5965
|
|
|
5095
5966
|
// src/commands/sweep.ts
|
|
5096
|
-
import
|
|
5097
|
-
import { z as
|
|
5967
|
+
import path7 from "path";
|
|
5968
|
+
import { z as z37 } from "zod";
|
|
5098
5969
|
|
|
5099
5970
|
// src/core/sweep.ts
|
|
5100
|
-
import
|
|
5101
|
-
import { z as
|
|
5971
|
+
import path6 from "path";
|
|
5972
|
+
import { z as z36 } from "zod";
|
|
5102
5973
|
|
|
5103
5974
|
// src/core/contact-sheet.ts
|
|
5104
5975
|
var BACKGROUND = [32, 32, 32];
|
|
@@ -5208,47 +6079,56 @@ function contactSheet(cells, { thumbnailWidth = 240, columns, maxWidth = 1600 }
|
|
|
5208
6079
|
|
|
5209
6080
|
// src/core/sweep.ts
|
|
5210
6081
|
var SWEEP_THEMES = ["light", "dark"];
|
|
6082
|
+
var SWEEP_DIRECTIONS = ["ltr", "rtl"];
|
|
5211
6083
|
var THUMBNAIL_WIDTH = 240;
|
|
5212
6084
|
var NO_SHOT = { width: THUMBNAIL_WIDTH, height: 427 };
|
|
5213
|
-
var sweepScreenSchema =
|
|
5214
|
-
number:
|
|
6085
|
+
var sweepScreenSchema = z36.object({
|
|
6086
|
+
number: z36.number().describe(
|
|
5215
6087
|
"The place of the link in the list, from 1: the number of its cell on each contact sheet, and of its screenshot file."
|
|
5216
6088
|
),
|
|
5217
|
-
url:
|
|
5218
|
-
variant:
|
|
5219
|
-
|
|
6089
|
+
url: z36.string(),
|
|
6090
|
+
variant: z36.string().describe(
|
|
6091
|
+
"The orientation and the theme, and the direction in a sweep with directions: portrait-dark, portrait-dark-rtl."
|
|
6092
|
+
),
|
|
6093
|
+
scrolled: z36.boolean().describe(
|
|
5220
6094
|
"True for the check after one scroll down. It comes right after the check of its link at the top."
|
|
5221
6095
|
),
|
|
5222
|
-
|
|
6096
|
+
reloaded: z36.boolean().describe(
|
|
6097
|
+
"True when loupe stopped the app before this link, so the link started it again."
|
|
6098
|
+
),
|
|
6099
|
+
passed: z36.boolean().describe("True when loupe checked the screen and every rule passed."),
|
|
5223
6100
|
check: screenCheckSchema.optional().describe("The result of each rule, as `check` gives it."),
|
|
5224
|
-
error:
|
|
6101
|
+
error: z36.object({ code: z36.enum(ERROR_CODES), message: z36.string() }).optional().describe(
|
|
5225
6102
|
"Why loupe could not check this screen. The sweep went on with the next one."
|
|
5226
6103
|
),
|
|
5227
|
-
screenshot:
|
|
5228
|
-
warnings:
|
|
5229
|
-
ms:
|
|
6104
|
+
screenshot: z36.string().optional().describe("The file. Left out when loupe could take no screenshot."),
|
|
6105
|
+
warnings: z36.array(z36.string()),
|
|
6106
|
+
ms: z36.number().describe(
|
|
5230
6107
|
"Milliseconds for this screen, from the open, or from the scroll for a scrolled screen."
|
|
5231
6108
|
)
|
|
5232
6109
|
});
|
|
5233
|
-
var sweepVariantSchema =
|
|
5234
|
-
name:
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
6110
|
+
var sweepVariantSchema = z36.object({
|
|
6111
|
+
name: z36.string().describe(
|
|
6112
|
+
"The orientation and the theme, and the direction in a sweep with directions: portrait-dark, portrait-dark-rtl."
|
|
6113
|
+
),
|
|
6114
|
+
orientation: z36.enum(ORIENTATIONS),
|
|
6115
|
+
theme: z36.string().describe("light or dark, or the setting of the device."),
|
|
6116
|
+
direction: z36.enum(SWEEP_DIRECTIONS).optional().describe("ltr or rtl. Left out in a sweep with no directions."),
|
|
6117
|
+
sheet: z36.string().describe(
|
|
5238
6118
|
"The contact sheet: a thumbnail of each screen with its number, in a red frame when the screen failed."
|
|
5239
6119
|
),
|
|
5240
|
-
scrolledSheet:
|
|
6120
|
+
scrolledSheet: z36.string().optional().describe(
|
|
5241
6121
|
"The contact sheet of the scrolled screens, each with the number of its link. Left out when no screen scrolled."
|
|
5242
6122
|
),
|
|
5243
|
-
screens:
|
|
5244
|
-
failed:
|
|
6123
|
+
screens: z36.number().describe("The screens checked: one for each link, and each scrolled one."),
|
|
6124
|
+
failed: z36.number()
|
|
5245
6125
|
});
|
|
5246
|
-
var sweepReportSchema =
|
|
5247
|
-
out:
|
|
5248
|
-
passed:
|
|
5249
|
-
variants:
|
|
5250
|
-
screens:
|
|
5251
|
-
warnings:
|
|
6126
|
+
var sweepReportSchema = z36.object({
|
|
6127
|
+
out: z36.string().describe("The folder with each file of the sweep."),
|
|
6128
|
+
passed: z36.boolean().describe("True when every screen passed."),
|
|
6129
|
+
variants: z36.array(sweepVariantSchema),
|
|
6130
|
+
screens: z36.array(sweepScreenSchema),
|
|
6131
|
+
warnings: z36.array(z36.string())
|
|
5252
6132
|
});
|
|
5253
6133
|
function fileNumber(number, count) {
|
|
5254
6134
|
return String(number).padStart(Math.max(2, String(count).length), "0");
|
|
@@ -5318,107 +6198,134 @@ function outcomeOf(screen) {
|
|
|
5318
6198
|
if (screen.error) return `error ${screen.error.code}`;
|
|
5319
6199
|
return screen.passed ? "passed" : "failed";
|
|
5320
6200
|
}
|
|
5321
|
-
async function sweep(driver, {
|
|
5322
|
-
|
|
6201
|
+
async function sweep(driver, {
|
|
6202
|
+
urls,
|
|
6203
|
+
orientations,
|
|
6204
|
+
themes,
|
|
6205
|
+
out,
|
|
6206
|
+
scroll,
|
|
6207
|
+
reloadEvery,
|
|
6208
|
+
directions
|
|
6209
|
+
}, { signal, progress } = {}) {
|
|
6210
|
+
const folder = path6.resolve(out);
|
|
5323
6211
|
const start = await driver.look();
|
|
5324
6212
|
const screens = [];
|
|
5325
6213
|
const variants = [];
|
|
5326
6214
|
const warnings = [];
|
|
5327
6215
|
const orientationList = orientations ?? [start.orientation];
|
|
5328
6216
|
const themeList = themes ?? [start.theme];
|
|
5329
|
-
const
|
|
6217
|
+
const directionList = directions ? [...directions] : [void 0];
|
|
6218
|
+
const total = urls.length * orientationList.length * themeList.length * directionList.length;
|
|
5330
6219
|
let done = 0;
|
|
6220
|
+
let opens = 0;
|
|
6221
|
+
let coldNext = false;
|
|
5331
6222
|
try {
|
|
5332
|
-
for (const
|
|
5333
|
-
|
|
5334
|
-
const
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
)
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
"cancelled",
|
|
5362
|
-
`The call was cancelled, so loupe stopped the sweep after ${done} of ${total} screens. The screenshots so far are in ${folder}; it wrote no report.`
|
|
6223
|
+
for (const direction of directionList) {
|
|
6224
|
+
if (direction) {
|
|
6225
|
+
const { restarted } = await driver.setDirection(direction);
|
|
6226
|
+
if (restarted) coldNext = true;
|
|
6227
|
+
}
|
|
6228
|
+
for (const orientation of orientationList) {
|
|
6229
|
+
for (const theme of themeList) {
|
|
6230
|
+
const name2 = direction ? `${orientation}-${theme}-${direction}` : `${orientation}-${theme}`;
|
|
6231
|
+
const topCells = [];
|
|
6232
|
+
const scrolledCells = [];
|
|
6233
|
+
let count = 0;
|
|
6234
|
+
let failed = 0;
|
|
6235
|
+
const keep = async (screen, png, began) => {
|
|
6236
|
+
if (png) {
|
|
6237
|
+
const file = `${fileNumber(screen.number, urls.length)}${screen.scrolled ? "-scrolled" : ""}.png`;
|
|
6238
|
+
screen.screenshot = await writeOutputFile(
|
|
6239
|
+
path6.join(folder, name2, file),
|
|
6240
|
+
png
|
|
6241
|
+
);
|
|
6242
|
+
}
|
|
6243
|
+
screen.ms = Date.now() - began;
|
|
6244
|
+
screens.push(screen);
|
|
6245
|
+
count += 1;
|
|
6246
|
+
if (!screen.passed) failed += 1;
|
|
6247
|
+
const image = thumbnailOf(png);
|
|
6248
|
+
const { number } = screen;
|
|
6249
|
+
const cells = screen.scrolled ? scrolledCells : topCells;
|
|
6250
|
+
cells.push(
|
|
6251
|
+
image ? { number, image, failed: !screen.passed } : { number, failed: true }
|
|
5363
6252
|
);
|
|
5364
|
-
}
|
|
5365
|
-
const
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
warnings: [],
|
|
5372
|
-
ms: 0
|
|
5373
|
-
});
|
|
5374
|
-
const opened = Date.now();
|
|
5375
|
-
const top = screenOf(false);
|
|
5376
|
-
const png = await checkScreen(driver, top, async () => {
|
|
5377
|
-
await driver.open(url);
|
|
5378
|
-
if (orientations) await driver.rotate(orientation);
|
|
5379
|
-
if (themes) {
|
|
5380
|
-
top.warnings.push(...await driver.setTheme(theme));
|
|
6253
|
+
};
|
|
6254
|
+
for (const [index, url] of urls.entries()) {
|
|
6255
|
+
if (signal?.aborted) {
|
|
6256
|
+
throw new LoupeError(
|
|
6257
|
+
"cancelled",
|
|
6258
|
+
`The call was cancelled, so loupe stopped the sweep after ${done} of ${total} screens. The screenshots so far are in ${folder}; it wrote no report.`
|
|
6259
|
+
);
|
|
5381
6260
|
}
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
const
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
6261
|
+
const reload = reloadEvery !== void 0 && opens > 0 && opens % reloadEvery === 0;
|
|
6262
|
+
opens += 1;
|
|
6263
|
+
const cold = reload || coldNext;
|
|
6264
|
+
coldNext = false;
|
|
6265
|
+
const screenOf = (scrolled) => ({
|
|
6266
|
+
number: index + 1,
|
|
6267
|
+
url,
|
|
6268
|
+
variant: name2,
|
|
6269
|
+
scrolled,
|
|
6270
|
+
reloaded: reload && !scrolled,
|
|
6271
|
+
passed: false,
|
|
6272
|
+
warnings: [],
|
|
6273
|
+
ms: 0
|
|
6274
|
+
});
|
|
6275
|
+
const opened = Date.now();
|
|
6276
|
+
const top = screenOf(false);
|
|
6277
|
+
const png = await checkScreen(driver, top, async () => {
|
|
6278
|
+
if (reload) await driver.reload();
|
|
6279
|
+
await driver.open(url, { cold, direction });
|
|
6280
|
+
if (orientations) await driver.rotate(orientation);
|
|
6281
|
+
if (themes) {
|
|
6282
|
+
top.warnings.push(
|
|
6283
|
+
...await driver.setTheme(theme)
|
|
6284
|
+
);
|
|
6285
|
+
}
|
|
6286
|
+
});
|
|
6287
|
+
await keep(top, png, opened);
|
|
6288
|
+
let below;
|
|
6289
|
+
if (scroll && !top.error) {
|
|
6290
|
+
const began = Date.now();
|
|
6291
|
+
const screen = screenOf(true);
|
|
6292
|
+
const shown = await checkScrolled(driver, screen);
|
|
6293
|
+
if (shown) {
|
|
6294
|
+
await keep(screen, shown.png, began);
|
|
6295
|
+
below = screen;
|
|
6296
|
+
}
|
|
5392
6297
|
}
|
|
6298
|
+
done += 1;
|
|
6299
|
+
progress?.({
|
|
6300
|
+
progress: done,
|
|
6301
|
+
total,
|
|
6302
|
+
message: `${name2}, link ${index + 1} of ${urls.length}${reload ? ", after a restart" : ""}: ${outcomeOf(top)}${below ? `; scrolled: ${outcomeOf(below)}` : ""}`
|
|
6303
|
+
});
|
|
5393
6304
|
}
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
6305
|
+
variants.push({
|
|
6306
|
+
name: name2,
|
|
6307
|
+
orientation,
|
|
6308
|
+
theme,
|
|
6309
|
+
...direction ? { direction } : {},
|
|
6310
|
+
sheet: await writeSheet(path6.join(folder, `${name2}.png`), topCells),
|
|
6311
|
+
...scrolledCells.length > 0 ? {
|
|
6312
|
+
scrolledSheet: await writeSheet(
|
|
6313
|
+
path6.join(folder, `${name2}-scrolled.png`),
|
|
6314
|
+
scrolledCells
|
|
6315
|
+
)
|
|
6316
|
+
} : {},
|
|
6317
|
+
screens: count,
|
|
6318
|
+
failed
|
|
5399
6319
|
});
|
|
5400
6320
|
}
|
|
5401
|
-
variants.push({
|
|
5402
|
-
name: name2,
|
|
5403
|
-
orientation,
|
|
5404
|
-
theme,
|
|
5405
|
-
sheet: await writeSheet(path5.join(folder, `${name2}.png`), topCells),
|
|
5406
|
-
...scrolledCells.length > 0 ? {
|
|
5407
|
-
scrolledSheet: await writeSheet(
|
|
5408
|
-
path5.join(folder, `${name2}-scrolled.png`),
|
|
5409
|
-
scrolledCells
|
|
5410
|
-
)
|
|
5411
|
-
} : {},
|
|
5412
|
-
screens: count,
|
|
5413
|
-
failed
|
|
5414
|
-
});
|
|
5415
6321
|
}
|
|
5416
6322
|
}
|
|
5417
6323
|
} finally {
|
|
5418
6324
|
warnings.push(
|
|
5419
6325
|
...await driver.restore(start, {
|
|
5420
6326
|
orientation: orientations !== void 0,
|
|
5421
|
-
theme: themes !== void 0
|
|
6327
|
+
theme: themes !== void 0,
|
|
6328
|
+
direction: directions !== void 0
|
|
5422
6329
|
})
|
|
5423
6330
|
);
|
|
5424
6331
|
}
|
|
@@ -5430,7 +6337,7 @@ async function sweep(driver, { urls, orientations, themes, out, scroll }, { sign
|
|
|
5430
6337
|
warnings
|
|
5431
6338
|
};
|
|
5432
6339
|
await writeOutputFile(
|
|
5433
|
-
|
|
6340
|
+
path6.join(folder, "report.json"),
|
|
5434
6341
|
Buffer.from(`${JSON.stringify(report, null, 2)}
|
|
5435
6342
|
`)
|
|
5436
6343
|
);
|
|
@@ -5438,7 +6345,7 @@ async function sweep(driver, { urls, orientations, themes, out, scroll }, { sign
|
|
|
5438
6345
|
}
|
|
5439
6346
|
|
|
5440
6347
|
// src/drivers/android/theme.ts
|
|
5441
|
-
import { setTimeout as
|
|
6348
|
+
import { setTimeout as sleep9 } from "timers/promises";
|
|
5442
6349
|
var THEMES = ["light", "dark"];
|
|
5443
6350
|
var THEME_SETTINGS = [...THEMES, "auto", "custom"];
|
|
5444
6351
|
var NIGHT = { light: "no", dark: "yes" };
|
|
@@ -5488,7 +6395,7 @@ async function probeScheme(target, app, theme, { timeout, interval }) {
|
|
|
5488
6395
|
`The theme is ${theme} now, but loupe can't see the app show it. ${failure2.message}`
|
|
5489
6396
|
);
|
|
5490
6397
|
}
|
|
5491
|
-
await
|
|
6398
|
+
await sleep9(interval);
|
|
5492
6399
|
}
|
|
5493
6400
|
}
|
|
5494
6401
|
async function setThemeAndroid(target, theme, app, { timeout = 5e3, interval = DEFAULT_WAIT_INTERVAL } = {}) {
|
|
@@ -5553,15 +6460,56 @@ async function orWarning(restore) {
|
|
|
5553
6460
|
return [error.message];
|
|
5554
6461
|
}
|
|
5555
6462
|
}
|
|
5556
|
-
function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5e3 }) {
|
|
6463
|
+
function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5e3, coldTimeout = 12e4 }, metro) {
|
|
6464
|
+
let lastUrl;
|
|
6465
|
+
const openCold = (url, direction) => showInExpoGo(target, {
|
|
6466
|
+
link: url,
|
|
6467
|
+
route: routeOfLink(url),
|
|
6468
|
+
direction,
|
|
6469
|
+
timeout: coldTimeout
|
|
6470
|
+
});
|
|
6471
|
+
const needMetro = () => {
|
|
6472
|
+
if (!metro || app !== EXPO_GO2) {
|
|
6473
|
+
throw new LoupeError(
|
|
6474
|
+
"invalid_input",
|
|
6475
|
+
"A sweep with direction needs the app in Expo Go: app host.exp.exponent."
|
|
6476
|
+
);
|
|
6477
|
+
}
|
|
6478
|
+
return metro;
|
|
6479
|
+
};
|
|
5557
6480
|
return {
|
|
5558
6481
|
look: async () => ({
|
|
5559
6482
|
orientation: (await readAndroidDisplay(target)).orientation,
|
|
5560
6483
|
theme: await readThemeAndroid(target)
|
|
5561
6484
|
}),
|
|
5562
|
-
open: async (url) => {
|
|
6485
|
+
open: async (url, { cold, direction }) => {
|
|
6486
|
+
lastUrl = url;
|
|
6487
|
+
if (cold && app === EXPO_GO2) {
|
|
6488
|
+
await openCold(url, direction);
|
|
6489
|
+
return;
|
|
6490
|
+
}
|
|
5563
6491
|
await openUrlAndroid(target, url, app);
|
|
5564
6492
|
},
|
|
6493
|
+
setDirection: async (direction) => {
|
|
6494
|
+
const { context, port } = needMetro();
|
|
6495
|
+
const change = await switchRtl(
|
|
6496
|
+
context,
|
|
6497
|
+
port,
|
|
6498
|
+
direction === "rtl" ? "on" : "off"
|
|
6499
|
+
);
|
|
6500
|
+
if (!change.changed) return { restarted: false };
|
|
6501
|
+
await forceStopAndroid(target, EXPO_GO2);
|
|
6502
|
+
return { restarted: true };
|
|
6503
|
+
},
|
|
6504
|
+
reload: async () => {
|
|
6505
|
+
if (!app) {
|
|
6506
|
+
throw new LoupeError(
|
|
6507
|
+
"invalid_input",
|
|
6508
|
+
"A sweep with reloadEvery needs app: the package that loupe stops."
|
|
6509
|
+
);
|
|
6510
|
+
}
|
|
6511
|
+
await forceStopAndroid(target, app);
|
|
6512
|
+
},
|
|
5565
6513
|
rotate: async (orientation) => {
|
|
5566
6514
|
if ((await readAndroidDisplay(target)).orientation === orientation) return;
|
|
5567
6515
|
await rotateAndroid(target, orientation, { timeout: rotateTimeout });
|
|
@@ -5604,7 +6552,15 @@ function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5
|
|
|
5604
6552
|
}) : [],
|
|
5605
6553
|
...changed.theme ? await orWarning(
|
|
5606
6554
|
() => restoreThemeAndroid(target, look.theme)
|
|
5607
|
-
) : []
|
|
6555
|
+
) : [],
|
|
6556
|
+
// app.json goes back as it was, and the app opens its last link again
|
|
6557
|
+
// in that direction.
|
|
6558
|
+
...changed.direction && metro ? await orWarning(async () => {
|
|
6559
|
+
const change = await switchRtl(metro.context, metro.port, "off");
|
|
6560
|
+
if (!change.changed) return;
|
|
6561
|
+
await forceStopAndroid(target, EXPO_GO2);
|
|
6562
|
+
if (lastUrl) await openCold(lastUrl, directionOf(change));
|
|
6563
|
+
}) : []
|
|
5608
6564
|
]
|
|
5609
6565
|
};
|
|
5610
6566
|
}
|
|
@@ -5631,43 +6587,53 @@ var failureSchema = sweepScreenSchema.pick({
|
|
|
5631
6587
|
url: true,
|
|
5632
6588
|
variant: true,
|
|
5633
6589
|
scrolled: true,
|
|
6590
|
+
reloaded: true,
|
|
5634
6591
|
screenshot: true,
|
|
5635
6592
|
error: true
|
|
5636
6593
|
}).extend({
|
|
5637
|
-
rules:
|
|
5638
|
-
findings:
|
|
5639
|
-
findingSchema.pick({ element: true, message: true }).extend({ rule:
|
|
6594
|
+
rules: z37.array(z37.string()).describe("The rules that failed."),
|
|
6595
|
+
findings: z37.array(
|
|
6596
|
+
findingSchema.pick({ element: true, message: true }).extend({ rule: z37.enum(RULES) })
|
|
5640
6597
|
).describe(
|
|
5641
6598
|
"Each finding of those rules: the element, and a message with the numbers in dp. The report also has the numbers by name."
|
|
5642
6599
|
)
|
|
5643
6600
|
});
|
|
5644
6601
|
var sweepCommand = defineCommand({
|
|
5645
6602
|
name: "sweep",
|
|
5646
|
-
summary: "Open each link in each orientation and
|
|
5647
|
-
input:
|
|
5648
|
-
url:
|
|
5649
|
-
|
|
6603
|
+
summary: "Open each link in each orientation, theme and direction, check each screen, and write a report, the screenshots and a contact sheet for each variant",
|
|
6604
|
+
input: z37.object({
|
|
6605
|
+
url: z37.array(
|
|
6606
|
+
z37.string().regex(
|
|
5650
6607
|
/^[A-Za-z][A-Za-z0-9+.-]*:\S+$/,
|
|
5651
6608
|
"A URL starts with a scheme, for example https: or exp:, and has no spaces."
|
|
5652
6609
|
)
|
|
5653
6610
|
).min(1).describe(
|
|
5654
6611
|
"A link to open and check: a deep link or a web page. Give it once for each screen."
|
|
5655
6612
|
),
|
|
5656
|
-
orientation:
|
|
6613
|
+
orientation: z37.string().regex(LIST, "The orientations are a comma list.").optional().describe(
|
|
5657
6614
|
`The orientations to check, as a comma list of ${ORIENTATIONS.join(", ")}. Left out: only the one that the device has, and loupe turns nothing.`
|
|
5658
6615
|
),
|
|
5659
|
-
theme:
|
|
6616
|
+
theme: z37.string().regex(LIST, "The themes are a comma list.").optional().describe(
|
|
5660
6617
|
`The themes to check, as a comma list of ${SWEEP_THEMES.join(", ")}. Left out: only the one that the device has, and loupe sets nothing.`
|
|
5661
6618
|
),
|
|
5662
|
-
rules:
|
|
6619
|
+
rules: z37.string().regex(LIST, "The rules are a comma list.").optional().describe(
|
|
5663
6620
|
`The rules to run on each screen, as a comma list. Each one by default: ${SWEEP_RULES.join(", ")}.`
|
|
5664
6621
|
),
|
|
5665
|
-
out:
|
|
6622
|
+
out: z37.string().min(1).default("loupe-sweep").describe(
|
|
5666
6623
|
"The folder for report.json, the screenshots (<variant>/<number>.png) and the contact sheets (<variant>.png). Files that are there are replaced."
|
|
5667
6624
|
),
|
|
5668
|
-
scroll:
|
|
6625
|
+
scroll: z37.boolean().optional().describe(
|
|
5669
6626
|
"Also scroll each screen down once, by 60 % of its largest vertical scroll view, and check it again: <variant>/<number>-scrolled.png and <variant>-scrolled.png. Then loupe scrolls back to the top."
|
|
5670
6627
|
),
|
|
6628
|
+
direction: z37.string().regex(LIST, "The directions are a comma list.").optional().describe(
|
|
6629
|
+
`The layout directions to check, as a comma list of ${SWEEP_DIRECTIONS.join(", ")}. Only for an app in Expo Go (app ${EXPO_GO2}): loupe sets each one in app.json as expo-rtl does, opens the app again, and puts app.json back at the end. Left out: only the direction that the app has.`
|
|
6630
|
+
),
|
|
6631
|
+
port: portField.describe(
|
|
6632
|
+
`The port of Metro on this machine (npx expo start), for direction. ${DEFAULT_PORT} by default.`
|
|
6633
|
+
),
|
|
6634
|
+
reloadEvery: z37.number().int().min(1).optional().describe(
|
|
6635
|
+
"Stop the app before each N-th link that the sweep opens, over all the variants, so the link starts it again: stacked screens slow an app down. In Expo Go, loupe then waits until the app shows the route of the link. Needs app. Left out: no restart."
|
|
6636
|
+
),
|
|
5671
6637
|
waitTimeout: timeoutField.describe(
|
|
5672
6638
|
`How long each screen can take to keep still after its link opens, in ms. ${DEFAULT_WAIT_TIMEOUT} by default.`
|
|
5673
6639
|
),
|
|
@@ -5676,26 +6642,26 @@ var sweepCommand = defineCommand({
|
|
|
5676
6642
|
),
|
|
5677
6643
|
device: deviceField
|
|
5678
6644
|
}),
|
|
5679
|
-
output:
|
|
5680
|
-
out:
|
|
5681
|
-
report:
|
|
6645
|
+
output: z37.object({
|
|
6646
|
+
out: z37.string().describe("The folder with each file of the sweep."),
|
|
6647
|
+
report: z37.string().describe(
|
|
5682
6648
|
"report.json: each screen with its number, link, variant, the result of each rule with its numbers, and its screenshot."
|
|
5683
6649
|
),
|
|
5684
|
-
passed:
|
|
5685
|
-
screens:
|
|
5686
|
-
failed:
|
|
5687
|
-
variants:
|
|
5688
|
-
failures:
|
|
6650
|
+
passed: z37.boolean().describe("True when every screen passed."),
|
|
6651
|
+
screens: z37.number().describe("Links \xD7 variants, and each scrolled screen."),
|
|
6652
|
+
failed: z37.number(),
|
|
6653
|
+
variants: z37.array(sweepVariantSchema),
|
|
6654
|
+
failures: z37.array(failureSchema).describe(
|
|
5689
6655
|
"The screens that failed, each with its findings or its error. The report also has the screens that passed, and the warnings of each rule."
|
|
5690
6656
|
),
|
|
5691
|
-
warnings:
|
|
6657
|
+
warnings: z37.array(z37.string())
|
|
5692
6658
|
}),
|
|
5693
6659
|
run: async (input, context) => {
|
|
5694
6660
|
const rules = input.rules === void 0 ? SWEEP_RULES : rulesOf(input.rules);
|
|
5695
6661
|
if (rules.includes("mirrored")) {
|
|
5696
6662
|
throw new LoupeError(
|
|
5697
6663
|
"invalid_input",
|
|
5698
|
-
"A sweep
|
|
6664
|
+
"A sweep checks each screen on its own, so it has no mirrored rule. Run check --mirror-of on a screen for that."
|
|
5699
6665
|
);
|
|
5700
6666
|
}
|
|
5701
6667
|
const orientations = listOf(
|
|
@@ -5704,43 +6670,88 @@ var sweepCommand = defineCommand({
|
|
|
5704
6670
|
"an orientation"
|
|
5705
6671
|
);
|
|
5706
6672
|
const themes = listOf(input.theme, SWEEP_THEMES, "a theme");
|
|
6673
|
+
if (input.reloadEvery !== void 0 && input.app === void 0) {
|
|
6674
|
+
throw new LoupeError(
|
|
6675
|
+
"invalid_input",
|
|
6676
|
+
"reloadEvery needs app: the package that loupe stops before each N-th link."
|
|
6677
|
+
);
|
|
6678
|
+
}
|
|
6679
|
+
const directions = listOf(
|
|
6680
|
+
input.direction,
|
|
6681
|
+
SWEEP_DIRECTIONS,
|
|
6682
|
+
"a direction"
|
|
6683
|
+
);
|
|
6684
|
+
const port = input.port ?? DEFAULT_PORT;
|
|
6685
|
+
if (directions) {
|
|
6686
|
+
if (input.app !== EXPO_GO2) {
|
|
6687
|
+
throw new LoupeError(
|
|
6688
|
+
"invalid_input",
|
|
6689
|
+
`direction needs the app in Expo Go: app ${EXPO_GO2}. loupe sets the direction in app.json, as expo-rtl does.`
|
|
6690
|
+
);
|
|
6691
|
+
}
|
|
6692
|
+
const { projectRoot, dynamicConfigPath } = await expoProject(
|
|
6693
|
+
context,
|
|
6694
|
+
port
|
|
6695
|
+
);
|
|
6696
|
+
await requireAppJson(projectRoot, "on", dynamicConfigPath);
|
|
6697
|
+
}
|
|
5707
6698
|
const target = await selectAndroidDevice(context, input.device);
|
|
5708
6699
|
requireAppOnDevice(target, input.app);
|
|
5709
6700
|
const report = await sweep(
|
|
5710
|
-
androidSweepDriver(
|
|
5711
|
-
|
|
5712
|
-
|
|
6701
|
+
androidSweepDriver(
|
|
6702
|
+
target,
|
|
6703
|
+
input.app,
|
|
6704
|
+
rules,
|
|
6705
|
+
{ waitTimeout: input.waitTimeout ?? DEFAULT_WAIT_TIMEOUT },
|
|
6706
|
+
directions ? { context, port } : void 0
|
|
6707
|
+
),
|
|
5713
6708
|
{
|
|
5714
6709
|
urls: input.url,
|
|
5715
6710
|
orientations,
|
|
5716
6711
|
themes,
|
|
5717
6712
|
out: input.out,
|
|
5718
|
-
scroll: input.scroll
|
|
6713
|
+
scroll: input.scroll,
|
|
6714
|
+
reloadEvery: input.reloadEvery,
|
|
6715
|
+
directions
|
|
5719
6716
|
},
|
|
5720
6717
|
context
|
|
5721
6718
|
);
|
|
5722
|
-
const failures = report.screens.filter((screen) => !screen.passed).map(
|
|
5723
|
-
|
|
5724
|
-
return {
|
|
6719
|
+
const failures = report.screens.filter((screen) => !screen.passed).map(
|
|
6720
|
+
({
|
|
5725
6721
|
number,
|
|
5726
6722
|
url,
|
|
5727
6723
|
variant,
|
|
5728
6724
|
scrolled,
|
|
6725
|
+
reloaded,
|
|
5729
6726
|
screenshot,
|
|
5730
|
-
|
|
5731
|
-
findings: failed.flatMap(
|
|
5732
|
-
({ rule, findings }) => findings.map(({ element, message }) => ({
|
|
5733
|
-
rule,
|
|
5734
|
-
element,
|
|
5735
|
-
message
|
|
5736
|
-
}))
|
|
5737
|
-
),
|
|
6727
|
+
check,
|
|
5738
6728
|
error
|
|
5739
|
-
}
|
|
5740
|
-
|
|
6729
|
+
}) => {
|
|
6730
|
+
const failed = (check?.results ?? []).filter(
|
|
6731
|
+
(result) => !result.passed
|
|
6732
|
+
);
|
|
6733
|
+
return {
|
|
6734
|
+
number,
|
|
6735
|
+
url,
|
|
6736
|
+
variant,
|
|
6737
|
+
scrolled,
|
|
6738
|
+
reloaded,
|
|
6739
|
+
screenshot,
|
|
6740
|
+
rules: failed.map((result) => result.rule),
|
|
6741
|
+
findings: failed.flatMap(
|
|
6742
|
+
({ rule, findings }) => findings.map(({ element, message }) => ({
|
|
6743
|
+
rule,
|
|
6744
|
+
element,
|
|
6745
|
+
message
|
|
6746
|
+
}))
|
|
6747
|
+
),
|
|
6748
|
+
error
|
|
6749
|
+
};
|
|
6750
|
+
}
|
|
6751
|
+
);
|
|
5741
6752
|
return {
|
|
5742
6753
|
out: report.out,
|
|
5743
|
-
report:
|
|
6754
|
+
report: path7.join(report.out, "report.json"),
|
|
5744
6755
|
passed: report.passed,
|
|
5745
6756
|
screens: report.screens.length,
|
|
5746
6757
|
failed: failures.length,
|
|
@@ -5759,8 +6770,17 @@ var sweepCommand = defineCommand({
|
|
|
5759
6770
|
(variant) => `${variant.name}: ${variant.failed === 0 ? "pass" : `${variant.failed} failed`}, contact sheet ${variant.sheet}${variant.scrolledSheet ? `, scrolled ${variant.scrolledSheet}` : ""}`
|
|
5760
6771
|
),
|
|
5761
6772
|
...failures.flatMap(
|
|
5762
|
-
({
|
|
5763
|
-
|
|
6773
|
+
({
|
|
6774
|
+
number,
|
|
6775
|
+
url,
|
|
6776
|
+
variant,
|
|
6777
|
+
scrolled,
|
|
6778
|
+
reloaded,
|
|
6779
|
+
rules,
|
|
6780
|
+
findings,
|
|
6781
|
+
error
|
|
6782
|
+
}) => {
|
|
6783
|
+
const where = ` ${number} ${variant}${scrolled ? " scrolled" : ""}${reloaded ? " after a restart" : ""} ${url}`;
|
|
5764
6784
|
if (error) return [`${where}: ${error.code}: ${error.message}`];
|
|
5765
6785
|
return [
|
|
5766
6786
|
`${where}: ${rules.join(", ")}`,
|
|
@@ -5774,11 +6794,11 @@ var sweepCommand = defineCommand({
|
|
|
5774
6794
|
});
|
|
5775
6795
|
|
|
5776
6796
|
// src/commands/swipe.ts
|
|
5777
|
-
import { z as
|
|
6797
|
+
import { z as z38 } from "zod";
|
|
5778
6798
|
var swipeCommand = defineCommand({
|
|
5779
6799
|
name: "swipe",
|
|
5780
6800
|
summary: "Move one touch in a straight line from one point to another",
|
|
5781
|
-
input:
|
|
6801
|
+
input: z38.object({
|
|
5782
6802
|
fromX: coordinateField("x"),
|
|
5783
6803
|
fromY: coordinateField("y"),
|
|
5784
6804
|
toX: coordinateField("x"),
|
|
@@ -5809,11 +6829,11 @@ var swipeCommand = defineCommand({
|
|
|
5809
6829
|
});
|
|
5810
6830
|
|
|
5811
6831
|
// src/commands/tap.ts
|
|
5812
|
-
import { z as
|
|
6832
|
+
import { z as z39 } from "zod";
|
|
5813
6833
|
var tapCommand = defineCommand({
|
|
5814
6834
|
name: "tap",
|
|
5815
6835
|
summary: "Tap one point of the screen, or the element with a text, label or id",
|
|
5816
|
-
input:
|
|
6836
|
+
input: z39.object({
|
|
5817
6837
|
x: coordinateField("x").optional(),
|
|
5818
6838
|
y: coordinateField("y").optional(),
|
|
5819
6839
|
...selectorFields,
|
|
@@ -5842,8 +6862,8 @@ var tapCommand = defineCommand({
|
|
|
5842
6862
|
});
|
|
5843
6863
|
|
|
5844
6864
|
// src/commands/theme.ts
|
|
5845
|
-
import { z as
|
|
5846
|
-
var settingSchema =
|
|
6865
|
+
import { z as z40 } from "zod";
|
|
6866
|
+
var settingSchema = z40.enum(THEME_SETTINGS).describe(
|
|
5847
6867
|
"light or dark; auto: Android picks one by the time of day; custom: by a schedule."
|
|
5848
6868
|
);
|
|
5849
6869
|
function describeSetting(setting) {
|
|
@@ -5859,9 +6879,9 @@ function describeSetting(setting) {
|
|
|
5859
6879
|
var themeCommand = defineCommand({
|
|
5860
6880
|
name: "theme",
|
|
5861
6881
|
summary: "Set the system theme to light or dark, and wait until the app shows it. With no theme, read it",
|
|
5862
|
-
input:
|
|
5863
|
-
theme:
|
|
5864
|
-
timeout:
|
|
6882
|
+
input: z40.object({
|
|
6883
|
+
theme: z40.enum(THEMES).optional().describe("light or dark. Left out: loupe only reads the setting."),
|
|
6884
|
+
timeout: z40.number().int().min(0).default(5e3).describe(
|
|
5865
6885
|
"Milliseconds to wait until the app's probe shows the theme. A screen with no probe has no wait."
|
|
5866
6886
|
),
|
|
5867
6887
|
...waitFields,
|
|
@@ -5869,14 +6889,14 @@ var themeCommand = defineCommand({
|
|
|
5869
6889
|
device: deviceField
|
|
5870
6890
|
}),
|
|
5871
6891
|
positionals: ["theme"],
|
|
5872
|
-
output:
|
|
6892
|
+
output: z40.object({
|
|
5873
6893
|
theme: settingSchema.describe("The system theme setting now."),
|
|
5874
6894
|
was: settingSchema.optional().describe("The setting before. Left out when loupe only read it."),
|
|
5875
|
-
source:
|
|
6895
|
+
source: z40.enum(["probe", "setting"]).optional().describe(
|
|
5876
6896
|
"What showed the theme: probe, the app's probe on the screen; setting, the system setting alone (no probe on the screen, or a probe that kept the other scheme)."
|
|
5877
6897
|
),
|
|
5878
|
-
ms:
|
|
5879
|
-
warnings:
|
|
6898
|
+
ms: z40.number().optional().describe("Milliseconds from the write until the source showed it."),
|
|
6899
|
+
warnings: z40.array(z40.string()),
|
|
5880
6900
|
waited: waitedSchema.optional()
|
|
5881
6901
|
}),
|
|
5882
6902
|
run: async ({ theme, timeout, app, device, ...wait }, context) => {
|
|
@@ -5900,12 +6920,12 @@ var themeCommand = defineCommand({
|
|
|
5900
6920
|
});
|
|
5901
6921
|
|
|
5902
6922
|
// src/commands/type.ts
|
|
5903
|
-
import { z as
|
|
6923
|
+
import { z as z41 } from "zod";
|
|
5904
6924
|
var typeCommand = defineCommand({
|
|
5905
6925
|
name: "type",
|
|
5906
6926
|
summary: "Type text into the field that has the focus",
|
|
5907
|
-
input:
|
|
5908
|
-
text:
|
|
6927
|
+
input: z41.object({
|
|
6928
|
+
text: z41.string().min(1).describe(
|
|
5909
6929
|
"The text to type. On Android, printable ASCII only; press Enter with the key command."
|
|
5910
6930
|
),
|
|
5911
6931
|
...waitFields,
|
|
@@ -5914,8 +6934,8 @@ var typeCommand = defineCommand({
|
|
|
5914
6934
|
}),
|
|
5915
6935
|
positionals: ["text"],
|
|
5916
6936
|
// The output has no text: it can be a password.
|
|
5917
|
-
output:
|
|
5918
|
-
characters:
|
|
6937
|
+
output: z41.object({
|
|
6938
|
+
characters: z41.number().int(),
|
|
5919
6939
|
waited: waitedSchema.optional()
|
|
5920
6940
|
}),
|
|
5921
6941
|
run: async ({ text, app, device, ...wait }, context) => {
|
|
@@ -5931,17 +6951,17 @@ var typeCommand = defineCommand({
|
|
|
5931
6951
|
});
|
|
5932
6952
|
|
|
5933
6953
|
// src/commands/version.ts
|
|
5934
|
-
import { z as
|
|
6954
|
+
import { z as z42 } from "zod";
|
|
5935
6955
|
var versionCommand = defineCommand({
|
|
5936
6956
|
name: "version",
|
|
5937
6957
|
summary: "Print the loupe version and the host it runs on",
|
|
5938
6958
|
readOnly: true,
|
|
5939
|
-
input:
|
|
5940
|
-
output:
|
|
5941
|
-
loupe:
|
|
5942
|
-
node:
|
|
5943
|
-
platform:
|
|
5944
|
-
arch:
|
|
6959
|
+
input: z42.object({}),
|
|
6960
|
+
output: z42.object({
|
|
6961
|
+
loupe: z42.string(),
|
|
6962
|
+
node: z42.string(),
|
|
6963
|
+
platform: z42.string(),
|
|
6964
|
+
arch: z42.string()
|
|
5945
6965
|
}),
|
|
5946
6966
|
run: () => ({
|
|
5947
6967
|
loupe: version,
|
|
@@ -5953,7 +6973,7 @@ var versionCommand = defineCommand({
|
|
|
5953
6973
|
});
|
|
5954
6974
|
|
|
5955
6975
|
// src/commands/wait.ts
|
|
5956
|
-
import { z as
|
|
6976
|
+
import { z as z43 } from "zod";
|
|
5957
6977
|
function sentence(text) {
|
|
5958
6978
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
5959
6979
|
}
|
|
@@ -5961,8 +6981,8 @@ var waitCommand = defineCommand({
|
|
|
5961
6981
|
name: "wait",
|
|
5962
6982
|
summary: "Wait until the screen keeps still, or until an element is on the screen",
|
|
5963
6983
|
readOnly: true,
|
|
5964
|
-
input:
|
|
5965
|
-
still:
|
|
6984
|
+
input: z43.object({
|
|
6985
|
+
still: z43.boolean().optional().describe(
|
|
5966
6986
|
"Wait until the screen keeps still: two equal screenshots in a row, with the system bars left out (the clock ticks there)."
|
|
5967
6987
|
),
|
|
5968
6988
|
text: selectorFields.text.describe(
|
|
@@ -5975,7 +6995,7 @@ var waitCommand = defineCommand({
|
|
|
5975
6995
|
"Wait until an element with this id is on the screen."
|
|
5976
6996
|
),
|
|
5977
6997
|
timeout: timeoutField,
|
|
5978
|
-
interval:
|
|
6998
|
+
interval: z43.number().int().min(0).max(1e4).optional().describe(
|
|
5979
6999
|
`The pause between two screenshots or two reads, in ms. ${DEFAULT_WAIT_INTERVAL} by default.`
|
|
5980
7000
|
),
|
|
5981
7001
|
app: appField,
|
|
@@ -6028,6 +7048,10 @@ var registry = createRegistry([
|
|
|
6028
7048
|
dismissCommand,
|
|
6029
7049
|
doubleTapCommand,
|
|
6030
7050
|
dragCommand,
|
|
7051
|
+
expoOpenCommand,
|
|
7052
|
+
expoReloadCommand,
|
|
7053
|
+
expoRtlCommand,
|
|
7054
|
+
expoWarmCommand,
|
|
6031
7055
|
foregroundCommand,
|
|
6032
7056
|
holdCommand,
|
|
6033
7057
|
insetsCommand,
|
|
@@ -6049,8 +7073,19 @@ var registry = createRegistry([
|
|
|
6049
7073
|
]);
|
|
6050
7074
|
|
|
6051
7075
|
// src/core/context.ts
|
|
7076
|
+
var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
7077
|
+
var localFetch = async (input, init) => {
|
|
7078
|
+
const url = new URL(input instanceof Request ? input.url : input);
|
|
7079
|
+
if (!LOOPBACK.has(url.hostname)) {
|
|
7080
|
+
throw new LoupeError(
|
|
7081
|
+
"internal",
|
|
7082
|
+
`loupe calls only servers on this machine, not ${url.host}.`
|
|
7083
|
+
);
|
|
7084
|
+
}
|
|
7085
|
+
return fetch(input, init);
|
|
7086
|
+
};
|
|
6052
7087
|
function createContext() {
|
|
6053
|
-
return { exec: nodeExec, env: process.env };
|
|
7088
|
+
return { exec: nodeExec, env: process.env, fetch: localFetch };
|
|
6054
7089
|
}
|
|
6055
7090
|
|
|
6056
7091
|
// src/core/run-command.ts
|