stim 1.1.0 → 1.3.0
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/README.md +37 -0
- package/dist/{android-CC5bUer7.mjs → android-BW8i_YxU.mjs} +1 -1
- package/dist/android-BqVIJoG7.mjs +1368 -0
- package/dist/{android-DnZlT3aU.mjs → android-CqcW1hrP.mjs} +205 -58
- package/dist/{android-cas-DGlTStWu.mjs → android-cas-BR5YJBYv.mjs} +6 -6
- package/dist/android-cas-compiler.mjs +1 -1
- package/dist/{app-install-oZIQRbdD.mjs → app-install-DIp9riNx.mjs} +29 -21
- package/dist/{build-slots-CgacA9zQ.mjs → build-slots-C3-R4XQr.mjs} +3 -3
- package/dist/{cache-manifest-oeH18ERr.mjs → cache-manifest-CXR-Y8pH.mjs} +1 -1
- package/dist/cache-manifest.mjs +1 -1
- package/dist/cli.mjs +13 -13
- package/dist/collector-run.d.mts +4 -1
- package/dist/collector-run.mjs +36 -11
- package/dist/{config-D7uu8Gbq.mjs → config-CcefMY2Q.mjs} +94 -13
- package/dist/{deps-64wVnpZc.mjs → deps-Spz8ozgo.mjs} +2 -2
- package/dist/{dev-client-Bvky1hya.mjs → dev-client-BjisHDB5.mjs} +250 -10
- package/dist/{device-DJKv5Qej.mjs → device-BkiW-gkk.mjs} +19 -11
- package/dist/{device-lease-D-G3SgVe.mjs → device-lease-BJYybF-2.mjs} +107 -83
- package/dist/{device-pool-BlHXnYYs.mjs → device-pool-CPbLGfrB.mjs} +19 -13
- package/dist/{device-remote-CCgkG82J.mjs → device-remote-AkYCKS8U.mjs} +8 -8
- package/dist/{doctor-DlVxTtMq.mjs → doctor-Bmv86UUW.mjs} +18 -26
- package/dist/{doctor-BRF9aAJ3.mjs → doctor-fAMXC4vl.mjs} +10 -10
- package/dist/{error-diagnostics-B5IJwv3-.mjs → error-diagnostics-DHC31rXA.mjs} +65 -55
- package/dist/{exec-bsN9MJXb.mjs → exec-CyylIdq9.mjs} +4 -2
- package/dist/{gc-DhXdgSdt.mjs → gc-GGu-8ULN.mjs} +90 -67
- package/dist/{guide-DrhrDBo5.mjs → guide-92CPA21s.mjs} +414 -47
- package/dist/{ios-CK1Vrk6Q.mjs → ios-BSXFeO5H.mjs} +200 -59
- package/dist/{ios-BZxKPuqP.mjs → ios-Deh5js5V.mjs} +147 -40
- package/dist/{ios-device-CdSm0GDw.mjs → ios-device-CWOM_S44.mjs} +2 -2
- package/dist/{ios-device-CYbuRNXR.mjs → ios-device-D3pzTKQE.mjs} +1 -1
- package/dist/{logs-Dxoy16Qv.mjs → logs-DPNF4C9s.mjs} +9 -6
- package/dist/{logs-query-oqn47Ffx.mjs → logs-query-R-Cqc6Qv.mjs} +22 -5
- package/dist/{metro-B01H3EuD.mjs → metro-CORqXyTL.mjs} +3 -3
- package/dist/{ndjson-DcAtEx_K.mjs → ndjson-BZwI1NBv.mjs} +5 -2
- package/dist/{ownership-D8HmSv2E.mjs → ownership-8O073GIC.mjs} +3 -3
- package/dist/{ownership-B9QIdQOw.mjs → ownership-BpCKiRlQ.mjs} +4 -4
- package/dist/{ownership-claim-CeJLEpjD.mjs → ownership-claim-Bf2CAfw3.mjs} +4 -3
- package/dist/{project-COj6nzzh.mjs → project-fKmuIaMI.mjs} +2 -2
- package/dist/{reclaim-BPvN2HlP.mjs → reclaim-iW9Cad7k.mjs} +80 -73
- package/dist/{reload-DYZEBbZy.mjs → reload-DazHDSFA.mjs} +32 -24
- package/dist/{server-bare-BYHqEeyw.mjs → server-bare-DEzPZLvf.mjs} +7 -2
- package/dist/server-expo-44em5Pmg.mjs +2 -0
- package/dist/{server-expo-BEMr_m6p.mjs → server-expo-DizT4OMk.mjs} +5 -5
- package/dist/{settings-BSwrY4FZ.mjs → settings-DEJf6_kJ.mjs} +26 -5
- package/dist/slot-launch-cci0xvmC.mjs +19 -0
- package/dist/{start-ByCylYtB.mjs → start-mObjQH2W.mjs} +12 -12
- package/dist/{state-IYEY-zi8.mjs → state-B3XA2wp2.mjs} +9 -9
- package/dist/{stats-wqxPm7Tv.mjs → stats-BR-kwj0B.mjs} +1 -1
- package/dist/{stats-DZ4Q5J-7.mjs → stats-CaaQr4yN.mjs} +3 -3
- package/dist/{status-Dia0XTqG.mjs → status-BxQNqu9t.mjs} +86 -25
- package/dist/{stop-D6o5zAdm.mjs → stop-CrHGcjrV.mjs} +2 -2
- package/dist/{stop-BApyaF21.mjs → stop-DimGXEKY.mjs} +93 -42
- package/dist/supervisor-run.d.mts +1 -2
- package/dist/supervisor-run.mjs +5 -5
- package/dist/{remote-cache-DOi5-zLj.mjs → teardown-ClFp1Aax.mjs} +889 -830
- package/dist/{workspace-process-lock-CxOO9-pf.mjs → workspace-process-lock-3NcQnZ0X.mjs} +1 -1
- package/dist/{worktree-DxEmUI_n.mjs → worktree-DxTgN1CJ.mjs} +16 -16
- package/dist/{worktree-Dx3ZC5lS.mjs → worktree-Eq6TLH8N.mjs} +7 -3
- package/dist/{xcode-CDB6fytw.mjs → xcode-D7sAp-Zy.mjs} +256 -103
- package/package.json +5 -5
- package/shim/bundle-response.cjs +5 -0
- package/dist/android-xmyGBNy5.mjs +0 -665
- package/dist/build-lock-vE45ZzJZ.mjs +0 -645
- package/dist/server-expo-rb0k-0w7.mjs +0 -2
|
@@ -1,934 +1,993 @@
|
|
|
1
|
-
import { t as getExecutor } from "./exec-
|
|
2
|
-
import { C as withConfigLock, g as loadConfig, s as ensureConfig, y as saveConfig } from "./config-
|
|
3
|
-
import { r as createNdjsonWriter } from "./ndjson-
|
|
4
|
-
import { D as workspaceLogsDir } from "./state-
|
|
5
|
-
import { l as resolvePackageJson } from "./project-
|
|
1
|
+
import { t as getExecutor } from "./exec-CyylIdq9.mjs";
|
|
2
|
+
import { B as removeSlotDevice, C as withConfigLock, F as assignSlotDevice, L as deviceSlotPlatforms, g as loadConfig, s as ensureConfig, y as saveConfig, z as projectDeviceSlots } from "./config-CcefMY2Q.mjs";
|
|
3
|
+
import { r as createNdjsonWriter } from "./ndjson-BZwI1NBv.mjs";
|
|
4
|
+
import { D as workspaceLogsDir } from "./state-B3XA2wp2.mjs";
|
|
5
|
+
import { l as resolvePackageJson } from "./project-fKmuIaMI.mjs";
|
|
6
6
|
import { n as stripAnsi } from "./process-output-C7IlIzd7.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { E as ownedAvdMatchesConfiguration, F as shutdownAndroidEmulator, I as waitForAndroidEmulatorShutdown, N as resolveOwnedAvdSerial, O as ownedAvdSystemImage, S as listOrphanedAvdDirectories, T as ownedAvdDirectory, l as avdStorageRoots, o as assertOwnedAvdStopped, p as deleteAvd, s as avdPathExists } from "./android-BqVIJoG7.mjs";
|
|
8
|
+
import { n as expoBinFromPackage, r as expoBinPath, s as findBinUpward } from "./server-expo-DizT4OMk.mjs";
|
|
9
|
+
import { C as shutdownIosSim, _ as renameIosSim, a as deleteIosSim, d as listIosDeviceTypes, g as parseRuntimeVersion, h as parkedSimName, o as deleteParkedIosSim, r as clearAppDataContainer, s as findAppDataContainer, x as resolveOwnedIosSim } from "./ios-Deh5js5V.mjs";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
+
import { existsSync, lstatSync, readFileSync, renameSync, rmSync } from "node:fs";
|
|
12
12
|
import { randomUUID } from "node:crypto";
|
|
13
|
-
import { join } from "node:path";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
15
|
import { format } from "node:util";
|
|
16
16
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
17
|
+
//#region src/engine/remote-cache.ts
|
|
18
|
+
const EAS_PROVIDER_PACKAGE = "eas-build-cache-provider";
|
|
19
|
+
const RESOLVE_TIMEOUT_MS = 3e4;
|
|
20
|
+
const UPLOAD_TIMEOUT_MS = 6e4;
|
|
21
|
+
const CONFIG_TIMEOUT_MS = 3e4;
|
|
22
|
+
const DYNAMIC_CONFIG_FILES = [
|
|
23
|
+
"app.config.ts",
|
|
24
|
+
"app.config.js",
|
|
25
|
+
"app.config.mjs",
|
|
26
|
+
"app.config.cjs"
|
|
27
|
+
];
|
|
28
|
+
const TIMED_OUT = Symbol("timed-out");
|
|
29
|
+
function dynamicConfigFile(root) {
|
|
30
|
+
for (const name of DYNAMIC_CONFIG_FILES) if (existsSync(join(root, name))) return name;
|
|
31
|
+
return null;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
if (!explicit && pool !== void 0 && (pool === null || typeof pool !== "object" || Array.isArray(pool))) return {
|
|
39
|
-
max: 0,
|
|
40
|
-
error: "Invalid pool value. Expected an object with simulator and emulator bounds."
|
|
41
|
-
};
|
|
42
|
-
const fromConfig = pool !== null && typeof pool === "object" && !Array.isArray(pool) ? pool[key] : void 0;
|
|
43
|
-
const raw = explicit ? fromEnv : fromConfig;
|
|
44
|
-
if (raw === void 0) return {
|
|
45
|
-
max: env.STIM_HOME ? 0 : 3,
|
|
46
|
-
error: null
|
|
47
|
-
};
|
|
48
|
-
const parsed = parseMax(raw, explicit);
|
|
49
|
-
if (parsed === null) return {
|
|
50
|
-
max: 0,
|
|
51
|
-
error: `Invalid ${explicit ? envKey : `pool.${key}`} value ${JSON.stringify(raw)}. Expected a whole number of parked ${platform === "ios" ? "simulators" : "emulators"}, 0 or more.`
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
max: explicit ? parsed : env.STIM_HOME ? 0 : parsed,
|
|
55
|
-
error: null
|
|
56
|
-
};
|
|
33
|
+
function providerFromConfig(config) {
|
|
34
|
+
if (!config || typeof config !== "object") return null;
|
|
35
|
+
const expoField = config.expo;
|
|
36
|
+
const exp = expoField && typeof expoField === "object" ? expoField : config;
|
|
37
|
+
return exp.buildCacheProvider ?? exp.experiments?.buildCacheProvider ?? null;
|
|
57
38
|
}
|
|
58
|
-
function
|
|
59
|
-
if (
|
|
60
|
-
const
|
|
61
|
-
|
|
39
|
+
function ownerFromConfig(config) {
|
|
40
|
+
if (!config || typeof config !== "object") return null;
|
|
41
|
+
const expoField = config.expo;
|
|
42
|
+
const owner = (expoField && typeof expoField === "object" ? expoField : config).owner;
|
|
43
|
+
return typeof owner === "string" && owner.trim() !== "" ? owner.trim() : null;
|
|
62
44
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
ios: read("ios"),
|
|
72
|
-
android: read("android")
|
|
45
|
+
function normalizeProvider(raw) {
|
|
46
|
+
if (raw === null || raw === void 0 || raw === "") return null;
|
|
47
|
+
if (raw === "eas") return {
|
|
48
|
+
name: "eas",
|
|
49
|
+
reference: EAS_PROVIDER_PACKAGE,
|
|
50
|
+
options: {}
|
|
73
51
|
};
|
|
52
|
+
if (typeof raw === "object") {
|
|
53
|
+
const obj = raw;
|
|
54
|
+
if (typeof obj.plugin === "string" && obj.plugin.trim() !== "") {
|
|
55
|
+
const reference = obj.plugin.trim();
|
|
56
|
+
return {
|
|
57
|
+
name: reference,
|
|
58
|
+
reference,
|
|
59
|
+
options: obj.options && typeof obj.options === "object" ? obj.options : {}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { invalid: typeof raw === "string" ? `"${raw}"` : JSON.stringify(raw) };
|
|
74
64
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
function writeParked(config, platform, records) {
|
|
79
|
-
config.parked = {
|
|
80
|
-
...poolBlock(config),
|
|
81
|
-
[platform]: records
|
|
82
|
-
};
|
|
65
|
+
function runOptionsFor(platform) {
|
|
66
|
+
return platform === "android" ? { variant: "debug" } : { configuration: "Debug" };
|
|
83
67
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
68
|
+
function isProviderPlugin(plugin) {
|
|
69
|
+
if (!plugin || typeof plugin !== "object") return false;
|
|
70
|
+
const p = plugin;
|
|
71
|
+
const resolves = typeof p.resolveBuildCache === "function" || typeof p.resolveRemoteBuildCache === "function";
|
|
72
|
+
const uploads = typeof p.uploadBuildCache === "function" || typeof p.uploadRemoteBuildCache === "function";
|
|
73
|
+
return resolves && uploads;
|
|
86
74
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
75
|
+
function cacheLevel(value) {
|
|
76
|
+
return value === "local" || value === "remote" ? value : false;
|
|
89
77
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const evicted = ordered.slice(0, ordered.length - max);
|
|
97
|
-
const dropped = new Set(evicted.map((r) => r.udid));
|
|
98
|
-
return {
|
|
99
|
-
keep: records.filter((r) => !dropped.has(r.udid)),
|
|
100
|
-
evicted
|
|
101
|
-
};
|
|
78
|
+
function exitAfterFlush(code = 0, { exit = (c) => process.exit(c), stream = process.stdout } = {}) {
|
|
79
|
+
try {
|
|
80
|
+
stream.write("", () => exit(code));
|
|
81
|
+
} catch {
|
|
82
|
+
exit(code);
|
|
83
|
+
}
|
|
102
84
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
85
|
+
function readProjectConfig(root, { run = null, timeoutMs = CONFIG_TIMEOUT_MS } = {}) {
|
|
86
|
+
const dynamic = dynamicConfigFile(root);
|
|
87
|
+
if (!dynamic) {
|
|
88
|
+
const file = join(root, "app.json");
|
|
89
|
+
if (!existsSync(file)) return {
|
|
90
|
+
config: null,
|
|
91
|
+
source: null
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
return {
|
|
95
|
+
config: JSON.parse(readFileSync(file, "utf-8")),
|
|
96
|
+
source: "app.json"
|
|
97
|
+
};
|
|
98
|
+
} catch (err) {
|
|
99
|
+
return { unavailable: `app.json could not be parsed: ${firstLine(err)}` };
|
|
109
100
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
101
|
+
}
|
|
102
|
+
const bin = expoBinPath(root);
|
|
103
|
+
if (!bin) return { unavailable: `${dynamic} is code, so it has to be evaluated to read its buildCacheProvider, and the \`expo\` package is not resolvable from this project (no expo/package.json to read a bin from, and no node_modules/.bin/expo here or in any parent)` };
|
|
104
|
+
const exec = run || ((file, args, opts) => getExecutor().runFile(file, args, opts));
|
|
105
|
+
let stdout;
|
|
106
|
+
try {
|
|
107
|
+
stdout = exec(bin, [
|
|
108
|
+
"config",
|
|
109
|
+
"--json",
|
|
110
|
+
root
|
|
111
|
+
], { timeoutMs });
|
|
112
|
+
} catch (err) {
|
|
113
|
+
return { unavailable: `\`expo config --json\` failed: ${firstLine(err)}` };
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
return {
|
|
117
|
+
config: JSON.parse(String(stdout)),
|
|
118
|
+
source: dynamic
|
|
119
|
+
};
|
|
120
|
+
} catch (err) {
|
|
121
|
+
return { unavailable: `\`expo config --json\` did not print JSON: ${firstLine(err)}` };
|
|
122
|
+
}
|
|
133
123
|
}
|
|
134
|
-
function
|
|
124
|
+
async function loadPlugin(projectRoot, reference, { requireFrom = null } = {}) {
|
|
125
|
+
const localRequire = requireFrom ? requireFrom(projectRoot) : createRequire(join(projectRoot, "package.json"));
|
|
126
|
+
const file = localRequire.resolve(reference);
|
|
127
|
+
let mod;
|
|
135
128
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
mod = localRequire(file);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
if (err?.code !== "ERR_REQUIRE_ESM") throw err;
|
|
132
|
+
mod = await import(pathToFileURL(file).href);
|
|
140
133
|
}
|
|
134
|
+
const plugin = mod?.default ?? mod;
|
|
135
|
+
if (!isProviderPlugin(plugin)) throw new Error(`"${reference}" does not export resolveBuildCache and uploadBuildCache functions`);
|
|
136
|
+
return plugin;
|
|
141
137
|
}
|
|
142
|
-
function
|
|
143
|
-
if (
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
async function loadProjectProvider(projectRoot, { isExpo = true, run = null, requireFrom = null, timeoutMs = CONFIG_TIMEOUT_MS } = {}) {
|
|
139
|
+
if (!isExpo) return { none: true };
|
|
140
|
+
const read = readProjectConfig(projectRoot, {
|
|
141
|
+
run,
|
|
142
|
+
timeoutMs
|
|
143
|
+
});
|
|
144
|
+
if (read.unavailable) return { unavailable: read.unavailable };
|
|
145
|
+
const normalized = normalizeProvider(providerFromConfig(read.config));
|
|
146
|
+
if (!normalized) return { none: true };
|
|
147
|
+
if (normalized.invalid) return { unavailable: `buildCacheProvider is ${normalized.invalid}, which is not "eas" or { plugin: <module> }` };
|
|
148
|
+
if (normalized.reference === "@stim-cli/expo-build-cache") return { none: true };
|
|
149
|
+
let plugin;
|
|
150
|
+
try {
|
|
151
|
+
plugin = await loadPlugin(projectRoot, normalized.reference, { requireFrom });
|
|
152
|
+
} catch (err) {
|
|
153
|
+
const missing = err?.code === "MODULE_NOT_FOUND";
|
|
154
|
+
return { unavailable: normalized.name === "eas" && missing ? `the EAS build cache needs the \`${EAS_PROVIDER_PACKAGE}\` package, which is not installed in this project` : `${normalized.name} could not be loaded: ${firstLine(err)}` };
|
|
155
|
+
}
|
|
147
156
|
return {
|
|
148
|
-
|
|
149
|
-
|
|
157
|
+
provider: {
|
|
158
|
+
plugin,
|
|
159
|
+
options: normalized.options ?? {}
|
|
160
|
+
},
|
|
161
|
+
name: normalized.name,
|
|
162
|
+
owner: ownerFromConfig(read.config)
|
|
150
163
|
};
|
|
151
164
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
saveConfig(cfg);
|
|
171
|
-
const claimed = { ...record };
|
|
172
|
-
delete claimed.deletionClaim;
|
|
173
|
-
return {
|
|
174
|
-
record: claimed,
|
|
175
|
-
token
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function clearParkedRemovalClaim(platform, udid, token) {
|
|
180
|
-
withConfigLock(() => {
|
|
181
|
-
const cfg = loadConfig();
|
|
182
|
-
if (!cfg) return;
|
|
183
|
-
const records = readParked(platform, { config: cfg });
|
|
184
|
-
const record = records.find((candidate) => candidate.udid === udid);
|
|
185
|
-
if (!record || parseDeletionClaim(record.deletionClaim)?.token !== token) return;
|
|
186
|
-
const restored = { ...record };
|
|
187
|
-
delete restored.deletionClaim;
|
|
188
|
-
writeParked(cfg, platform, records.map((candidate) => candidate.udid === udid ? restored : candidate));
|
|
189
|
-
saveConfig(cfg);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function removeParkedAfter(platform, udid, beforeRemove) {
|
|
193
|
-
const claim = claimParkedRemoval(platform, udid);
|
|
194
|
-
if (!claim) return null;
|
|
195
|
-
try {
|
|
196
|
-
beforeRemove(claim.record);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
try {
|
|
199
|
-
clearParkedRemovalClaim(platform, udid, claim.token);
|
|
200
|
-
} catch {}
|
|
201
|
-
throw error;
|
|
165
|
+
const WHOAMI_TIMEOUT_MS = 15e3;
|
|
166
|
+
const EAS_CLI_PACKAGE = "eas-cli";
|
|
167
|
+
const EAS_CLI_BIN = "eas";
|
|
168
|
+
function parseWhoami({ stdout = "", stderr = "", exitCode = 0 } = {}) {
|
|
169
|
+
const out = stripAnsi(stdout);
|
|
170
|
+
const combined = `${out}\n${stripAnsi(stderr)}`;
|
|
171
|
+
if (/^\s*Not logged in\s*$/m.test(combined)) return { loggedOut: true };
|
|
172
|
+
if (exitCode !== 0) return { unknown: firstLine(combined.trim() || `eas whoami exited ${exitCode}`) };
|
|
173
|
+
const lines = out.split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
174
|
+
if (lines.length === 0) return { unknown: "eas whoami printed nothing" };
|
|
175
|
+
const raw = lines[0];
|
|
176
|
+
if (raw === void 0) return { unknown: "eas whoami printed nothing" };
|
|
177
|
+
const viaToken = /\(authenticated using EXPO_TOKEN\)\s*$/.test(raw);
|
|
178
|
+
const display = raw.replace(/\s*\(authenticated using EXPO_TOKEN\)\s*$/, "").trim();
|
|
179
|
+
const accounts = [];
|
|
180
|
+
for (const line of lines) {
|
|
181
|
+
const name = /^\u2022\s*(\S+)\s*\(Role:/.exec(line)?.[1];
|
|
182
|
+
if (name !== void 0) accounts.push(name);
|
|
202
183
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return claim.record;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
function dropParked(platform, udid) {
|
|
214
|
-
return removeParkedAfter(platform, udid, () => {}) !== null;
|
|
184
|
+
if (accounts.length === 0 && !display.endsWith("(robot)") && display !== "robot") accounts.push(display);
|
|
185
|
+
return {
|
|
186
|
+
loggedIn: true,
|
|
187
|
+
account: display,
|
|
188
|
+
accounts: accounts.length ? accounts : null,
|
|
189
|
+
viaToken
|
|
190
|
+
};
|
|
215
191
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return removeParkedAfter("android", avdName, () => {
|
|
221
|
-
const result = teardownOwnedAvd(avdName, { del: true });
|
|
222
|
-
if (result.status !== "torn-down" && result.status !== "missing") throw new Error(result.reason);
|
|
223
|
-
}) ? {
|
|
224
|
-
status: "torn-down",
|
|
225
|
-
label: avdName
|
|
226
|
-
} : {
|
|
227
|
-
status: "skipped",
|
|
228
|
-
kind: "not-parked",
|
|
229
|
-
reason: "emulator is no longer parked"
|
|
230
|
-
};
|
|
231
|
-
} catch (error) {
|
|
232
|
-
return {
|
|
233
|
-
status: "failed",
|
|
234
|
-
reason: String(error?.message || error)
|
|
235
|
-
};
|
|
236
|
-
}
|
|
192
|
+
function isEasAuthFailureText(text) {
|
|
193
|
+
const t = stripAnsi(text || "");
|
|
194
|
+
if (t.trim() === "") return false;
|
|
195
|
+
return /not logged in/i.test(t) || /\beas login\b/i.test(t) || /EXPO_TOKEN/.test(t) || /unauthorized/i.test(t) || /not authorized/i.test(t) || /authentication (failed|required)/i.test(t);
|
|
237
196
|
}
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
reason: "simulator is no longer parked"
|
|
245
|
-
};
|
|
246
|
-
return {
|
|
247
|
-
status: "torn-down",
|
|
248
|
-
label: label ?? removed.name
|
|
249
|
-
};
|
|
250
|
-
} catch (error) {
|
|
251
|
-
return {
|
|
252
|
-
status: "failed",
|
|
253
|
-
reason: String(error?.message || error)
|
|
254
|
-
};
|
|
255
|
-
}
|
|
197
|
+
function easAuthNote(status) {
|
|
198
|
+
const { code, account, owner, reason, phase = "resolve" } = status || {};
|
|
199
|
+
const because = reason ? ` (${reason})` : "";
|
|
200
|
+
if (code === "logged-out") return `eas is not authenticated${because} -- run \`eas login\` (or set EXPO_TOKEN); ` + (phase === "upload" ? "this build stayed in the local cache" : "building with the local cache only");
|
|
201
|
+
if (code === "wrong-account") return `eas is authenticated as ${account}, and this project's owner is ${owner} -- run \`eas login\` as a member of ${owner} (or set EXPO_TOKEN); consulting the EAS cache anyway`;
|
|
202
|
+
return null;
|
|
256
203
|
}
|
|
257
|
-
function
|
|
258
|
-
const
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (sim.state !== "Shutdown") throw new Error(`simulator ${udid} is still ${sim.state} after shutdown`);
|
|
263
|
-
const model = listIosDeviceTypes().find((d) => d.identifier === sim.deviceTypeIdentifier)?.name ?? null;
|
|
264
|
-
const runtime = parseRuntimeVersion(sim.runtime);
|
|
265
|
-
if (park.bundleId) {
|
|
266
|
-
if (!sim.dataPath) throw new Error(`simulator ${udid} did not report a data path for app cleanup`);
|
|
267
|
-
const container = findAppDataContainer(sim.dataPath, park.bundleId);
|
|
268
|
-
if (container) clearAppDataContainer(container);
|
|
269
|
-
}
|
|
270
|
-
const name = parkedSimName(sim.udid, {
|
|
271
|
-
model,
|
|
272
|
-
runtime
|
|
273
|
-
});
|
|
274
|
-
renameIosSim(sim.udid, name);
|
|
275
|
-
const record = {
|
|
276
|
-
udid: sim.udid,
|
|
277
|
-
name,
|
|
278
|
-
deviceTypeIdentifier: sim.deviceTypeIdentifier,
|
|
279
|
-
runtimeIdentifier: sim.runtime,
|
|
280
|
-
parkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
281
|
-
simslimManaged: Boolean(park.simslimManaged),
|
|
282
|
-
...park.bundleId ? { bundleId: park.bundleId } : {},
|
|
283
|
-
...park.cacheKey ? { cacheKey: park.cacheKey } : {}
|
|
204
|
+
function resolveEasCliBin(projectRoot, { lookupPath = null, timeoutMs = 5e3 } = {}) {
|
|
205
|
+
const fromPackage = expoBinFromPackage(resolvePackageJson(projectRoot, EAS_CLI_PACKAGE), EAS_CLI_BIN);
|
|
206
|
+
if (fromPackage) return {
|
|
207
|
+
file: fromPackage,
|
|
208
|
+
source: "project"
|
|
284
209
|
};
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
projectPath: park.projectPath,
|
|
290
|
-
record,
|
|
291
|
-
max: park.max
|
|
292
|
-
})
|
|
210
|
+
const shim = findBinUpward(projectRoot, EAS_CLI_BIN);
|
|
211
|
+
if (shim) return {
|
|
212
|
+
file: shim,
|
|
213
|
+
source: "project"
|
|
293
214
|
};
|
|
215
|
+
const onPath = lookupPath ? lookupPath() : getExecutor().runQuiet(`command -v ${EAS_CLI_BIN}`, { timeoutMs });
|
|
216
|
+
const file = (String(onPath || "").split("\n")[0] ?? "").trim();
|
|
217
|
+
return file ? {
|
|
218
|
+
file,
|
|
219
|
+
source: "path"
|
|
220
|
+
} : null;
|
|
294
221
|
}
|
|
295
|
-
|
|
296
|
-
|
|
222
|
+
const easAuthCache = /* @__PURE__ */ new Map();
|
|
223
|
+
function checkEasAuth({ projectRoot, owner = null, run = null, resolveBin = null, timeoutMs = WHOAMI_TIMEOUT_MS, cache = easAuthCache }) {
|
|
224
|
+
const key = `${projectRoot}::${owner || ""}`;
|
|
225
|
+
if (cache?.has(key)) return cache.get(key);
|
|
226
|
+
const answer = probeEasAuth({
|
|
227
|
+
projectRoot,
|
|
228
|
+
owner,
|
|
229
|
+
run,
|
|
230
|
+
resolveBin,
|
|
231
|
+
timeoutMs
|
|
232
|
+
});
|
|
233
|
+
cache?.set(key, answer);
|
|
234
|
+
return answer;
|
|
235
|
+
}
|
|
236
|
+
function probeEasAuth({ projectRoot, owner, run, resolveBin, timeoutMs }) {
|
|
237
|
+
const bin = (resolveBin || resolveEasCliBin)(projectRoot);
|
|
238
|
+
if (!bin) return {
|
|
239
|
+
failed: true,
|
|
240
|
+
code: "no-cli",
|
|
241
|
+
reason: "no `eas` executable is resolvable from this project or on PATH",
|
|
242
|
+
remedy: "Install eas-cli (`npm i -g eas-cli`, or as a project devDependency), then run `eas login`."
|
|
243
|
+
};
|
|
244
|
+
const exec = run || ((file, args, opts) => getExecutor().runFile(file, args, opts));
|
|
245
|
+
let result;
|
|
297
246
|
try {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
kind: "not-owned",
|
|
302
|
-
reason: `sim is now named "${resolved.notOwned}", not Stim-owned by name`
|
|
303
|
-
};
|
|
304
|
-
if (resolved.missing) return { status: "missing" };
|
|
305
|
-
shutdownIosSim(udid);
|
|
306
|
-
const sim = resolved.sim;
|
|
307
|
-
if (del && park && park.max > 0) try {
|
|
308
|
-
const { record, evicted } = parkOwnedIosSim(udid, park);
|
|
309
|
-
const removed = [];
|
|
310
|
-
const failures = [];
|
|
311
|
-
for (const entry of evicted) {
|
|
312
|
-
const result = teardownParkedIosSim(entry.udid, { label: entry.name });
|
|
313
|
-
if (result.status === "torn-down") removed.push({
|
|
314
|
-
udid: entry.udid,
|
|
315
|
-
name: entry.name
|
|
316
|
-
});
|
|
317
|
-
else if (result.status === "failed") failures.push(`could not delete evicted ${entry.name} (${entry.udid}): ${result.reason}`);
|
|
318
|
-
}
|
|
319
|
-
return {
|
|
320
|
-
status: "torn-down",
|
|
321
|
-
label: label ?? sim.name ?? udid,
|
|
322
|
-
parked: {
|
|
323
|
-
udid: record.udid,
|
|
324
|
-
name: record.name
|
|
325
|
-
},
|
|
326
|
-
evicted: removed,
|
|
327
|
-
...failures.length ? { evictionFailures: failures } : {}
|
|
328
|
-
};
|
|
329
|
-
} catch (e) {
|
|
330
|
-
parkFallback = String(e?.message || e);
|
|
331
|
-
}
|
|
332
|
-
if (del) deleteIosSim(udid);
|
|
333
|
-
return {
|
|
334
|
-
status: "torn-down",
|
|
335
|
-
label: label ?? sim.name ?? udid,
|
|
336
|
-
...parkFallback ? { parkFallback } : {}
|
|
247
|
+
result = {
|
|
248
|
+
stdout: String(exec(bin.file, ["whoami"], { timeoutMs }) ?? ""),
|
|
249
|
+
exitCode: 0
|
|
337
250
|
};
|
|
338
251
|
} catch (e) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
252
|
+
const err = e;
|
|
253
|
+
if (err?.code === "ETIMEDOUT" || err?.signal === "SIGTERM" || err?.killed) return { unknown: `eas whoami timed out after ${timeoutMs}ms` };
|
|
254
|
+
result = {
|
|
255
|
+
stdout: String(err?.stdout ?? ""),
|
|
256
|
+
stderr: String(err?.stderr ?? err?.message ?? ""),
|
|
257
|
+
exitCode: typeof err?.status === "number" ? err.status : 1
|
|
343
258
|
};
|
|
344
259
|
}
|
|
260
|
+
const parsed = parseWhoami(result);
|
|
261
|
+
if (parsed.loggedOut) return {
|
|
262
|
+
failed: true,
|
|
263
|
+
code: "logged-out",
|
|
264
|
+
reason: "eas whoami says \"Not logged in\"",
|
|
265
|
+
remedy: "Run `eas login` (or set EXPO_TOKEN)."
|
|
266
|
+
};
|
|
267
|
+
if (parsed.unknown) return { unknown: parsed.unknown };
|
|
268
|
+
if (owner && Array.isArray(parsed.accounts) && !parsed.accounts.includes(owner)) return {
|
|
269
|
+
failed: true,
|
|
270
|
+
code: "wrong-account",
|
|
271
|
+
account: parsed.account,
|
|
272
|
+
accounts: parsed.accounts,
|
|
273
|
+
owner,
|
|
274
|
+
reason: `eas is authenticated as ${parsed.account} (accounts: ${parsed.accounts.join(", ")}), which does not include this project's owner ${owner}`,
|
|
275
|
+
remedy: `Run \`eas login\` as a member of ${owner}, or set EXPO_TOKEN to a token for it.`
|
|
276
|
+
};
|
|
277
|
+
return {
|
|
278
|
+
ok: true,
|
|
279
|
+
account: parsed.account,
|
|
280
|
+
accounts: parsed.accounts,
|
|
281
|
+
viaToken: parsed.viaToken,
|
|
282
|
+
source: bin.source
|
|
283
|
+
};
|
|
345
284
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (del) {
|
|
360
|
-
const current = resolveAvd(avdName);
|
|
361
|
-
if (current.notOwned) return {
|
|
362
|
-
status: "skipped",
|
|
363
|
-
kind: "not-owned",
|
|
364
|
-
reason: `AVD ${avdName} is not Stim-owned by name`
|
|
365
|
-
};
|
|
366
|
-
if (current.missing) return { status: "missing" };
|
|
367
|
-
if (current.serial) throw new Error(`Owned AVD ${avdName} started again before deletion.`);
|
|
368
|
-
assertStopped(avdName);
|
|
369
|
-
if (park && park.max > 0) try {
|
|
370
|
-
const systemImage = ownedAvdSystemImage(avdName);
|
|
371
|
-
if (!systemImage || !park.configuration || !ownedAvdMatchesConfiguration(avdName, park.configuration)) throw new Error("the AVD has no verified creation configuration");
|
|
372
|
-
const evicted = parkSim({
|
|
373
|
-
platform: "android",
|
|
374
|
-
projectPath: park.projectPath,
|
|
375
|
-
max: park.max,
|
|
376
|
-
record: {
|
|
377
|
-
udid: avdName,
|
|
378
|
-
name: avdName,
|
|
379
|
-
systemImage,
|
|
380
|
-
configuration: park.configuration,
|
|
381
|
-
parkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
const removed = [];
|
|
385
|
-
const failures = [];
|
|
386
|
-
for (const entry of evicted) {
|
|
387
|
-
const result = teardownParkedAvd(entry.name);
|
|
388
|
-
if (result.status === "torn-down") removed.push({
|
|
389
|
-
udid: entry.name,
|
|
390
|
-
name: entry.name,
|
|
391
|
-
platform: "android"
|
|
392
|
-
});
|
|
393
|
-
else if (result.status === "failed") failures.push(`could not delete evicted ${entry.name}: ${result.reason}`);
|
|
394
|
-
}
|
|
395
|
-
return {
|
|
396
|
-
status: "torn-down",
|
|
397
|
-
label: avdName,
|
|
398
|
-
parked: {
|
|
399
|
-
udid: avdName,
|
|
400
|
-
name: avdName,
|
|
401
|
-
platform: "android"
|
|
402
|
-
},
|
|
403
|
-
evicted: removed,
|
|
404
|
-
...failures.length ? { evictionFailures: failures } : {}
|
|
405
|
-
};
|
|
406
|
-
} catch (error) {
|
|
407
|
-
parkFallback = String(error?.message || error);
|
|
408
|
-
}
|
|
409
|
-
deleteAvd(avdName);
|
|
410
|
-
}
|
|
411
|
-
return {
|
|
412
|
-
status: "torn-down",
|
|
413
|
-
label: avdName,
|
|
414
|
-
serial: resolved.serial ?? null,
|
|
415
|
-
...parkFallback ? { parkFallback } : {}
|
|
416
|
-
};
|
|
417
|
-
} catch (e) {
|
|
418
|
-
return {
|
|
419
|
-
status: "failed",
|
|
420
|
-
reason: String(e?.message || e)
|
|
421
|
-
};
|
|
285
|
+
const capturing = [];
|
|
286
|
+
const abandoned = /* @__PURE__ */ new Set();
|
|
287
|
+
let patched = null;
|
|
288
|
+
const PROVIDER_CONTEXT = new AsyncLocalStorage();
|
|
289
|
+
function uploadDestination(lines) {
|
|
290
|
+
const text = (lines || []).map(stripAnsi);
|
|
291
|
+
for (const line of text) {
|
|
292
|
+
const url = /(https?:\/\/[^\s'"]+)/.exec(line)?.[1];
|
|
293
|
+
if (url !== void 0) return url.replace(/[.,)\]]+$/, "");
|
|
294
|
+
}
|
|
295
|
+
for (const line of text) {
|
|
296
|
+
const slug = /\bto\s+(@?[\w.-]+\/[\w.-]+)/i.exec(line)?.[1];
|
|
297
|
+
if (slug !== void 0) return slug.replace(/[.,)\]]+$/, "");
|
|
422
298
|
}
|
|
423
|
-
}
|
|
424
|
-
//#endregion
|
|
425
|
-
//#region src/engine/remote-cache.ts
|
|
426
|
-
const EAS_PROVIDER_PACKAGE = "eas-build-cache-provider";
|
|
427
|
-
const RESOLVE_TIMEOUT_MS = 3e4;
|
|
428
|
-
const UPLOAD_TIMEOUT_MS = 6e4;
|
|
429
|
-
const CONFIG_TIMEOUT_MS = 3e4;
|
|
430
|
-
const DYNAMIC_CONFIG_FILES = [
|
|
431
|
-
"app.config.ts",
|
|
432
|
-
"app.config.js",
|
|
433
|
-
"app.config.mjs",
|
|
434
|
-
"app.config.cjs"
|
|
435
|
-
];
|
|
436
|
-
const TIMED_OUT = Symbol("timed-out");
|
|
437
|
-
function dynamicConfigFile(root) {
|
|
438
|
-
for (const name of DYNAMIC_CONFIG_FILES) if (existsSync(join(root, name))) return name;
|
|
439
299
|
return null;
|
|
440
300
|
}
|
|
441
|
-
function
|
|
442
|
-
|
|
443
|
-
const expoField = config.expo;
|
|
444
|
-
const exp = expoField && typeof expoField === "object" ? expoField : config;
|
|
445
|
-
return exp.buildCacheProvider ?? exp.experiments?.buildCacheProvider ?? null;
|
|
301
|
+
function providerNote(text) {
|
|
302
|
+
return `${"cache".padEnd(11)} ${text}`;
|
|
446
303
|
}
|
|
447
|
-
function
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const owner = (expoField && typeof expoField === "object" ? expoField : config).owner;
|
|
451
|
-
return typeof owner === "string" && owner.trim() !== "" ? owner.trim() : null;
|
|
304
|
+
function currentFrame() {
|
|
305
|
+
const store = PROVIDER_CONTEXT.getStore();
|
|
306
|
+
return store && (capturing.includes(store) || abandoned.has(store)) ? store : null;
|
|
452
307
|
}
|
|
453
|
-
function
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
308
|
+
function install() {
|
|
309
|
+
if (patched && process.stdout.write === patched.patchedWrite) return;
|
|
310
|
+
const stdout = process.stdout;
|
|
311
|
+
const write = stdout.write.bind(stdout);
|
|
312
|
+
const log = console.log;
|
|
313
|
+
const passthrough = write;
|
|
314
|
+
const patchedWrite = ((chunk, encoding, callback) => {
|
|
315
|
+
const frame = currentFrame();
|
|
316
|
+
if (!frame) return passthrough(chunk, encoding, callback);
|
|
317
|
+
const cb = typeof encoding === "function" ? encoding : callback;
|
|
318
|
+
absorb(frame, typeof chunk === "string" ? chunk : String(chunk));
|
|
319
|
+
if (typeof cb === "function") cb();
|
|
320
|
+
return true;
|
|
321
|
+
});
|
|
322
|
+
const patchedLog = (...args) => {
|
|
323
|
+
const frame = currentFrame();
|
|
324
|
+
if (!frame) return log(...args);
|
|
325
|
+
absorb(frame, `${format(...args)}\n`);
|
|
459
326
|
};
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
327
|
+
stdout.write = patchedWrite;
|
|
328
|
+
console.log = patchedLog;
|
|
329
|
+
patched = {
|
|
330
|
+
stdout,
|
|
331
|
+
write,
|
|
332
|
+
log,
|
|
333
|
+
patchedWrite,
|
|
334
|
+
patchedLog
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function uninstall() {
|
|
338
|
+
if (!patched || capturing.length || abandoned.size) return;
|
|
339
|
+
if (patched.stdout.write === patched.patchedWrite) patched.stdout.write = patched.write;
|
|
340
|
+
if (console.log === patched.patchedLog) console.log = patched.log;
|
|
341
|
+
patched = null;
|
|
342
|
+
}
|
|
343
|
+
function absorb(frame, chunk) {
|
|
344
|
+
try {
|
|
345
|
+
process.stderr.write(chunk);
|
|
346
|
+
} catch {}
|
|
347
|
+
frame.pending += chunk;
|
|
348
|
+
let index = frame.pending.indexOf("\n");
|
|
349
|
+
while (index !== -1) {
|
|
350
|
+
emitLine(frame, frame.pending.slice(0, index));
|
|
351
|
+
frame.pending = frame.pending.slice(index + 1);
|
|
352
|
+
index = frame.pending.indexOf("\n");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function emitLine(frame, raw) {
|
|
356
|
+
const line = stripAnsi(raw).trim();
|
|
357
|
+
if (line === "") return;
|
|
358
|
+
frame.lines.push(line);
|
|
359
|
+
const writer = frame.writer();
|
|
360
|
+
try {
|
|
361
|
+
writer?.write({
|
|
362
|
+
src: "build",
|
|
363
|
+
level: "debug",
|
|
364
|
+
event: "provider",
|
|
365
|
+
msg: line
|
|
366
|
+
});
|
|
367
|
+
} catch {}
|
|
368
|
+
frame.onLine?.(line);
|
|
369
|
+
}
|
|
370
|
+
function beginCapture({ logWriter = null, projectRoot = null, platform = null, onLine = null } = {}) {
|
|
371
|
+
let own = null;
|
|
372
|
+
const frame = {
|
|
373
|
+
lines: [],
|
|
374
|
+
pending: "",
|
|
375
|
+
onLine,
|
|
376
|
+
writer: () => {
|
|
377
|
+
if (logWriter) return logWriter;
|
|
378
|
+
if (own) return own;
|
|
379
|
+
if (!projectRoot || !platform) return null;
|
|
380
|
+
own = createNdjsonWriter(join(workspaceLogsDir(projectRoot), `build-${platform}.ndjson`));
|
|
381
|
+
return own;
|
|
382
|
+
},
|
|
383
|
+
close: () => {
|
|
384
|
+
own?.close?.();
|
|
385
|
+
own = null;
|
|
469
386
|
}
|
|
387
|
+
};
|
|
388
|
+
capturing.push(frame);
|
|
389
|
+
install();
|
|
390
|
+
return frame;
|
|
391
|
+
}
|
|
392
|
+
function endCapture(frame) {
|
|
393
|
+
if (!frame) return;
|
|
394
|
+
const at = capturing.lastIndexOf(frame);
|
|
395
|
+
if (at !== -1) capturing.splice(at, 1);
|
|
396
|
+
abandoned.delete(frame);
|
|
397
|
+
if (frame.pending !== "") {
|
|
398
|
+
const rest = frame.pending;
|
|
399
|
+
frame.pending = "";
|
|
400
|
+
emitLine(frame, rest);
|
|
470
401
|
}
|
|
471
|
-
|
|
402
|
+
frame.close();
|
|
403
|
+
uninstall();
|
|
472
404
|
}
|
|
473
|
-
function
|
|
474
|
-
|
|
405
|
+
function abandonCapture(frame, work) {
|
|
406
|
+
if (!frame) return;
|
|
407
|
+
const at = capturing.lastIndexOf(frame);
|
|
408
|
+
if (at !== -1) capturing.splice(at, 1);
|
|
409
|
+
abandoned.add(frame);
|
|
410
|
+
Promise.resolve(work).then(() => endCapture(frame), () => endCapture(frame));
|
|
475
411
|
}
|
|
476
|
-
function
|
|
477
|
-
if (!plugin ||
|
|
478
|
-
const
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
412
|
+
async function resolveRemote({ provider, platform, projectRoot, fingerprintHash, runOptions = null, timeoutMs = RESOLVE_TIMEOUT_MS, logWriter = null } = {}) {
|
|
413
|
+
if (!provider?.plugin || !fingerprintHash) return null;
|
|
414
|
+
const opts = runOptions || runOptionsFor(platform);
|
|
415
|
+
const outcome = await withBudget(async () => {
|
|
416
|
+
const props = {
|
|
417
|
+
fingerprintHash: await providerFingerprint({
|
|
418
|
+
provider,
|
|
419
|
+
platform,
|
|
420
|
+
projectRoot,
|
|
421
|
+
runOptions: opts
|
|
422
|
+
}) ?? fingerprintHash,
|
|
423
|
+
platform,
|
|
424
|
+
runOptions: opts,
|
|
425
|
+
projectRoot
|
|
426
|
+
};
|
|
427
|
+
return typeof provider.plugin.resolveBuildCache === "function" ? provider.plugin.resolveBuildCache(props, provider.options) : provider.plugin.resolveRemoteBuildCache(props, provider.options);
|
|
428
|
+
}, timeoutMs, {
|
|
429
|
+
logWriter,
|
|
430
|
+
projectRoot,
|
|
431
|
+
platform
|
|
432
|
+
});
|
|
433
|
+
if (outcome.timedOut) return { timedOut: true };
|
|
434
|
+
if (outcome.error) return { failed: firstLine(outcome.error) };
|
|
435
|
+
const appPath = typeof outcome.value === "string" ? outcome.value.trim() : "";
|
|
436
|
+
if (!appPath) return null;
|
|
437
|
+
if (!existsSync(appPath)) return { failed: `returned ${appPath}, which does not exist` };
|
|
438
|
+
return { appPath };
|
|
482
439
|
}
|
|
483
|
-
function
|
|
484
|
-
|
|
440
|
+
async function uploadRemote({ provider, platform, projectRoot, fingerprintHash, buildPath, runOptions = null, timeoutMs = UPLOAD_TIMEOUT_MS, logWriter = null, note = (line) => console.error(line) } = {}) {
|
|
441
|
+
if (!provider?.plugin || !fingerprintHash || !buildPath) return { skipped: true };
|
|
442
|
+
const opts = runOptions || runOptionsFor(platform);
|
|
443
|
+
let announced = false;
|
|
444
|
+
const onLine = (line) => {
|
|
445
|
+
if (announced) return;
|
|
446
|
+
const dest = uploadDestination([line]);
|
|
447
|
+
if (!dest) return;
|
|
448
|
+
announced = true;
|
|
449
|
+
note(providerNote(`uploading to ${dest}`));
|
|
450
|
+
};
|
|
451
|
+
const outcome = await withBudget(async () => {
|
|
452
|
+
const props = {
|
|
453
|
+
projectRoot,
|
|
454
|
+
platform,
|
|
455
|
+
fingerprintHash: await providerFingerprint({
|
|
456
|
+
provider,
|
|
457
|
+
platform,
|
|
458
|
+
projectRoot,
|
|
459
|
+
runOptions: opts
|
|
460
|
+
}) ?? fingerprintHash,
|
|
461
|
+
buildPath,
|
|
462
|
+
runOptions: opts
|
|
463
|
+
};
|
|
464
|
+
return typeof provider.plugin.uploadBuildCache === "function" ? provider.plugin.uploadBuildCache(props, provider.options) : provider.plugin.uploadRemoteBuildCache(props, provider.options);
|
|
465
|
+
}, timeoutMs, {
|
|
466
|
+
logWriter,
|
|
467
|
+
projectRoot,
|
|
468
|
+
platform,
|
|
469
|
+
onLine
|
|
470
|
+
});
|
|
471
|
+
if (outcome.timedOut) return { timedOut: true };
|
|
472
|
+
if (outcome.error) return { failed: firstLine(outcome.error) };
|
|
473
|
+
const destination = uploadDestination(outcome.lines);
|
|
474
|
+
return destination ? {
|
|
475
|
+
uploaded: true,
|
|
476
|
+
destination
|
|
477
|
+
} : { uploaded: true };
|
|
485
478
|
}
|
|
486
|
-
function
|
|
479
|
+
async function providerFingerprint({ provider, platform, projectRoot, runOptions }) {
|
|
480
|
+
if (typeof provider.plugin.calculateFingerprintHash !== "function") return null;
|
|
487
481
|
try {
|
|
488
|
-
|
|
482
|
+
const hash = await provider.plugin.calculateFingerprintHash({
|
|
483
|
+
projectRoot,
|
|
484
|
+
platform,
|
|
485
|
+
runOptions
|
|
486
|
+
}, provider.options);
|
|
487
|
+
return typeof hash === "string" && hash.trim() !== "" ? hash.trim() : null;
|
|
489
488
|
} catch {
|
|
490
|
-
|
|
489
|
+
return null;
|
|
491
490
|
}
|
|
492
491
|
}
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
492
|
+
async function withBudget(factory, ms, capture) {
|
|
493
|
+
let timer = null;
|
|
494
|
+
const timeout = new Promise((resolve) => {
|
|
495
|
+
timer = setTimeout(() => resolve(TIMED_OUT), ms);
|
|
496
|
+
timer?.unref?.();
|
|
497
|
+
});
|
|
498
|
+
const frame = beginCapture(capture || {});
|
|
499
|
+
const work = Promise.resolve().then(() => PROVIDER_CONTEXT.run(frame, factory)).then((value) => ({ value }), (error) => ({ error }));
|
|
500
|
+
try {
|
|
501
|
+
const settled = await Promise.race([work, timeout]);
|
|
502
|
+
if (settled === TIMED_OUT) {
|
|
503
|
+
abandonCapture(frame, work);
|
|
502
504
|
return {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
+
timedOut: true,
|
|
506
|
+
lines: frame.lines
|
|
505
507
|
};
|
|
506
|
-
} catch (err) {
|
|
507
|
-
return { unavailable: `app.json could not be parsed: ${firstLine(err)}` };
|
|
508
508
|
}
|
|
509
|
-
|
|
510
|
-
const bin = expoBinPath(root);
|
|
511
|
-
if (!bin) return { unavailable: `${dynamic} is code, so it has to be evaluated to read its buildCacheProvider, and the \`expo\` package is not resolvable from this project (no expo/package.json to read a bin from, and no node_modules/.bin/expo here or in any parent)` };
|
|
512
|
-
const exec = run || ((file, args, opts) => getExecutor().runFile(file, args, opts));
|
|
513
|
-
let stdout;
|
|
514
|
-
try {
|
|
515
|
-
stdout = exec(bin, [
|
|
516
|
-
"config",
|
|
517
|
-
"--json",
|
|
518
|
-
root
|
|
519
|
-
], { timeoutMs });
|
|
520
|
-
} catch (err) {
|
|
521
|
-
return { unavailable: `\`expo config --json\` failed: ${firstLine(err)}` };
|
|
522
|
-
}
|
|
523
|
-
try {
|
|
509
|
+
endCapture(frame);
|
|
524
510
|
return {
|
|
525
|
-
|
|
526
|
-
|
|
511
|
+
...settled,
|
|
512
|
+
lines: frame.lines
|
|
527
513
|
};
|
|
528
514
|
} catch (err) {
|
|
529
|
-
|
|
515
|
+
endCapture(frame);
|
|
516
|
+
throw err;
|
|
517
|
+
} finally {
|
|
518
|
+
if (timer) clearTimeout(timer);
|
|
530
519
|
}
|
|
531
520
|
}
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
let mod;
|
|
536
|
-
try {
|
|
537
|
-
mod = localRequire(file);
|
|
538
|
-
} catch (err) {
|
|
539
|
-
if (err?.code !== "ERR_REQUIRE_ESM") throw err;
|
|
540
|
-
mod = await import(pathToFileURL(file).href);
|
|
541
|
-
}
|
|
542
|
-
const plugin = mod?.default ?? mod;
|
|
543
|
-
if (!isProviderPlugin(plugin)) throw new Error(`"${reference}" does not export resolveBuildCache and uploadBuildCache functions`);
|
|
544
|
-
return plugin;
|
|
521
|
+
function firstLine(err) {
|
|
522
|
+
const line = (String(err?.message || err || "unknown error").trim().split("\n")[0] ?? "").trim();
|
|
523
|
+
return line.length > 200 ? `${line.slice(0, 197)}...` : line;
|
|
545
524
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
if (normalized.invalid) return { unavailable: `buildCacheProvider is ${normalized.invalid}, which is not "eas" or { plugin: <module> }` };
|
|
556
|
-
if (normalized.reference === "@stim-cli/expo-build-cache") return { none: true };
|
|
557
|
-
let plugin;
|
|
558
|
-
try {
|
|
559
|
-
plugin = await loadPlugin(projectRoot, normalized.reference, { requireFrom });
|
|
560
|
-
} catch (err) {
|
|
561
|
-
const missing = err?.code === "MODULE_NOT_FOUND";
|
|
562
|
-
return { unavailable: normalized.name === "eas" && missing ? `the EAS build cache needs the \`${EAS_PROVIDER_PACKAGE}\` package, which is not installed in this project` : `${normalized.name} could not be loaded: ${firstLine(err)}` };
|
|
525
|
+
const POOL_SETTING_REMEDY = "Run `stim guide settings` for the device pool bounds and where it can be set.";
|
|
526
|
+
const MAX_SETTING = {
|
|
527
|
+
ios: {
|
|
528
|
+
key: "iosParkedMax",
|
|
529
|
+
env: "STIM_POOL_IOS_PARKED_MAX"
|
|
530
|
+
},
|
|
531
|
+
android: {
|
|
532
|
+
key: "androidParkedMax",
|
|
533
|
+
env: "STIM_POOL_ANDROID_PARKED_MAX"
|
|
563
534
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
name: normalized.name,
|
|
570
|
-
owner: ownerFromConfig(read.config)
|
|
571
|
-
};
|
|
535
|
+
};
|
|
536
|
+
function parseMax(raw, strings) {
|
|
537
|
+
const value = strings && typeof raw === "string" ? /^\d+$/.test(raw.trim()) ? Number(raw.trim()) : NaN : raw;
|
|
538
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) return null;
|
|
539
|
+
return value;
|
|
572
540
|
}
|
|
573
|
-
|
|
574
|
-
const
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
const raw =
|
|
584
|
-
if (raw === void 0) return {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
541
|
+
function parkedMaxSetting(platform, { config, env = process.env } = {}) {
|
|
542
|
+
const { key, env: envKey } = MAX_SETTING[platform];
|
|
543
|
+
const fromEnv = env[envKey];
|
|
544
|
+
const explicit = fromEnv !== void 0 && fromEnv !== "";
|
|
545
|
+
const pool = (config === void 0 ? loadConfig() : config)?.pool;
|
|
546
|
+
if (!explicit && pool !== void 0 && (pool === null || typeof pool !== "object" || Array.isArray(pool))) return {
|
|
547
|
+
max: 0,
|
|
548
|
+
error: "Invalid pool value. Expected an object with simulator and emulator bounds."
|
|
549
|
+
};
|
|
550
|
+
const fromConfig = pool !== null && typeof pool === "object" && !Array.isArray(pool) ? pool[key] : void 0;
|
|
551
|
+
const raw = explicit ? fromEnv : fromConfig;
|
|
552
|
+
if (raw === void 0) return {
|
|
553
|
+
max: env.STIM_HOME ? 0 : 3,
|
|
554
|
+
error: null
|
|
555
|
+
};
|
|
556
|
+
const parsed = parseMax(raw, explicit);
|
|
557
|
+
if (parsed === null) return {
|
|
558
|
+
max: 0,
|
|
559
|
+
error: `Invalid ${explicit ? envKey : `pool.${key}`} value ${JSON.stringify(raw)}. Expected a whole number of parked ${platform === "ios" ? "simulators" : "emulators"}, 0 or more.`
|
|
560
|
+
};
|
|
593
561
|
return {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
accounts: accounts.length ? accounts : null,
|
|
597
|
-
viaToken
|
|
562
|
+
max: explicit ? parsed : env.STIM_HOME ? 0 : parsed,
|
|
563
|
+
error: null
|
|
598
564
|
};
|
|
599
565
|
}
|
|
600
|
-
function
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return
|
|
604
|
-
}
|
|
605
|
-
function easAuthNote(status) {
|
|
606
|
-
const { code, account, owner, reason, phase = "resolve" } = status || {};
|
|
607
|
-
const because = reason ? ` (${reason})` : "";
|
|
608
|
-
if (code === "logged-out") return `eas is not authenticated${because} -- run \`eas login\` (or set EXPO_TOKEN); ` + (phase === "upload" ? "this build stayed in the local cache" : "building with the local cache only");
|
|
609
|
-
if (code === "wrong-account") return `eas is authenticated as ${account}, and this project's owner is ${owner} -- run \`eas login\` as a member of ${owner} (or set EXPO_TOKEN); consulting the EAS cache anyway`;
|
|
610
|
-
return null;
|
|
566
|
+
function isParkedRecord(value, platform) {
|
|
567
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
568
|
+
const record = value;
|
|
569
|
+
return typeof record.udid === "string" && typeof record.name === "string" && record.name.startsWith("stim-") && typeof record.parkedAt === "string" && (platform === "android" ? record.udid === record.name && /^stim-[A-Za-z0-9._-]+$/.test(record.name) && typeof record.systemImage === "string" && typeof record.configuration === "string" : typeof record.deviceTypeIdentifier === "string" && typeof record.runtimeIdentifier === "string" && typeof record.simslimManaged === "boolean" && (record.bundleId === void 0 || typeof record.bundleId === "string") && (record.cacheKey === void 0 || typeof record.cacheKey === "string"));
|
|
611
570
|
}
|
|
612
|
-
function
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
571
|
+
function poolBlock(config) {
|
|
572
|
+
const raw = config?.parked;
|
|
573
|
+
const block = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
574
|
+
const read = (platform) => {
|
|
575
|
+
const list = block[platform];
|
|
576
|
+
return Array.isArray(list) ? list.filter((record) => isParkedRecord(record, platform)) : [];
|
|
617
577
|
};
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
source: "project"
|
|
578
|
+
return {
|
|
579
|
+
ios: read("ios"),
|
|
580
|
+
android: read("android")
|
|
622
581
|
};
|
|
623
|
-
const onPath = lookupPath ? lookupPath() : getExecutor().runQuiet(`command -v ${EAS_CLI_BIN}`, { timeoutMs });
|
|
624
|
-
const file = (String(onPath || "").split("\n")[0] ?? "").trim();
|
|
625
|
-
return file ? {
|
|
626
|
-
file,
|
|
627
|
-
source: "path"
|
|
628
|
-
} : null;
|
|
629
582
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const key = `${projectRoot}::${owner || ""}`;
|
|
633
|
-
if (cache?.has(key)) return cache.get(key);
|
|
634
|
-
const answer = probeEasAuth({
|
|
635
|
-
projectRoot,
|
|
636
|
-
owner,
|
|
637
|
-
run,
|
|
638
|
-
resolveBin,
|
|
639
|
-
timeoutMs
|
|
640
|
-
});
|
|
641
|
-
cache?.set(key, answer);
|
|
642
|
-
return answer;
|
|
583
|
+
function readParked(platform, { config } = {}) {
|
|
584
|
+
return poolBlock(config === void 0 ? loadConfig() : config)[platform];
|
|
643
585
|
}
|
|
644
|
-
function
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
code: "no-cli",
|
|
649
|
-
reason: "no `eas` executable is resolvable from this project or on PATH",
|
|
650
|
-
remedy: "Install eas-cli (`npm i -g eas-cli`, or as a project devDependency), then run `eas login`."
|
|
651
|
-
};
|
|
652
|
-
const exec = run || ((file, args, opts) => getExecutor().runFile(file, args, opts));
|
|
653
|
-
let result;
|
|
654
|
-
try {
|
|
655
|
-
result = {
|
|
656
|
-
stdout: String(exec(bin.file, ["whoami"], { timeoutMs }) ?? ""),
|
|
657
|
-
exitCode: 0
|
|
658
|
-
};
|
|
659
|
-
} catch (e) {
|
|
660
|
-
const err = e;
|
|
661
|
-
if (err?.code === "ETIMEDOUT" || err?.signal === "SIGTERM" || err?.killed) return { unknown: `eas whoami timed out after ${timeoutMs}ms` };
|
|
662
|
-
result = {
|
|
663
|
-
stdout: String(err?.stdout ?? ""),
|
|
664
|
-
stderr: String(err?.stderr ?? err?.message ?? ""),
|
|
665
|
-
exitCode: typeof err?.status === "number" ? err.status : 1
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
const parsed = parseWhoami(result);
|
|
669
|
-
if (parsed.loggedOut) return {
|
|
670
|
-
failed: true,
|
|
671
|
-
code: "logged-out",
|
|
672
|
-
reason: "eas whoami says \"Not logged in\"",
|
|
673
|
-
remedy: "Run `eas login` (or set EXPO_TOKEN)."
|
|
586
|
+
function writeParked(config, platform, records) {
|
|
587
|
+
config.parked = {
|
|
588
|
+
...poolBlock(config),
|
|
589
|
+
[platform]: records
|
|
674
590
|
};
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
591
|
+
}
|
|
592
|
+
function oldestFirst(records) {
|
|
593
|
+
return records.toSorted((a, b) => String(a.parkedAt).localeCompare(String(b.parkedAt)));
|
|
594
|
+
}
|
|
595
|
+
function selectParked(records, { deviceTypeIdentifier, runtimeIdentifier }) {
|
|
596
|
+
return oldestFirst(records.filter((r) => r.deletionClaim === void 0 && r.deviceTypeIdentifier === deviceTypeIdentifier && r.runtimeIdentifier === runtimeIdentifier));
|
|
597
|
+
}
|
|
598
|
+
function evictOverflow(records, max) {
|
|
599
|
+
if (records.length <= max) return {
|
|
600
|
+
keep: [...records],
|
|
601
|
+
evicted: []
|
|
684
602
|
};
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
603
|
+
const ordered = oldestFirst(records);
|
|
604
|
+
const evicted = ordered.slice(0, ordered.length - max);
|
|
605
|
+
const dropped = new Set(evicted.map((r) => r.udid));
|
|
606
|
+
return {
|
|
607
|
+
keep: records.filter((r) => !dropped.has(r.udid)),
|
|
608
|
+
evicted
|
|
691
609
|
};
|
|
692
610
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
611
|
+
function parkSim({ platform, projectPath, slot = "default", record, max }) {
|
|
612
|
+
return withConfigLock(() => {
|
|
613
|
+
const cfg = ensureConfig();
|
|
614
|
+
const current = deviceSlotPlatforms(cfg.projects[projectPath], slot)?.[platform];
|
|
615
|
+
const currentId = platform === "ios" ? current?.deviceUdid : current?.avdName;
|
|
616
|
+
if (!current?.owned || currentId !== record.udid) throw new Error(`The ${platform === "ios" ? "simulator" : "emulator"} assignment changed before parking.`);
|
|
617
|
+
const { keep, evicted } = evictOverflow([...readParked(platform, { config: cfg }).filter((r) => r.udid !== record.udid), record], max);
|
|
618
|
+
writeParked(cfg, platform, [...keep, ...evicted]);
|
|
619
|
+
const project = cfg.projects[projectPath];
|
|
620
|
+
if (project) removeSlotDevice(project, platform, slot);
|
|
621
|
+
saveConfig(cfg);
|
|
622
|
+
return evicted;
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
function adoptParked({ platform, projectPath, slot = "default", udid, device }) {
|
|
626
|
+
return withConfigLock(() => {
|
|
627
|
+
const cfg = ensureConfig();
|
|
628
|
+
const records = readParked(platform, { config: cfg });
|
|
629
|
+
const taken = records.find((r) => r.udid === udid);
|
|
630
|
+
if (!taken || taken.deletionClaim !== void 0) return null;
|
|
631
|
+
if (deviceSlotPlatforms(cfg.projects[projectPath], slot)?.[platform]) return null;
|
|
632
|
+
writeParked(cfg, platform, records.filter((r) => r.udid !== udid));
|
|
633
|
+
const project = cfg.projects[projectPath];
|
|
634
|
+
if (!project) throw new Error(`Project not registered: ${projectPath}`);
|
|
635
|
+
assignSlotDevice(project, platform, device, slot);
|
|
636
|
+
saveConfig(cfg);
|
|
637
|
+
return taken;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
function isProcessAlive(pid) {
|
|
641
|
+
try {
|
|
642
|
+
process.kill(pid, 0);
|
|
643
|
+
return true;
|
|
644
|
+
} catch (error) {
|
|
645
|
+
return error.code === "EPERM";
|
|
706
646
|
}
|
|
707
|
-
return null;
|
|
708
647
|
}
|
|
709
|
-
function
|
|
710
|
-
|
|
648
|
+
function parseDeletionClaim(value) {
|
|
649
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
|
|
650
|
+
const claim = value;
|
|
651
|
+
if (!Number.isSafeInteger(claim.pid) || claim.pid <= 0) return null;
|
|
652
|
+
if (typeof claim.token !== "string" || claim.token.length === 0) return null;
|
|
653
|
+
return {
|
|
654
|
+
pid: claim.pid,
|
|
655
|
+
token: claim.token
|
|
656
|
+
};
|
|
711
657
|
}
|
|
712
|
-
function
|
|
713
|
-
|
|
714
|
-
|
|
658
|
+
function claimParkedRemoval(platform, udid) {
|
|
659
|
+
return withConfigLock(() => {
|
|
660
|
+
const cfg = loadConfig();
|
|
661
|
+
if (!cfg) return null;
|
|
662
|
+
const records = readParked(platform, { config: cfg });
|
|
663
|
+
const record = records.find((candidate) => candidate.udid === udid);
|
|
664
|
+
if (!record) return null;
|
|
665
|
+
const existingClaim = parseDeletionClaim(record.deletionClaim);
|
|
666
|
+
if (record.deletionClaim !== void 0 && (!existingClaim || isProcessAlive(existingClaim.pid))) return null;
|
|
667
|
+
const token = randomUUID();
|
|
668
|
+
const claimedRecord = {
|
|
669
|
+
...record,
|
|
670
|
+
deletionClaim: {
|
|
671
|
+
pid: process.pid,
|
|
672
|
+
token
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
writeParked(cfg, platform, records.map((candidate) => candidate.udid === udid ? claimedRecord : candidate));
|
|
676
|
+
saveConfig(cfg);
|
|
677
|
+
const claimed = { ...record };
|
|
678
|
+
delete claimed.deletionClaim;
|
|
679
|
+
return {
|
|
680
|
+
record: claimed,
|
|
681
|
+
token
|
|
682
|
+
};
|
|
683
|
+
});
|
|
715
684
|
}
|
|
716
|
-
function
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
if (typeof cb === "function") cb();
|
|
728
|
-
return true;
|
|
685
|
+
function clearParkedRemovalClaim(platform, udid, token) {
|
|
686
|
+
withConfigLock(() => {
|
|
687
|
+
const cfg = loadConfig();
|
|
688
|
+
if (!cfg) return;
|
|
689
|
+
const records = readParked(platform, { config: cfg });
|
|
690
|
+
const record = records.find((candidate) => candidate.udid === udid);
|
|
691
|
+
if (!record || parseDeletionClaim(record.deletionClaim)?.token !== token) return;
|
|
692
|
+
const restored = { ...record };
|
|
693
|
+
delete restored.deletionClaim;
|
|
694
|
+
writeParked(cfg, platform, records.map((candidate) => candidate.udid === udid ? restored : candidate));
|
|
695
|
+
saveConfig(cfg);
|
|
729
696
|
});
|
|
730
|
-
const patchedLog = (...args) => {
|
|
731
|
-
const frame = currentFrame();
|
|
732
|
-
if (!frame) return log(...args);
|
|
733
|
-
absorb(frame, `${format(...args)}\n`);
|
|
734
|
-
};
|
|
735
|
-
stdout.write = patchedWrite;
|
|
736
|
-
console.log = patchedLog;
|
|
737
|
-
patched = {
|
|
738
|
-
stdout,
|
|
739
|
-
write,
|
|
740
|
-
log,
|
|
741
|
-
patchedWrite,
|
|
742
|
-
patchedLog
|
|
743
|
-
};
|
|
744
697
|
}
|
|
745
|
-
function
|
|
746
|
-
|
|
747
|
-
if (
|
|
748
|
-
|
|
749
|
-
|
|
698
|
+
function removeParkedAfter(platform, udid, beforeRemove) {
|
|
699
|
+
const claim = claimParkedRemoval(platform, udid);
|
|
700
|
+
if (!claim) return null;
|
|
701
|
+
try {
|
|
702
|
+
beforeRemove(claim.record);
|
|
703
|
+
} catch (error) {
|
|
704
|
+
try {
|
|
705
|
+
clearParkedRemovalClaim(platform, udid, claim.token);
|
|
706
|
+
} catch {}
|
|
707
|
+
throw error;
|
|
708
|
+
}
|
|
709
|
+
return withConfigLock(() => {
|
|
710
|
+
const cfg = loadConfig();
|
|
711
|
+
if (!cfg) return null;
|
|
712
|
+
const records = readParked(platform, { config: cfg });
|
|
713
|
+
if (parseDeletionClaim(records.find((candidate) => candidate.udid === udid)?.deletionClaim)?.token !== claim.token) return null;
|
|
714
|
+
writeParked(cfg, platform, records.filter((candidate) => candidate.udid !== udid));
|
|
715
|
+
saveConfig(cfg);
|
|
716
|
+
return claim.record;
|
|
717
|
+
});
|
|
750
718
|
}
|
|
751
|
-
function
|
|
719
|
+
function dropParked(platform, udid) {
|
|
720
|
+
return removeParkedAfter(platform, udid, () => {}) !== null;
|
|
721
|
+
}
|
|
722
|
+
//#endregion
|
|
723
|
+
//#region src/teardown.ts
|
|
724
|
+
function teardownParkedAvd(avdName) {
|
|
752
725
|
try {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
726
|
+
return removeParkedAfter("android", avdName, () => {
|
|
727
|
+
const result = teardownOwnedAvd(avdName, {
|
|
728
|
+
del: true,
|
|
729
|
+
owner: { pool: true }
|
|
730
|
+
});
|
|
731
|
+
if (result.status !== "torn-down" && result.status !== "missing") throw new Error(result.reason);
|
|
732
|
+
}) ? {
|
|
733
|
+
status: "torn-down",
|
|
734
|
+
label: avdName
|
|
735
|
+
} : {
|
|
736
|
+
status: "skipped",
|
|
737
|
+
kind: "not-parked",
|
|
738
|
+
reason: "emulator is no longer parked"
|
|
739
|
+
};
|
|
740
|
+
} catch (error) {
|
|
741
|
+
return {
|
|
742
|
+
status: "failed",
|
|
743
|
+
reason: String(error?.message || error)
|
|
744
|
+
};
|
|
761
745
|
}
|
|
762
746
|
}
|
|
763
|
-
function
|
|
764
|
-
const line = stripAnsi(raw).trim();
|
|
765
|
-
if (line === "") return;
|
|
766
|
-
frame.lines.push(line);
|
|
767
|
-
const writer = frame.writer();
|
|
747
|
+
function teardownParkedIosSim(udid, { label, deleteSim = deleteParkedIosSim } = {}) {
|
|
768
748
|
try {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
|
|
749
|
+
const removed = removeParkedAfter("ios", udid, () => deleteSim(udid));
|
|
750
|
+
if (!removed) return {
|
|
751
|
+
status: "skipped",
|
|
752
|
+
kind: "not-parked",
|
|
753
|
+
reason: "simulator is no longer parked"
|
|
754
|
+
};
|
|
755
|
+
return {
|
|
756
|
+
status: "torn-down",
|
|
757
|
+
label: label ?? removed.name
|
|
758
|
+
};
|
|
759
|
+
} catch (error) {
|
|
760
|
+
return {
|
|
761
|
+
status: "failed",
|
|
762
|
+
reason: String(error?.message || error)
|
|
763
|
+
};
|
|
764
|
+
}
|
|
777
765
|
}
|
|
778
|
-
function
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
766
|
+
function parkOwnedIosSim(udid, park) {
|
|
767
|
+
const resolved = resolveOwnedIosSim(udid);
|
|
768
|
+
if (resolved.missing) throw new Error(`simulator ${udid} disappeared after shutdown`);
|
|
769
|
+
if (resolved.notOwned) throw new Error(`simulator ${udid} is now named ${JSON.stringify(resolved.notOwned)}`);
|
|
770
|
+
const sim = resolved.sim;
|
|
771
|
+
if (sim.state !== "Shutdown") throw new Error(`simulator ${udid} is still ${sim.state} after shutdown`);
|
|
772
|
+
const model = listIosDeviceTypes().find((d) => d.identifier === sim.deviceTypeIdentifier)?.name ?? null;
|
|
773
|
+
const runtime = parseRuntimeVersion(sim.runtime);
|
|
774
|
+
if (park.bundleId) {
|
|
775
|
+
if (!sim.dataPath) throw new Error(`simulator ${udid} did not report a data path for app cleanup`);
|
|
776
|
+
const container = findAppDataContainer(sim.dataPath, park.bundleId);
|
|
777
|
+
if (container) clearAppDataContainer(container);
|
|
778
|
+
}
|
|
779
|
+
const name = parkedSimName(sim.udid, {
|
|
780
|
+
model,
|
|
781
|
+
runtime
|
|
782
|
+
});
|
|
783
|
+
renameIosSim(sim.udid, name);
|
|
784
|
+
const record = {
|
|
785
|
+
udid: sim.udid,
|
|
786
|
+
name,
|
|
787
|
+
deviceTypeIdentifier: sim.deviceTypeIdentifier,
|
|
788
|
+
runtimeIdentifier: sim.runtime,
|
|
789
|
+
parkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
790
|
+
simslimManaged: Boolean(park.simslimManaged),
|
|
791
|
+
...park.bundleId ? { bundleId: park.bundleId } : {},
|
|
792
|
+
...park.cacheKey ? { cacheKey: park.cacheKey } : {}
|
|
793
|
+
};
|
|
794
|
+
return {
|
|
795
|
+
record,
|
|
796
|
+
evicted: parkSim({
|
|
797
|
+
platform: "ios",
|
|
798
|
+
projectPath: park.projectPath,
|
|
799
|
+
slot: park.slot,
|
|
800
|
+
record,
|
|
801
|
+
max: park.max
|
|
802
|
+
})
|
|
795
803
|
};
|
|
796
|
-
capturing.push(frame);
|
|
797
|
-
install();
|
|
798
|
-
return frame;
|
|
799
804
|
}
|
|
800
|
-
function
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
805
|
+
function teardownOwnedIosSim(udid, { del = false, label, park } = {}) {
|
|
806
|
+
let parkFallback;
|
|
807
|
+
try {
|
|
808
|
+
const resolved = resolveOwnedIosSim(udid);
|
|
809
|
+
if (resolved.notOwned) return {
|
|
810
|
+
status: "skipped",
|
|
811
|
+
kind: "not-owned",
|
|
812
|
+
reason: `sim is now named "${resolved.notOwned}", not Stim-owned by name`
|
|
813
|
+
};
|
|
814
|
+
if (resolved.missing) return { status: "missing" };
|
|
815
|
+
shutdownIosSim(udid);
|
|
816
|
+
const sim = resolved.sim;
|
|
817
|
+
if (del && park && park.max > 0) try {
|
|
818
|
+
const { record, evicted } = parkOwnedIosSim(udid, park);
|
|
819
|
+
const removed = [];
|
|
820
|
+
const failures = [];
|
|
821
|
+
for (const entry of evicted) {
|
|
822
|
+
const result = teardownParkedIosSim(entry.udid, { label: entry.name });
|
|
823
|
+
if (result.status === "torn-down") removed.push({
|
|
824
|
+
udid: entry.udid,
|
|
825
|
+
name: entry.name
|
|
826
|
+
});
|
|
827
|
+
else if (result.status === "failed") failures.push(`could not delete evicted ${entry.name} (${entry.udid}): ${result.reason}`);
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
status: "torn-down",
|
|
831
|
+
label: label ?? sim.name ?? udid,
|
|
832
|
+
parked: {
|
|
833
|
+
udid: record.udid,
|
|
834
|
+
name: record.name
|
|
835
|
+
},
|
|
836
|
+
evicted: removed,
|
|
837
|
+
...failures.length ? { evictionFailures: failures } : {}
|
|
838
|
+
};
|
|
839
|
+
} catch (e) {
|
|
840
|
+
parkFallback = String(e?.message || e);
|
|
841
|
+
}
|
|
842
|
+
if (del) deleteIosSim(udid);
|
|
843
|
+
return {
|
|
844
|
+
status: "torn-down",
|
|
845
|
+
label: label ?? sim.name ?? udid,
|
|
846
|
+
...parkFallback ? { parkFallback } : {}
|
|
847
|
+
};
|
|
848
|
+
} catch (e) {
|
|
849
|
+
return {
|
|
850
|
+
status: "failed",
|
|
851
|
+
reason: String(e?.message || e),
|
|
852
|
+
...parkFallback ? { parkFallback } : {}
|
|
853
|
+
};
|
|
809
854
|
}
|
|
810
|
-
frame.close();
|
|
811
|
-
uninstall();
|
|
812
|
-
}
|
|
813
|
-
function abandonCapture(frame, work) {
|
|
814
|
-
if (!frame) return;
|
|
815
|
-
const at = capturing.lastIndexOf(frame);
|
|
816
|
-
if (at !== -1) capturing.splice(at, 1);
|
|
817
|
-
abandoned.add(frame);
|
|
818
|
-
Promise.resolve(work).then(() => endCapture(frame), () => endCapture(frame));
|
|
819
855
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
return typeof provider.plugin.resolveBuildCache === "function" ? provider.plugin.resolveBuildCache(props, provider.options) : provider.plugin.resolveRemoteBuildCache(props, provider.options);
|
|
836
|
-
}, timeoutMs, {
|
|
837
|
-
logWriter,
|
|
838
|
-
projectRoot,
|
|
839
|
-
platform
|
|
856
|
+
function removeOrphanedAvdDirectory(candidate, owner) {
|
|
857
|
+
const detached = withConfigLock(() => {
|
|
858
|
+
const current = listOrphanedAvdDirectories(candidate.name).find((entry) => entry.directory === candidate.directory);
|
|
859
|
+
if (!current || current.name !== candidate.name || current.dev !== candidate.dev || current.ino !== candidate.ino) throw new Error(`AVD data at ${candidate.directory} changed or is registered; it was kept.`);
|
|
860
|
+
const config = loadConfig();
|
|
861
|
+
if (!config) throw new Error("Cannot verify AVD references without a Stim config; the data was kept.");
|
|
862
|
+
for (const [projectPath, project] of Object.entries(config.projects)) for (const { platforms } of projectDeviceSlots(project)) {
|
|
863
|
+
if (platforms.android?.avdName !== candidate.name) continue;
|
|
864
|
+
if (!owner || !("projectPath" in owner) || owner.projectPath !== projectPath || !platforms.android.owned) throw new Error(`AVD ${candidate.name} is referenced by ${projectPath}; its data was kept.`);
|
|
865
|
+
}
|
|
866
|
+
if (readParked("android", { config }).some((entry) => entry.name === candidate.name) && !(owner && "pool" in owner)) throw new Error(`AVD ${candidate.name} is in the emulator pool; its data was kept.`);
|
|
867
|
+
assertOwnedAvdStopped(candidate.name, { resolveDirectory: () => candidate.directory });
|
|
868
|
+
const destination = join(dirname(candidate.directory), `stim-gc-${randomUUID()}.avd`);
|
|
869
|
+
renameSync(candidate.directory, destination);
|
|
870
|
+
return destination;
|
|
840
871
|
});
|
|
841
|
-
|
|
842
|
-
if (
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
872
|
+
const current = lstatSync(detached);
|
|
873
|
+
if (!current.isDirectory() || current.dev !== candidate.dev || current.ino !== candidate.ino) throw new Error(`Detached AVD data changed at ${detached}; it was kept.`);
|
|
874
|
+
try {
|
|
875
|
+
rmSync(detached, { recursive: true });
|
|
876
|
+
} catch (error) {
|
|
877
|
+
throw new Error(`Could not remove AVD data at ${detached}; retry gc --delete: ${error.message}`, { cause: error });
|
|
878
|
+
}
|
|
847
879
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
note(providerNote(`uploading to ${dest}`));
|
|
880
|
+
function teardownUnregisteredAvd(avdName, del, owner, surveyed) {
|
|
881
|
+
const candidates = surveyed ? [surveyed] : listOrphanedAvdDirectories(avdName);
|
|
882
|
+
if (candidates.length === 0) {
|
|
883
|
+
if (avdStorageRoots().some((root) => avdPathExists(join(root, `${avdName}.ini`)) || avdPathExists(join(root, `${avdName}.avd`)))) throw new Error(`AVD ${avdName} is not listed but its storage remains; it was kept.`);
|
|
884
|
+
return { status: "missing" };
|
|
885
|
+
}
|
|
886
|
+
if (!del) return {
|
|
887
|
+
status: "skipped",
|
|
888
|
+
reason: "AVD registration is missing; its data was kept."
|
|
858
889
|
};
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
platform,
|
|
863
|
-
fingerprintHash: await providerFingerprint({
|
|
864
|
-
provider,
|
|
865
|
-
platform,
|
|
866
|
-
projectRoot,
|
|
867
|
-
runOptions: opts
|
|
868
|
-
}) ?? fingerprintHash,
|
|
869
|
-
buildPath,
|
|
870
|
-
runOptions: opts
|
|
871
|
-
};
|
|
872
|
-
return typeof provider.plugin.uploadBuildCache === "function" ? provider.plugin.uploadBuildCache(props, provider.options) : provider.plugin.uploadRemoteBuildCache(props, provider.options);
|
|
873
|
-
}, timeoutMs, {
|
|
874
|
-
logWriter,
|
|
875
|
-
projectRoot,
|
|
876
|
-
platform,
|
|
877
|
-
onLine
|
|
878
|
-
});
|
|
879
|
-
if (outcome.timedOut) return { timedOut: true };
|
|
880
|
-
if (outcome.error) return { failed: firstLine(outcome.error) };
|
|
881
|
-
const destination = uploadDestination(outcome.lines);
|
|
882
|
-
return destination ? {
|
|
883
|
-
uploaded: true,
|
|
884
|
-
destination
|
|
885
|
-
} : { uploaded: true };
|
|
886
|
-
}
|
|
887
|
-
async function providerFingerprint({ provider, platform, projectRoot, runOptions }) {
|
|
888
|
-
if (typeof provider.plugin.calculateFingerprintHash !== "function") return null;
|
|
889
|
-
try {
|
|
890
|
-
const hash = await provider.plugin.calculateFingerprintHash({
|
|
891
|
-
projectRoot,
|
|
892
|
-
platform,
|
|
893
|
-
runOptions
|
|
894
|
-
}, provider.options);
|
|
895
|
-
return typeof hash === "string" && hash.trim() !== "" ? hash.trim() : null;
|
|
896
|
-
} catch {
|
|
897
|
-
return null;
|
|
890
|
+
for (const candidate of candidates) {
|
|
891
|
+
if (candidate.name !== avdName) throw new Error(`AVD data does not match ${avdName}; it was kept.`);
|
|
892
|
+
removeOrphanedAvdDirectory(candidate, owner);
|
|
898
893
|
}
|
|
894
|
+
return {
|
|
895
|
+
status: "torn-down",
|
|
896
|
+
label: avdName
|
|
897
|
+
};
|
|
899
898
|
}
|
|
900
|
-
|
|
901
|
-
let
|
|
902
|
-
const timeout = new Promise((resolve) => {
|
|
903
|
-
timer = setTimeout(() => resolve(TIMED_OUT), ms);
|
|
904
|
-
timer?.unref?.();
|
|
905
|
-
});
|
|
906
|
-
const frame = beginCapture(capture || {});
|
|
907
|
-
const work = Promise.resolve().then(() => PROVIDER_CONTEXT.run(frame, factory)).then((value) => ({ value }), (error) => ({ error }));
|
|
899
|
+
function teardownOwnedAvd(avdName, { del = false, park, owner, orphanedDirectory, waitForShutdown = waitForAndroidEmulatorShutdown, assertStopped = assertOwnedAvdStopped, resolveAvd = resolveOwnedAvdSerial } = {}) {
|
|
900
|
+
let parkFallback;
|
|
908
901
|
try {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
902
|
+
if (!/^stim-[A-Za-z0-9._-]+$/.test(avdName)) return {
|
|
903
|
+
status: "skipped",
|
|
904
|
+
kind: "not-owned",
|
|
905
|
+
reason: `AVD ${avdName} is not Stim-owned by name`
|
|
906
|
+
};
|
|
907
|
+
const resolved = resolveAvd(avdName);
|
|
908
|
+
if (resolved.notOwned) return {
|
|
909
|
+
status: "skipped",
|
|
910
|
+
kind: "not-owned",
|
|
911
|
+
reason: `AVD ${avdName} is not Stim-owned by name`
|
|
912
|
+
};
|
|
913
|
+
if (resolved.missing) return teardownUnregisteredAvd(avdName, del, owner, orphanedDirectory);
|
|
914
|
+
if (orphanedDirectory) return {
|
|
915
|
+
status: "skipped",
|
|
916
|
+
reason: "AVD registration appeared; its data was kept."
|
|
917
|
+
};
|
|
918
|
+
const serial = resolved.serial;
|
|
919
|
+
if (serial) waitForShutdown(avdName, (timeoutMs) => shutdownAndroidEmulator(serial, timeoutMs));
|
|
920
|
+
else assertStopped(avdName);
|
|
921
|
+
if (del) {
|
|
922
|
+
const current = resolveAvd(avdName);
|
|
923
|
+
if (current.notOwned) return {
|
|
924
|
+
status: "skipped",
|
|
925
|
+
kind: "not-owned",
|
|
926
|
+
reason: `AVD ${avdName} is not Stim-owned by name`
|
|
915
927
|
};
|
|
928
|
+
if (current.missing) return teardownUnregisteredAvd(avdName, del, owner);
|
|
929
|
+
if (current.serial) throw new Error(`Owned AVD ${avdName} started again before deletion.`);
|
|
930
|
+
assertStopped(avdName);
|
|
931
|
+
if (park && park.max > 0) try {
|
|
932
|
+
const systemImage = ownedAvdSystemImage(avdName);
|
|
933
|
+
if (!systemImage || !park.configuration || !ownedAvdMatchesConfiguration(avdName, park.configuration)) throw new Error("the AVD has no verified creation configuration");
|
|
934
|
+
const evicted = parkSim({
|
|
935
|
+
platform: "android",
|
|
936
|
+
projectPath: park.projectPath,
|
|
937
|
+
slot: park.slot,
|
|
938
|
+
max: park.max,
|
|
939
|
+
record: {
|
|
940
|
+
udid: avdName,
|
|
941
|
+
name: avdName,
|
|
942
|
+
systemImage,
|
|
943
|
+
configuration: park.configuration,
|
|
944
|
+
parkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
const removed = [];
|
|
948
|
+
const failures = [];
|
|
949
|
+
for (const entry of evicted) {
|
|
950
|
+
const result = teardownParkedAvd(entry.name);
|
|
951
|
+
if (result.status === "torn-down") removed.push({
|
|
952
|
+
udid: entry.name,
|
|
953
|
+
name: entry.name,
|
|
954
|
+
platform: "android"
|
|
955
|
+
});
|
|
956
|
+
else if (result.status === "failed") failures.push(`could not delete evicted ${entry.name}: ${result.reason}`);
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
status: "torn-down",
|
|
960
|
+
label: avdName,
|
|
961
|
+
parked: {
|
|
962
|
+
udid: avdName,
|
|
963
|
+
name: avdName,
|
|
964
|
+
platform: "android"
|
|
965
|
+
},
|
|
966
|
+
evicted: removed,
|
|
967
|
+
...failures.length ? { evictionFailures: failures } : {}
|
|
968
|
+
};
|
|
969
|
+
} catch (error) {
|
|
970
|
+
parkFallback = String(error?.message || error);
|
|
971
|
+
}
|
|
972
|
+
const directory = ownedAvdDirectory(avdName);
|
|
973
|
+
const paths = avdStorageRoots().map((root) => join(root, `${avdName}.ini`));
|
|
974
|
+
if (directory) paths.push(directory);
|
|
975
|
+
deleteAvd(avdName);
|
|
976
|
+
const remaining = paths.filter(avdPathExists);
|
|
977
|
+
if (remaining.length) throw new Error(`AVD ${avdName} was only partially deleted; data remains at ${remaining.join(", ")}.`);
|
|
916
978
|
}
|
|
917
|
-
endCapture(frame);
|
|
918
979
|
return {
|
|
919
|
-
|
|
920
|
-
|
|
980
|
+
status: "torn-down",
|
|
981
|
+
label: avdName,
|
|
982
|
+
serial: resolved.serial ?? null,
|
|
983
|
+
...parkFallback ? { parkFallback } : {}
|
|
984
|
+
};
|
|
985
|
+
} catch (e) {
|
|
986
|
+
return {
|
|
987
|
+
status: "failed",
|
|
988
|
+
reason: String(e?.message || e)
|
|
921
989
|
};
|
|
922
|
-
} catch (err) {
|
|
923
|
-
endCapture(frame);
|
|
924
|
-
throw err;
|
|
925
|
-
} finally {
|
|
926
|
-
if (timer) clearTimeout(timer);
|
|
927
990
|
}
|
|
928
991
|
}
|
|
929
|
-
function firstLine(err) {
|
|
930
|
-
const line = (String(err?.message || err || "unknown error").trim().split("\n")[0] ?? "").trim();
|
|
931
|
-
return line.length > 200 ? `${line.slice(0, 197)}...` : line;
|
|
932
|
-
}
|
|
933
992
|
//#endregion
|
|
934
|
-
export {
|
|
993
|
+
export { uploadRemote as C, resolveRemote as S, isEasAuthFailureText as _, POOL_SETTING_REMEDY as a, providerFromConfig as b, parkedMaxSetting as c, RESOLVE_TIMEOUT_MS as d, UPLOAD_TIMEOUT_MS as f, exitAfterFlush as g, easAuthNote as h, teardownParkedIosSim as i, readParked as l, checkEasAuth as m, teardownOwnedIosSim as n, adoptParked as o, cacheLevel as p, teardownParkedAvd as r, dropParked as s, teardownOwnedAvd as t, selectParked as u, loadProjectProvider as v, resolveEasCliBin as x, ownerFromConfig as y };
|