eas-cli 27.4.1 → 27.6.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 +373 -200
- package/build/build/simulatorsLaunchHint.js +1 -1
- package/build/commands/observe/events.d.ts +2 -0
- package/build/commands/observe/events.js +42 -4
- package/build/commands/simulator/availability.d.ts +1 -0
- package/build/commands/simulator/availability.js +3 -1
- package/build/commands/simulator/control/connection.d.ts +19 -0
- package/build/commands/simulator/control/connection.js +93 -0
- package/build/commands/simulator/control.d.ts +7 -0
- package/build/commands/simulator/control.js +249 -110
- package/build/commands/simulator/egress.d.ts +1 -0
- package/build/commands/simulator/egress.js +3 -1
- package/build/commands/simulator/events.d.ts +1 -0
- package/build/commands/simulator/events.js +3 -1
- package/build/commands/simulator/exec.d.ts +1 -0
- package/build/commands/simulator/exec.js +3 -1
- package/build/commands/simulator/get.d.ts +1 -0
- package/build/commands/simulator/get.js +3 -1
- package/build/commands/simulator/index.d.ts +2 -0
- package/build/commands/simulator/index.js +286 -76
- package/build/commands/simulator/list.d.ts +1 -0
- package/build/commands/simulator/list.js +3 -1
- package/build/commands/simulator/logs.d.ts +1 -0
- package/build/commands/simulator/logs.js +3 -1
- package/build/commands/simulator/stop.d.ts +1 -0
- package/build/commands/simulator/stop.js +3 -1
- package/build/commands/workflow/ssh.d.ts +0 -1
- package/build/commands/workflow/ssh.js +0 -1
- package/build/graphql/generated.d.ts +8 -0
- package/build/graphql/types/Actor.js +3 -0
- package/build/help.js +2 -1
- package/build/observe/fetchCustomEvents.d.ts +2 -1
- package/build/observe/fetchCustomEvents.js +1 -0
- package/build/project/accountSelection.js +5 -8
- package/build/simulator/commandAliases.d.ts +10 -0
- package/build/simulator/commandAliases.js +24 -0
- package/build/simulator/controlActions.d.ts +32 -0
- package/build/simulator/controlActions.js +128 -0
- package/build/simulator/controlConfig.d.ts +43 -0
- package/build/simulator/controlConfig.js +156 -0
- package/build/simulator/controlConnection.d.ts +28 -0
- package/build/simulator/controlConnection.js +337 -0
- package/build/simulator/controlConnectionProtocol.d.ts +64 -0
- package/build/simulator/controlConnectionProtocol.js +155 -0
- package/build/simulator/controlConnectionWorker.d.ts +7 -0
- package/build/simulator/controlConnectionWorker.js +278 -0
- package/build/simulator/controlSession.d.ts +3 -0
- package/build/simulator/controlSession.js +28 -0
- package/build/simulator/hostActions.d.ts +22 -3
- package/build/simulator/hostActions.js +78 -19
- package/build/simulator/sessionConfig.d.ts +16 -0
- package/build/simulator/sessionConfig.js +36 -0
- package/build/simulator/startConfig.d.ts +7 -0
- package/build/simulator/startConfig.js +89 -0
- package/build/simulator/startSetup.d.ts +7 -0
- package/build/simulator/startSetup.js +17 -0
- package/build/user/User.d.ts +9 -1
- package/build/user/User.js +25 -3
- package/build/user/accountPermissions.js +3 -1
- package/oclif.manifest.json +1194 -996
- package/package.json +8 -6
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serveControlConnectionAsync = serveControlConnectionAsync;
|
|
4
|
+
const node_net_1 = require("node:net");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const controlConnection_1 = require("./controlConnection");
|
|
7
|
+
const controlConnectionProtocol_1 = require("./controlConnectionProtocol");
|
|
8
|
+
const hostActions_1 = require("./hostActions");
|
|
9
|
+
const Request = zod_1.z.strictObject({
|
|
10
|
+
id: zod_1.z.number().int().positive(),
|
|
11
|
+
action: zod_1.z.string().min(1).max(200),
|
|
12
|
+
params: zod_1.z.record(zod_1.z.string(), zod_1.z.json()),
|
|
13
|
+
});
|
|
14
|
+
async function serveControlConnectionAsync(identity, session, remote, catalog, initialIdleTimeoutMs = controlConnectionProtocol_1.DEFAULT_CONTROL_IDLE_TIMEOUT_MS) {
|
|
15
|
+
await (0, controlConnection_1.ensureControlConnectionDirectoryAsync)(identity.root);
|
|
16
|
+
let idleTimeoutMs = initialIdleTimeoutMs;
|
|
17
|
+
let idleDeadline = null;
|
|
18
|
+
let timer;
|
|
19
|
+
let authTimer;
|
|
20
|
+
let closePromise;
|
|
21
|
+
let closeStarted;
|
|
22
|
+
let leaseTail = Promise.resolve();
|
|
23
|
+
let leases = 0;
|
|
24
|
+
let active;
|
|
25
|
+
const channels = new Set();
|
|
26
|
+
const info = () => ({
|
|
27
|
+
version: controlConnectionProtocol_1.CONTROL_CONNECTION_VERSION,
|
|
28
|
+
pid: process.pid,
|
|
29
|
+
session,
|
|
30
|
+
idleTimeoutMs,
|
|
31
|
+
idleDeadline,
|
|
32
|
+
busy: Boolean(active),
|
|
33
|
+
});
|
|
34
|
+
const resetIdle = () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
idleDeadline = null;
|
|
37
|
+
if (leases || closePromise) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
idleDeadline = Date.now() + idleTimeoutMs;
|
|
41
|
+
timer = setTimeout(() => {
|
|
42
|
+
void closeAsync();
|
|
43
|
+
}, idleTimeoutMs);
|
|
44
|
+
};
|
|
45
|
+
async function closeAsync(requester) {
|
|
46
|
+
if (!closePromise) {
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
for (const channel of channels) {
|
|
49
|
+
if (channel !== active) {
|
|
50
|
+
channel.destroy();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let acknowledge;
|
|
54
|
+
closeStarted = new Promise(resolve => {
|
|
55
|
+
acknowledge = resolve;
|
|
56
|
+
});
|
|
57
|
+
closePromise = (async () => {
|
|
58
|
+
clearInterval(authTimer);
|
|
59
|
+
await (0, controlConnection_1.withControlConnectionLockAsync)(identity, async () => {
|
|
60
|
+
acknowledge();
|
|
61
|
+
await leaseTail;
|
|
62
|
+
await new Promise((resolve, reject) => server.close(error => {
|
|
63
|
+
error ? reject(error) : resolve();
|
|
64
|
+
}));
|
|
65
|
+
remote.close();
|
|
66
|
+
});
|
|
67
|
+
remote.signal.removeEventListener('abort', onRemoteClosed);
|
|
68
|
+
})().catch(() => process.exit(1));
|
|
69
|
+
}
|
|
70
|
+
if (requester) {
|
|
71
|
+
// Every close acknowledges under ownership, including repeated close calls.
|
|
72
|
+
await closeStarted;
|
|
73
|
+
await requester.writeAsync(info()).catch(() => { });
|
|
74
|
+
requester.socket.destroySoon();
|
|
75
|
+
}
|
|
76
|
+
await closePromise;
|
|
77
|
+
}
|
|
78
|
+
async function handleAsync(channel) {
|
|
79
|
+
const operation = controlConnectionProtocol_1.ConnectionOperationSchema.parse(await channel.readAsync());
|
|
80
|
+
await (0, controlConnection_1.assertControlConnectionCredentialAsync)(identity);
|
|
81
|
+
if (channel.socket.destroyed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (closePromise && operation.operation !== 'close') {
|
|
85
|
+
throw new Error('The control connection is closing; no action was sent. Try again after it closes.');
|
|
86
|
+
}
|
|
87
|
+
if (operation.idleTimeoutMs !== undefined) {
|
|
88
|
+
idleTimeoutMs = operation.idleTimeoutMs;
|
|
89
|
+
resetIdle();
|
|
90
|
+
}
|
|
91
|
+
if (operation.operation !== 'lease') {
|
|
92
|
+
if (operation.operation === 'close') {
|
|
93
|
+
// Keep this caller alive until shutdown acknowledges its request.
|
|
94
|
+
channels.delete(channel);
|
|
95
|
+
await closeAsync(channel);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
await channel.writeAsync(info());
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (leases >= 16) {
|
|
103
|
+
throw new Error('The control connection is busy; no action was sent. Try again after the current command finishes.');
|
|
104
|
+
}
|
|
105
|
+
const previous = leaseTail;
|
|
106
|
+
let release;
|
|
107
|
+
leaseTail = new Promise(resolve => {
|
|
108
|
+
release = resolve;
|
|
109
|
+
});
|
|
110
|
+
leases++;
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
idleDeadline = null;
|
|
113
|
+
let cleanupTimer;
|
|
114
|
+
const limitCleanup = () => {
|
|
115
|
+
if (closePromise && !cleanupTimer) {
|
|
116
|
+
cleanupTimer = setTimeout(() => {
|
|
117
|
+
channel.destroy();
|
|
118
|
+
}, controlConnectionProtocol_1.CONTROL_SETUP_TIMEOUT_MS);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
await previous;
|
|
123
|
+
if (closePromise || channel.socket.destroyed) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
active = channel;
|
|
127
|
+
await channel.writeAsync({ info: info(), catalog });
|
|
128
|
+
for (;;) {
|
|
129
|
+
const request = Request.parse(await channel.readAsync(30_000));
|
|
130
|
+
await (0, controlConnection_1.assertControlConnectionCredentialAsync)(identity);
|
|
131
|
+
if (channel.socket.destroyed) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
limitCleanup();
|
|
135
|
+
if (closePromise && request.action !== 'upload.remove') {
|
|
136
|
+
await channel.writeAsync({
|
|
137
|
+
id: request.id,
|
|
138
|
+
error: 'The control connection is closing; no action was sent.',
|
|
139
|
+
});
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
let result;
|
|
143
|
+
try {
|
|
144
|
+
result = await remote.requestAsync(request.action, request.params);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
remote.signal.throwIfAborted();
|
|
148
|
+
await channel.writeAsync({
|
|
149
|
+
id: request.id,
|
|
150
|
+
error: error instanceof Error ? error.message : 'Simulator action failed.',
|
|
151
|
+
});
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
limitCleanup();
|
|
156
|
+
}
|
|
157
|
+
await channel.writeAsync({ id: request.id, ...result });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
clearTimeout(cleanupTimer);
|
|
162
|
+
if (active === channel) {
|
|
163
|
+
active = undefined;
|
|
164
|
+
}
|
|
165
|
+
leases--;
|
|
166
|
+
release();
|
|
167
|
+
resetIdle();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const server = (0, node_net_1.createServer)(socket => {
|
|
171
|
+
const channel = new controlConnectionProtocol_1.ControlConnectionChannel(socket);
|
|
172
|
+
channels.add(channel);
|
|
173
|
+
socket.once('close', () => channels.delete(channel));
|
|
174
|
+
void handleAsync(channel)
|
|
175
|
+
.catch(async (error) => {
|
|
176
|
+
if (!socket.destroyed) {
|
|
177
|
+
await channel
|
|
178
|
+
.writeAsync({
|
|
179
|
+
error: error instanceof Error ? error.message : 'Local control request failed.',
|
|
180
|
+
})
|
|
181
|
+
.catch(() => { });
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
.finally(() => {
|
|
185
|
+
socket.destroySoon();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
server.maxConnections = 32;
|
|
189
|
+
await new Promise((resolve, reject) => {
|
|
190
|
+
server.once('error', reject);
|
|
191
|
+
server.listen(identity.socketPath, () => {
|
|
192
|
+
server.removeListener('error', reject);
|
|
193
|
+
resolve();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
const onRemoteClosed = () => {
|
|
197
|
+
for (const channel of channels) {
|
|
198
|
+
channel.destroy();
|
|
199
|
+
}
|
|
200
|
+
void closeAsync();
|
|
201
|
+
};
|
|
202
|
+
authTimer = setInterval(() => {
|
|
203
|
+
void (0, controlConnection_1.assertControlConnectionCredentialAsync)(identity).catch(onRemoteClosed);
|
|
204
|
+
}, 1_000);
|
|
205
|
+
authTimer.unref();
|
|
206
|
+
remote.signal.addEventListener('abort', onRemoteClosed, { once: true });
|
|
207
|
+
if (remote.signal.aborted) {
|
|
208
|
+
onRemoteClosed();
|
|
209
|
+
}
|
|
210
|
+
resetIdle();
|
|
211
|
+
return { closeAsync, info: info() };
|
|
212
|
+
}
|
|
213
|
+
async function runWorkerAsync() {
|
|
214
|
+
if (!process.send) {
|
|
215
|
+
throw new Error('Control helpers must be started by EAS CLI.');
|
|
216
|
+
}
|
|
217
|
+
process.umask(0o077);
|
|
218
|
+
// Until readiness is handed back, parent loss cancels all bootstrap work.
|
|
219
|
+
const onParentGone = () => process.exit(1);
|
|
220
|
+
process.once('disconnect', onParentGone);
|
|
221
|
+
const input = await new Promise((resolve, reject) => {
|
|
222
|
+
const timer = setTimeout(() => {
|
|
223
|
+
reject(new Error('Control bootstrap timed out.'));
|
|
224
|
+
}, 10_000);
|
|
225
|
+
process.once('message', message => {
|
|
226
|
+
clearTimeout(timer);
|
|
227
|
+
resolve(message);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
const parsed = zod_1.z
|
|
231
|
+
.object({
|
|
232
|
+
identity: zod_1.z.object({
|
|
233
|
+
root: zod_1.z.string(),
|
|
234
|
+
socketPath: zod_1.z.string(),
|
|
235
|
+
credentialHash: zod_1.z.string().regex(/^[a-f0-9]{64}$/),
|
|
236
|
+
scope: zod_1.z.string(),
|
|
237
|
+
sessionStatePath: zod_1.z.string().optional(),
|
|
238
|
+
}),
|
|
239
|
+
bootstrap: zod_1.z.object({
|
|
240
|
+
access: zod_1.z.object({ apiUrl: zod_1.z.string(), token: zod_1.z.string() }),
|
|
241
|
+
session: controlConnectionProtocol_1.ControlSessionSchema.omit({ device: true }),
|
|
242
|
+
}),
|
|
243
|
+
idleTimeoutMs: controlConnectionProtocol_1.ConnectionOperationSchema.shape.idleTimeoutMs,
|
|
244
|
+
})
|
|
245
|
+
.parse(input);
|
|
246
|
+
const { identity, bootstrap } = parsed;
|
|
247
|
+
const remote = await (0, hostActions_1.connectHostActionsAsync)(bootstrap.access);
|
|
248
|
+
try {
|
|
249
|
+
const catalog = await (0, hostActions_1.fetchHostActionCatalogAsync)(remote);
|
|
250
|
+
const device = await (0, hostActions_1.fetchHostActionDeviceAsync)(bootstrap.access, remote.udid);
|
|
251
|
+
const server = await serveControlConnectionAsync(identity, { ...bootstrap.session, device }, remote, catalog, parsed.idleTimeoutMs);
|
|
252
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
253
|
+
process.once(signal, () => {
|
|
254
|
+
void server.closeAsync();
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
process.removeListener('disconnect', onParentGone);
|
|
258
|
+
await new Promise((resolve, reject) => {
|
|
259
|
+
process.send({ ready: true, info: server.info }, (error) => {
|
|
260
|
+
error ? reject(error) : resolve();
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
remote.close();
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (require.main === module) {
|
|
270
|
+
void runWorkerAsync().catch(error => {
|
|
271
|
+
if (process.connected && process.send) {
|
|
272
|
+
process.send({ error: error instanceof Error ? error.message : 'Local control setup failed.' }, () => process.exit(1));
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ControlConnectionBootstrap } from './controlConnection';
|
|
2
|
+
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
|
|
3
|
+
export declare function loadControlSessionAsync(graphqlClient: ExpoGraphqlClient, sessionId: string): Promise<ControlConnectionBootstrap>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadControlSessionAsync = loadControlSessionAsync;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const generated_1 = require("../graphql/generated");
|
|
6
|
+
const DeviceRunSessionQuery_1 = require("../graphql/queries/DeviceRunSessionQuery");
|
|
7
|
+
async function loadControlSessionAsync(graphqlClient, sessionId) {
|
|
8
|
+
const session = await DeviceRunSessionQuery_1.DeviceRunSessionQuery.byIdAsync(graphqlClient, sessionId);
|
|
9
|
+
if (session.status !== generated_1.DeviceRunSessionStatus.InProgress) {
|
|
10
|
+
throw new Error(`Simulator session ${session.id} is ${session.status.toLowerCase()}. Simulator actions need a running session. Start one with \`eas simulator:start\`.`);
|
|
11
|
+
}
|
|
12
|
+
if (session.platform !== generated_1.AppPlatform.Ios) {
|
|
13
|
+
throw new Error(`Simulator control on ${session.platform.toLowerCase()} is not supported yet. Simulator actions are available only for iOS sessions.`);
|
|
14
|
+
}
|
|
15
|
+
const access = session.remoteConfig ? (0, utils_1.getPreviewApiAccess)(session.remoteConfig) : null;
|
|
16
|
+
if (!access) {
|
|
17
|
+
throw new Error(`Simulator session ${session.id} does not expose a preview server with a token. Simulator actions use that server. Start a new session with \`eas simulator:start\`.`);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
access,
|
|
21
|
+
session: {
|
|
22
|
+
id: session.id,
|
|
23
|
+
name: session.name ?? null,
|
|
24
|
+
project: `@${session.app.ownerAccount.name}/${session.app.slug}`,
|
|
25
|
+
status: session.status,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -6,6 +6,8 @@ export type HostActionResult = {
|
|
|
6
6
|
exitCode: number;
|
|
7
7
|
};
|
|
8
8
|
export type HostActionConnection = {
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
readonly udid: string;
|
|
9
11
|
requestAsync(action: string, params?: Record<string, unknown>): Promise<HostActionResult>;
|
|
10
12
|
close(): void;
|
|
11
13
|
};
|
|
@@ -30,7 +32,7 @@ declare const CatalogEntry: z.ZodObject<{
|
|
|
30
32
|
base64: "base64";
|
|
31
33
|
}>>;
|
|
32
34
|
}, z.core.$loose>;
|
|
33
|
-
declare const
|
|
35
|
+
export declare const HostActionCatalogSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
34
36
|
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
35
37
|
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
36
38
|
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -51,15 +53,32 @@ declare const Catalog: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
|
51
53
|
base64: "base64";
|
|
52
54
|
}>>;
|
|
53
55
|
}, z.core.$loose>>;
|
|
54
|
-
export type HostActionCatalog = z.infer<typeof
|
|
56
|
+
export type HostActionCatalog = z.infer<typeof HostActionCatalogSchema>;
|
|
55
57
|
export type HostActionCatalogEntry = z.infer<typeof CatalogEntry>;
|
|
56
|
-
export
|
|
58
|
+
export type HostActionDevice = {
|
|
59
|
+
udid: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
runtime?: string;
|
|
62
|
+
};
|
|
63
|
+
export declare const HostActionReplySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
64
|
+
id: z.ZodNumber;
|
|
65
|
+
error: z.ZodString;
|
|
66
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
67
|
+
id: z.ZodNumber;
|
|
68
|
+
stdout: z.ZodString;
|
|
69
|
+
stderr: z.ZodString;
|
|
70
|
+
exitCode: z.ZodNumber;
|
|
71
|
+
}, z.core.$strip>]>;
|
|
72
|
+
export declare function fetchHostActionDeviceAsync({ apiUrl, token }: PreviewApiAccess, udid: string): Promise<HostActionDevice>;
|
|
73
|
+
export declare function connectHostActionsAsync(access: PreviewApiAccess, { timeoutMs, signal }?: {
|
|
57
74
|
timeoutMs?: number;
|
|
75
|
+
signal?: AbortSignal;
|
|
58
76
|
}): Promise<HostActionConnection>;
|
|
59
77
|
export declare function fetchHostActionCatalogAsync(connection: HostActionConnection): Promise<HostActionCatalog>;
|
|
60
78
|
export declare function formatHostActionUsage(name: string, entry: HostActionCatalogEntry): string;
|
|
61
79
|
export declare function buildHostActionParams(name: string, entry: HostActionCatalogEntry, values: string[]): Record<string, unknown>;
|
|
62
80
|
export declare function assertHostActionOutputAsync(name: string, entry: HostActionCatalogEntry, outputPath: string | undefined): Promise<void>;
|
|
81
|
+
export declare function createHostActionUploadId(localPath: string): string;
|
|
63
82
|
export declare function uploadFileAsync(connection: HostActionConnection, localPath: string, { chunkBytes }?: {
|
|
64
83
|
chunkBytes?: number;
|
|
65
84
|
}): Promise<{
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HostActionReplySchema = exports.HostActionCatalogSchema = void 0;
|
|
4
|
+
exports.fetchHostActionDeviceAsync = fetchHostActionDeviceAsync;
|
|
3
5
|
exports.connectHostActionsAsync = connectHostActionsAsync;
|
|
4
6
|
exports.fetchHostActionCatalogAsync = fetchHostActionCatalogAsync;
|
|
5
7
|
exports.formatHostActionUsage = formatHostActionUsage;
|
|
6
8
|
exports.buildHostActionParams = buildHostActionParams;
|
|
7
9
|
exports.assertHostActionOutputAsync = assertHostActionOutputAsync;
|
|
10
|
+
exports.createHostActionUploadId = createHostActionUploadId;
|
|
8
11
|
exports.uploadFileAsync = uploadFileAsync;
|
|
9
12
|
exports.saveHostActionOutputAsync = saveHostActionOutputAsync;
|
|
10
13
|
const tslib_1 = require("tslib");
|
|
@@ -31,11 +34,10 @@ const CatalogEntry = SchemaNode.extend({
|
|
|
31
34
|
keepUpload: zod_1.z.boolean().optional(),
|
|
32
35
|
output: zod_1.z.enum(['path', 'base64']).optional(),
|
|
33
36
|
});
|
|
34
|
-
|
|
37
|
+
exports.HostActionCatalogSchema = zod_1.z.record(zod_1.z.string(), CatalogEntry);
|
|
35
38
|
const PreviewConfig = zod_1.z.object({ device: zod_1.z.string().min(1) });
|
|
36
39
|
const ReplyId = zod_1.z.object({ id: zod_1.z.number() });
|
|
37
|
-
|
|
38
|
-
zod_1.z.object({ ready: zod_1.z.literal(true) }),
|
|
40
|
+
exports.HostActionReplySchema = zod_1.z.union([
|
|
39
41
|
zod_1.z.object({ id: zod_1.z.number(), error: zod_1.z.string() }),
|
|
40
42
|
zod_1.z.object({
|
|
41
43
|
id: zod_1.z.number(),
|
|
@@ -44,8 +46,10 @@ const SocketMessage = zod_1.z.union([
|
|
|
44
46
|
exitCode: zod_1.z.number(),
|
|
45
47
|
}),
|
|
46
48
|
]);
|
|
49
|
+
const SocketMessage = zod_1.z.union([zod_1.z.object({ ready: zod_1.z.literal(true) }), exports.HostActionReplySchema]);
|
|
47
50
|
const HOST_ACTION_TIMEOUT_MS = 130_000;
|
|
48
51
|
const PREVIEW_API_TIMEOUT_MS = 30_000;
|
|
52
|
+
const PREVIEW_UNAVAILABLE_MESSAGE = 'The simulator preview server is unavailable. The session may have ended or expired. Check it with `eas simulator:get`, or start a new session with `eas simulator:start`.';
|
|
49
53
|
const UPLOAD_CHUNK_BYTES = 2 * 1024 * 1024;
|
|
50
54
|
const NAMED_VALUE = /^([A-Za-z][A-Za-z0-9]*)=(.*)$/s;
|
|
51
55
|
const NUMBER = /^-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;
|
|
@@ -64,17 +68,23 @@ function previewEndpoint(apiUrl, endpoint) {
|
|
|
64
68
|
}
|
|
65
69
|
return new URL(endpoint, base);
|
|
66
70
|
}
|
|
67
|
-
async function fetchSimulatorUdidAsync({ apiUrl, token }) {
|
|
71
|
+
async function fetchSimulatorUdidAsync({ apiUrl, token }, signal) {
|
|
68
72
|
let text;
|
|
69
73
|
try {
|
|
70
74
|
const response = await (0, fetch_1.default)(previewEndpoint(apiUrl, 'api').toString(), {
|
|
71
75
|
headers: { Authorization: `Bearer ${token}` },
|
|
72
76
|
redirect: 'error',
|
|
73
|
-
signal:
|
|
77
|
+
signal: signal
|
|
78
|
+
? AbortSignal.any([signal, AbortSignal.timeout(PREVIEW_API_TIMEOUT_MS)])
|
|
79
|
+
: AbortSignal.timeout(PREVIEW_API_TIMEOUT_MS),
|
|
74
80
|
});
|
|
75
81
|
text = await response.text();
|
|
76
82
|
}
|
|
77
83
|
catch (error) {
|
|
84
|
+
signal?.throwIfAborted();
|
|
85
|
+
if (error instanceof fetch_1.RequestError && error.response.status === 404) {
|
|
86
|
+
throw new Error(PREVIEW_UNAVAILABLE_MESSAGE);
|
|
87
|
+
}
|
|
78
88
|
if (error instanceof fetch_1.RequestError && [401, 403].includes(error.response.status)) {
|
|
79
89
|
throw new Error(`The simulator preview server refused the session token (HTTP ${error.response.status}). Run \`eas simulator:get\` to check that the session still runs, then try again.`);
|
|
80
90
|
}
|
|
@@ -94,17 +104,40 @@ async function fetchSimulatorUdidAsync({ apiUrl, token }) {
|
|
|
94
104
|
}
|
|
95
105
|
return config.data.device;
|
|
96
106
|
}
|
|
107
|
+
async function fetchHostActionDeviceAsync({ apiUrl, token }, udid) {
|
|
108
|
+
const url = previewEndpoint(apiUrl, 'grid/api/catalog').toString();
|
|
109
|
+
try {
|
|
110
|
+
const response = await (0, fetch_1.default)(url, {
|
|
111
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
112
|
+
redirect: 'error',
|
|
113
|
+
signal: AbortSignal.timeout(PREVIEW_API_TIMEOUT_MS),
|
|
114
|
+
});
|
|
115
|
+
const catalog = zod_1.z
|
|
116
|
+
.object({
|
|
117
|
+
devices: zod_1.z.array(zod_1.z.object({ device: zod_1.z.string(), name: zod_1.z.string(), runtime: zod_1.z.string().optional() })),
|
|
118
|
+
})
|
|
119
|
+
.parse(await response.json());
|
|
120
|
+
const device = catalog.devices.find(device => device.device === udid);
|
|
121
|
+
return device ? { udid, name: device.name, runtime: device.runtime } : { udid };
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return { udid };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
97
127
|
function refusedError(error) {
|
|
98
128
|
return error.startsWith('unknown action')
|
|
99
129
|
? new Error('This simulator session runs a serve-sim version that does not support this action. Start a new session with `eas simulator:start` to get a newer version.')
|
|
100
130
|
: new Error(`The simulator refused the request: ${error}`);
|
|
101
131
|
}
|
|
102
|
-
async function connectHostActionsAsync(access, { timeoutMs = HOST_ACTION_TIMEOUT_MS } = {}) {
|
|
103
|
-
|
|
132
|
+
async function connectHostActionsAsync(access, { timeoutMs = HOST_ACTION_TIMEOUT_MS, signal } = {}) {
|
|
133
|
+
signal?.throwIfAborted();
|
|
134
|
+
const udid = await fetchSimulatorUdidAsync(access, signal);
|
|
135
|
+
signal?.throwIfAborted();
|
|
104
136
|
const socketUrl = previewEndpoint(access.apiUrl, 'exec-ws');
|
|
105
137
|
socketUrl.protocol = socketUrl.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
106
138
|
const ws = new ws_1.default(socketUrl.toString(), [`serve-sim.token.${access.token}`], fetch_1.httpsProxyAgent ? { agent: fetch_1.httpsProxyAgent } : {});
|
|
107
139
|
const pending = new Map();
|
|
140
|
+
const controller = new AbortController();
|
|
108
141
|
let nextId = 1;
|
|
109
142
|
let lost = null;
|
|
110
143
|
let ready = false;
|
|
@@ -117,24 +150,30 @@ async function connectHostActionsAsync(access, { timeoutMs = HOST_ACTION_TIMEOUT
|
|
|
117
150
|
return request;
|
|
118
151
|
}
|
|
119
152
|
function loseConnection(error) {
|
|
120
|
-
lost
|
|
153
|
+
if (lost) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
lost = error;
|
|
157
|
+
controller.abort(error);
|
|
121
158
|
for (const id of [...pending.keys()]) {
|
|
122
159
|
settle(id)?.reject(error);
|
|
123
160
|
}
|
|
161
|
+
ws.terminate();
|
|
124
162
|
}
|
|
125
163
|
await new Promise((resolve, reject) => {
|
|
126
164
|
const timer = setTimeout(() => {
|
|
127
|
-
|
|
128
|
-
ws.terminate();
|
|
165
|
+
fail(new Error(`The simulator preview server did not accept the connection within ${PREVIEW_API_TIMEOUT_MS / 1000} seconds. Check that the session still runs with \`eas simulator:get\`, then try again.`));
|
|
129
166
|
}, PREVIEW_API_TIMEOUT_MS);
|
|
130
167
|
const fail = (error) => {
|
|
131
168
|
clearTimeout(timer);
|
|
132
169
|
reject(error);
|
|
133
170
|
loseConnection(error);
|
|
134
|
-
if (!ready) {
|
|
135
|
-
ws.terminate();
|
|
136
|
-
}
|
|
137
171
|
};
|
|
172
|
+
const onAbort = () => {
|
|
173
|
+
fail(signal?.reason instanceof Error ? signal.reason : new Error('Simulator setup canceled.'));
|
|
174
|
+
};
|
|
175
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
176
|
+
ws.once('close', () => signal?.removeEventListener('abort', onAbort));
|
|
138
177
|
ws.on('message', data => {
|
|
139
178
|
let message;
|
|
140
179
|
try {
|
|
@@ -170,7 +209,9 @@ async function connectHostActionsAsync(access, { timeoutMs = HOST_ACTION_TIMEOUT
|
|
|
170
209
|
});
|
|
171
210
|
ws.on('unexpected-response', (_req, res) => {
|
|
172
211
|
res.destroy();
|
|
173
|
-
fail(new Error(
|
|
212
|
+
fail(new Error(res.statusCode === 404
|
|
213
|
+
? PREVIEW_UNAVAILABLE_MESSAGE
|
|
214
|
+
: `The simulator preview server refused the connection (HTTP ${res.statusCode}). The session token may be out of date. Run \`eas simulator:get\` to check the session, then try again.`));
|
|
174
215
|
});
|
|
175
216
|
ws.on('error', error => {
|
|
176
217
|
fail(new Error(`Could not connect to the simulator preview server: ${error.message}. Check your network connection and that the session still runs.`));
|
|
@@ -180,23 +221,38 @@ async function connectHostActionsAsync(access, { timeoutMs = HOST_ACTION_TIMEOUT
|
|
|
180
221
|
? 'The simulator preview server closed the connection before it answered. The action may still have run. Check the current state before you try again.'
|
|
181
222
|
: 'The simulator preview server closed the connection during setup. The session token may be invalid or expired, or the session may run an older serve-sim version. Check the session with `eas simulator:get` before starting a new session.'));
|
|
182
223
|
});
|
|
224
|
+
if (signal?.aborted) {
|
|
225
|
+
onAbort();
|
|
226
|
+
}
|
|
183
227
|
});
|
|
184
228
|
return {
|
|
229
|
+
signal: controller.signal,
|
|
230
|
+
udid,
|
|
185
231
|
async requestAsync(action, params = {}) {
|
|
186
232
|
if (lost) {
|
|
187
233
|
throw lost;
|
|
188
234
|
}
|
|
189
235
|
const id = nextId++;
|
|
236
|
+
const message = JSON.stringify({ id, action, params: { ...params, udid } });
|
|
190
237
|
return await new Promise((resolve, reject) => {
|
|
191
238
|
const timer = setTimeout(() => {
|
|
192
|
-
|
|
239
|
+
loseConnection(new Error(`The simulator did not answer within ${Math.round(timeoutMs / 1000)} seconds. The action may still have run. Check the session with \`eas simulator:get\` and the current state before you try again.`));
|
|
193
240
|
}, timeoutMs);
|
|
194
241
|
pending.set(id, { resolve, reject, timer });
|
|
195
|
-
|
|
242
|
+
try {
|
|
243
|
+
ws.send(message, error => {
|
|
244
|
+
if (error) {
|
|
245
|
+
loseConnection(error);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
loseConnection(error instanceof Error ? error : new Error(String(error)));
|
|
251
|
+
}
|
|
196
252
|
});
|
|
197
253
|
},
|
|
198
254
|
close() {
|
|
199
|
-
|
|
255
|
+
loseConnection(new Error('The simulator action connection was closed.'));
|
|
200
256
|
},
|
|
201
257
|
};
|
|
202
258
|
}
|
|
@@ -207,7 +263,7 @@ async function fetchHostActionCatalogAsync(connection) {
|
|
|
207
263
|
body = JSON.parse(result.stdout);
|
|
208
264
|
}
|
|
209
265
|
catch { }
|
|
210
|
-
const catalog =
|
|
266
|
+
const catalog = exports.HostActionCatalogSchema.safeParse(body);
|
|
211
267
|
if (result.exitCode !== 0 || !catalog.success) {
|
|
212
268
|
throw new Error('The simulator did not return its list of actions. Start a new session with `eas simulator:start` to get a newer serve-sim version.');
|
|
213
269
|
}
|
|
@@ -346,8 +402,11 @@ async function assertHostActionOutputAsync(name, entry, outputPath) {
|
|
|
346
402
|
throw new Error(`The folder for ${outputPath} does not exist. Create it, or pass --output with a path in a folder that exists.`);
|
|
347
403
|
}
|
|
348
404
|
}
|
|
405
|
+
function createHostActionUploadId(localPath) {
|
|
406
|
+
return `eas-cli-${(0, crypto_1.randomUUID)()}${path_1.default.extname(localPath).replace(/[^A-Za-z0-9.]/g, '')}`;
|
|
407
|
+
}
|
|
349
408
|
async function uploadFileAsync(connection, localPath, { chunkBytes = UPLOAD_CHUNK_BYTES } = {}) {
|
|
350
|
-
const uploadId =
|
|
409
|
+
const uploadId = createHostActionUploadId(localPath);
|
|
351
410
|
let remotePath = '';
|
|
352
411
|
let first = true;
|
|
353
412
|
try {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const Config: z.ZodObject<{
|
|
3
|
+
version: z.ZodLiteral<1>;
|
|
4
|
+
start: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
5
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
6
|
+
action: z.ZodString;
|
|
7
|
+
params: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
8
|
+
file: z.ZodOptional<z.ZodString>;
|
|
9
|
+
output: z.ZodOptional<z.ZodString>;
|
|
10
|
+
}, z.core.$strict>>>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type SimulatorSessionConfig = z.infer<typeof Config> & {
|
|
13
|
+
path: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function readSimulatorSessionConfigAsync(filePath: string): Promise<SimulatorSessionConfig>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readSimulatorSessionConfigAsync = readSimulatorSessionConfigAsync;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const Action = zod_1.z.strictObject({
|
|
9
|
+
action: zod_1.z.string().min(1),
|
|
10
|
+
params: zod_1.z.record(zod_1.z.string(), zod_1.z.json()).default({}),
|
|
11
|
+
file: zod_1.z.string().min(1).optional(),
|
|
12
|
+
output: zod_1.z.string().min(1).optional(),
|
|
13
|
+
});
|
|
14
|
+
const Config = zod_1.z.strictObject({
|
|
15
|
+
version: zod_1.z.literal(1),
|
|
16
|
+
start: zod_1.z.record(zod_1.z.string(), zod_1.z.json()).optional(),
|
|
17
|
+
actions: zod_1.z.array(Action).min(1).optional(),
|
|
18
|
+
});
|
|
19
|
+
async function readSimulatorSessionConfigAsync(filePath) {
|
|
20
|
+
const absolutePath = path_1.default.resolve(filePath);
|
|
21
|
+
let input;
|
|
22
|
+
try {
|
|
23
|
+
input = await fs.readJson(absolutePath);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new Error(`Could not read simulator configuration ${absolutePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
27
|
+
}
|
|
28
|
+
const parsed = Config.safeParse(input);
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
const detail = parsed.error.issues
|
|
31
|
+
.map(issue => `${issue.path.join('.')}: ${issue.message}`)
|
|
32
|
+
.join('; ');
|
|
33
|
+
throw new Error(`Invalid simulator configuration ${absolutePath}: ${detail}`);
|
|
34
|
+
}
|
|
35
|
+
return { ...parsed.data, path: absolutePath };
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Interfaces } from '@oclif/core';
|
|
2
|
+
import { SimulatorSessionConfig } from './sessionConfig';
|
|
3
|
+
/** Reparse the effective values using the command's own validation, options and defaults. */
|
|
4
|
+
export declare function resolveStartConfigAsync(argv: string[], definitions: Interfaces.FlagInput): Promise<{
|
|
5
|
+
argv: string[];
|
|
6
|
+
config?: SimulatorSessionConfig;
|
|
7
|
+
}>;
|