eas-cli 23.0.0 → 23.2.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.
Files changed (53) hide show
  1. package/README.md +174 -149
  2. package/build/api.d.ts +1 -0
  3. package/build/api.js +12 -0
  4. package/build/commandUtils/new/commands.d.ts +16 -1
  5. package/build/commandUtils/new/commands.js +59 -20
  6. package/build/commandUtils/new/projectFiles.d.ts +2 -1
  7. package/build/commandUtils/new/projectFiles.js +24 -1
  8. package/build/commandUtils/new/sdkVersion.d.ts +17 -0
  9. package/build/commandUtils/new/sdkVersion.js +138 -0
  10. package/build/commandUtils/workflow/logs/fetchLogs.d.ts +5 -0
  11. package/build/commandUtils/workflow/logs/fetchLogs.js +24 -0
  12. package/build/commandUtils/workflow/logs/parseLogs.d.ts +14 -0
  13. package/build/commandUtils/workflow/logs/parseLogs.js +69 -0
  14. package/build/commandUtils/workflow/logs/watcher.d.ts +32 -0
  15. package/build/commandUtils/workflow/logs/watcher.js +162 -0
  16. package/build/commandUtils/workflow/stateMachine.js +2 -1
  17. package/build/commandUtils/workflow/types.d.ts +12 -5
  18. package/build/commandUtils/workflow/utils.d.ts +9 -5
  19. package/build/commandUtils/workflow/utils.js +144 -146
  20. package/build/commands/project/new.d.ts +1 -0
  21. package/build/commands/project/new.js +13 -2
  22. package/build/commands/simulator/get.js +2 -0
  23. package/build/commands/simulator/index.d.ts +1 -0
  24. package/build/commands/simulator/index.js +10 -0
  25. package/build/commands/simulator/list.d.ts +1 -0
  26. package/build/commands/simulator/list.js +9 -0
  27. package/build/commands/workflow/run.d.ts +8 -0
  28. package/build/commands/workflow/run.js +27 -0
  29. package/build/commands/workflow/ssh.d.ts +31 -0
  30. package/build/commands/workflow/ssh.js +190 -0
  31. package/build/graphql/generated.d.ts +243 -3
  32. package/build/graphql/generated.js +28 -4
  33. package/build/graphql/mutations/RealtimeLogsMutation.d.ts +6 -0
  34. package/build/graphql/mutations/RealtimeLogsMutation.js +40 -0
  35. package/build/graphql/mutations/WorkflowRunMutation.d.ts +3 -2
  36. package/build/graphql/mutations/WorkflowRunMutation.js +4 -1
  37. package/build/graphql/queries/DeviceRunSessionQuery.js +5 -0
  38. package/build/graphql/queries/WorkflowJobSshQuery.d.ts +20 -0
  39. package/build/graphql/queries/WorkflowJobSshQuery.js +133 -0
  40. package/build/ora.d.ts +7 -0
  41. package/build/ora.js +12 -0
  42. package/build/simulator/utils.js +9 -1
  43. package/build/utils/centrifuge.d.ts +10 -0
  44. package/build/utils/centrifuge.js +89 -0
  45. package/build/utils/expodash/uniqBy.js +3 -2
  46. package/build/worker/upload.d.ts +14 -1
  47. package/build/worker/upload.js +81 -17
  48. package/oclif.manifest.json +397 -287
  49. package/package.json +12 -10
  50. package/build/commandUtils/workflow/fetchLogs.d.ts +0 -6
  51. package/build/commandUtils/workflow/fetchLogs.js +0 -44
  52. package/build/onboarding/git.d.ts +0 -16
  53. package/build/onboarding/git.js +0 -88
@@ -57,6 +57,7 @@ class SimulatorGet extends EasCommand_1.default {
57
57
  (0, json_1.printJsonOnlyOutput)({
58
58
  id: session.id,
59
59
  name: session.name ?? undefined,
60
+ tags: session.tags,
60
61
  type: (0, utils_1.deviceRunSessionTypeToFlagValue)(session.type),
61
62
  status: session.status,
62
63
  platform: session.platform,
@@ -89,6 +90,7 @@ function formatSessionFields(session, deviceRunSessionUrl) {
89
90
  return (0, formatFields_1.default)([
90
91
  { label: 'ID', value: session.id },
91
92
  { label: 'Name', value: formatNullable(session.name) },
93
+ { label: 'Tags', value: session.tags.length > 0 ? session.tags.join(', ') : 'none' },
92
94
  { label: 'Type', value: session.type },
93
95
  { label: 'Status', value: session.status },
94
96
  { label: 'Platform', value: session.platform },
@@ -8,6 +8,7 @@ export default class Simulator extends EasCommand {
8
8
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
9
  platform: import("@oclif/core/lib/interfaces").OptionFlag<"android" | "ios" | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
+ tag: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
12
  device: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
12
13
  'build-id': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
14
  'application-archive-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -43,6 +43,10 @@ class Simulator extends EasCommand_1.default {
43
43
  name: core_1.Flags.string({
44
44
  description: 'Human-readable name for the simulator session, shown in eas simulator:list and on expo.dev. Defaults to unnamed.',
45
45
  }),
46
+ tag: core_1.Flags.string({
47
+ description: 'Label used to group simulator sessions, for example one per app variant. Repeat for multiple tags. Stored lowercased.',
48
+ multiple: true,
49
+ }),
46
50
  device: core_1.Flags.string({
47
51
  description: 'Virtual device to start for the session. On iOS, a Simulator device name or UDID (e.g. "iPhone 16 Pro"). On Android, an AVD hardware profile id (e.g. "pixel_7"). Defaults to a device chosen by the runner.',
48
52
  }),
@@ -127,6 +131,7 @@ class Simulator extends EasCommand_1.default {
127
131
  // The server rejects blank names, so trim here and treat a whitespace-only
128
132
  // --name as if it had been omitted rather than surfacing a validation error.
129
133
  const name = flags.name?.trim() || undefined;
134
+ const tags = flags.tag?.map(tag => tag.trim()).filter(tag => tag.length > 0);
130
135
  const deviceIdentifier = flags.device?.trim() || undefined;
131
136
  const buildId = flags['build-id']?.trim() || undefined;
132
137
  const applicationArchiveUrlFromFlag = flags['application-archive-url']?.trim() || undefined;
@@ -151,6 +156,10 @@ class Simulator extends EasCommand_1.default {
151
156
  throw new Error(`Existing simulator session in environment. Use --force to create a new simulator session.`);
152
157
  }
153
158
  const platform = await resolvePlatformAsync(flags.platform, nonInteractive);
159
+ if (platform === generated_1.AppPlatform.Android) {
160
+ log_1.default.warn('Android emulator support in EAS Simulator is still in development. Some features available on iOS may not work on Android yet. Full parity with iOS is coming soon.');
161
+ log_1.default.newLine();
162
+ }
154
163
  const expoGoSdkVersion = flags['expo-go']
155
164
  ? await (0, expoGo_1.resolveExpoGoSdkVersionAsync)({ projectDir, sdkVersion: sdkVersionFromFlag })
156
165
  : undefined;
@@ -168,6 +177,7 @@ class Simulator extends EasCommand_1.default {
168
177
  const session = await DeviceRunSessionMutation_1.DeviceRunSessionMutation.createDeviceRunSessionAsync(graphqlClient, {
169
178
  appId: projectId,
170
179
  name,
180
+ ...(tags?.length ? { tags } : {}),
171
181
  platform,
172
182
  type: utils_1.DEVICE_RUN_SESSION_TYPE_BY_FLAG_VALUE[flags.type],
173
183
  packageVersion: flags['package-version'],
@@ -10,6 +10,7 @@ export default class SimulatorList extends EasCommand {
10
10
  type: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
11
  platform: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
12
12
  name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
+ tag: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
14
  limit: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined>;
14
15
  after: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
16
  };
@@ -54,6 +54,10 @@ class SimulatorList extends EasCommand_1.default {
54
54
  name: core_1.Flags.string({
55
55
  description: 'Filter by session name (case-insensitive prefix match)',
56
56
  }),
57
+ tag: core_1.Flags.string({
58
+ description: 'Filter by tag (repeatable). A session must carry every tag listed.',
59
+ multiple: true,
60
+ }),
57
61
  limit: (0, pagination_1.getLimitFlagWithCustomValues)({ defaultTo: DEFAULT_LIMIT, limit: MAX_LIMIT }),
58
62
  after: core_1.Flags.string({
59
63
  description: 'Cursor for pagination. Use the endCursor from a previous query to fetch the next page.',
@@ -86,6 +90,9 @@ class SimulatorList extends EasCommand_1.default {
86
90
  if (flags.name) {
87
91
  filter.name = flags.name;
88
92
  }
93
+ if (flags.tag && flags.tag.length > 0) {
94
+ filter.tags = flags.tag;
95
+ }
89
96
  const limit = flags.limit ?? DEFAULT_LIMIT;
90
97
  const fetchSpinner = jsonFlag ? null : (0, ora_1.ora)('Fetching simulator sessions').start();
91
98
  let connection;
@@ -108,6 +115,7 @@ class SimulatorList extends EasCommand_1.default {
108
115
  sessions: sessions.map(session => ({
109
116
  id: session.id,
110
117
  name: session.name ?? undefined,
118
+ tags: session.tags,
111
119
  type: (0, utils_1.deviceRunSessionTypeToFlagValue)(session.type),
112
120
  status: session.status,
113
121
  platform: session.platform,
@@ -131,6 +139,7 @@ class SimulatorList extends EasCommand_1.default {
131
139
  const lines = [
132
140
  `ID: ${session.id}`,
133
141
  `Name: ${session.name ?? 'null'}`,
142
+ `Tags: ${session.tags.length > 0 ? session.tags.join(', ') : 'none'}`,
134
143
  `Type: ${session.type}`,
135
144
  `Status: ${session.status}`,
136
145
  `Platform: ${session.platform}`,
@@ -40,6 +40,12 @@
40
40
  * ```
41
41
  */
42
42
  import EasCommand from '../../commandUtils/EasCommand';
43
+ export declare function resolveWorkflowRunSshInput({ ssh, idleTimeoutSeconds, }: {
44
+ ssh: boolean;
45
+ idleTimeoutSeconds: number | undefined;
46
+ }): {
47
+ idleTimeoutSeconds: number | undefined;
48
+ } | null;
43
49
  export default class WorkflowRun extends EasCommand {
44
50
  static description: string;
45
51
  static args: {
@@ -50,6 +56,8 @@ export default class WorkflowRun extends EasCommand {
50
56
  wait: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
51
57
  input: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
52
58
  ref: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
59
+ ssh: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
60
+ 'ssh-idle-timeout': import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
53
61
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
54
62
  };
55
63
  static contextDefinition: {
@@ -41,6 +41,7 @@
41
41
  * ```
42
42
  */
43
43
  Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.resolveWorkflowRunSshInput = resolveWorkflowRunSshInput;
44
45
  const tslib_1 = require("tslib");
45
46
  const spawn_async_1 = tslib_1.__importDefault(require("@expo/spawn-async"));
46
47
  const core_1 = require("@oclif/core");
@@ -64,6 +65,12 @@ const uploadAccountScopedFileAsync_1 = require("../../project/uploadAccountScope
64
65
  const uploadAccountScopedProjectSourceAsync_1 = require("../../project/uploadAccountScopedProjectSourceAsync");
65
66
  const json_1 = require("../../utils/json");
66
67
  const workflowFile_1 = require("../../utils/workflowFile");
68
+ function resolveWorkflowRunSshInput({ ssh, idleTimeoutSeconds, }) {
69
+ if (idleTimeoutSeconds !== undefined && !ssh) {
70
+ throw new Error('--ssh-idle-timeout requires --ssh.');
71
+ }
72
+ return ssh ? { idleTimeoutSeconds } : null;
73
+ }
67
74
  class WorkflowRun extends EasCommand_1.default {
68
75
  static description = 'run an EAS workflow. The entire local project directory will be packaged and uploaded to EAS servers for the workflow run, unless the --ref flag is used.';
69
76
  static args = {
@@ -91,6 +98,17 @@ class WorkflowRun extends EasCommand_1.default {
91
98
  description: "The git reference must exist in the project's git repository, and the workflow file must exist at that reference. When this flag is used, the local project is not uploaded; instead, the workflow is run from the exact state of the project at the chosen reference.",
92
99
  summary: 'Git reference to run the workflow on',
93
100
  }),
101
+ ssh: core_1.Flags.boolean({
102
+ default: false,
103
+ description: 'Open an SSH session on each VM job for live debugging with `eas workflow:ssh`.',
104
+ summary: '[EXPERIMENTAL] Enable SSH on the run',
105
+ }),
106
+ 'ssh-idle-timeout': core_1.Flags.integer({
107
+ description: 'Seconds to keep an SSH session open after its job finishes, while no client is connected. The session is always available for the whole job. Requires --ssh. Must be between 0 and 3600; defaults to 0 (close as soon as the job finishes and nobody is connected).',
108
+ summary: '[EXPERIMENTAL] SSH idle timeout in seconds',
109
+ min: 0,
110
+ max: 3600,
111
+ }),
94
112
  ...flags_1.EasJsonOnlyFlag,
95
113
  };
96
114
  static contextDefinition = {
@@ -104,6 +122,10 @@ class WorkflowRun extends EasCommand_1.default {
104
122
  if (flags.json) {
105
123
  (0, json_1.enableJsonOutput)();
106
124
  }
125
+ const sshInput = resolveWorkflowRunSshInput({
126
+ ssh: flags.ssh,
127
+ idleTimeoutSeconds: flags['ssh-idle-timeout'],
128
+ });
107
129
  const { getDynamicPrivateProjectConfigAsync, loggedIn: { graphqlClient }, vcsClient, projectDir, } = await this.getContextAsync(WorkflowRun, {
108
130
  nonInteractive: flags['non-interactive'],
109
131
  withServerSideEnvironment: null,
@@ -216,6 +238,7 @@ class WorkflowRun extends EasCommand_1.default {
216
238
  workflowRevisionId: workflowRevisionId ?? '',
217
239
  gitRef,
218
240
  inputs,
241
+ ssh: sshInput,
219
242
  });
220
243
  }
221
244
  catch (err) {
@@ -274,6 +297,7 @@ class WorkflowRun extends EasCommand_1.default {
274
297
  packageJsonBucketKey,
275
298
  projectRootDirectory,
276
299
  },
300
+ ssh: sshInput,
277
301
  },
278
302
  }));
279
303
  }
@@ -284,6 +308,9 @@ class WorkflowRun extends EasCommand_1.default {
284
308
  }
285
309
  log_1.default.newLine();
286
310
  log_1.default.log(`See logs: ${(0, log_1.link)((0, url_1.getWorkflowRunUrl)(account.name, projectName, workflowRunId))}`);
311
+ if (sshInput) {
312
+ log_1.default.log('SSH enabled. Each VM job logs the `eas workflow:ssh` command to connect.');
313
+ }
287
314
  if (!flags.wait) {
288
315
  if (flags.json) {
289
316
  (0, json_1.printJsonOnlyOutput)({
@@ -0,0 +1,31 @@
1
+ import EasCommand from '../../commandUtils/EasCommand';
2
+ import { WorkflowJobSshConnectInfo, WorkflowJobSshSession } from '../../graphql/queries/WorkflowJobSshQuery';
3
+ export declare function splitConnectionHost(connectionHost: string): {
4
+ hostname: string;
5
+ port?: number;
6
+ };
7
+ export type SshConnectStatus = 'unknown' | 'not-enabled' | 'ended' | 'pending' | 'ready';
8
+ export declare function resolveSshConnectStatus(connectInfo: (Pick<WorkflowJobSshConnectInfo, 'sshRequested' | 'jobCompleted'> & {
9
+ session?: Pick<WorkflowJobSshSession, 'connectionConfig'> | null;
10
+ }) | null): SshConnectStatus;
11
+ export declare function terminalSshStatusMessage(status: SshConnectStatus, resourceId: string): string | null;
12
+ export declare function sshHostAliasForResource(resourceId: string): string;
13
+ export declare function parseSshArgv(rawArgv: readonly string[]): {
14
+ showConnect: boolean;
15
+ resourceId: string | undefined;
16
+ command: string[];
17
+ };
18
+ export default class WorkflowSsh extends EasCommand {
19
+ static hidden: boolean;
20
+ static description: string;
21
+ static strict: boolean;
22
+ static flags: {
23
+ 'show-connect': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
24
+ };
25
+ static contextDefinition: {
26
+ loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
27
+ };
28
+ private isRunningSubprocess;
29
+ runAsync(): Promise<void>;
30
+ protected catch(err: Error): Promise<void>;
31
+ }
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitConnectionHost = splitConnectionHost;
4
+ exports.resolveSshConnectStatus = resolveSshConnectStatus;
5
+ exports.terminalSshStatusMessage = terminalSshStatusMessage;
6
+ exports.sshHostAliasForResource = sshHostAliasForResource;
7
+ exports.parseSshArgv = parseSshArgv;
8
+ const tslib_1 = require("tslib");
9
+ const spawn_async_1 = tslib_1.__importDefault(require("@expo/spawn-async"));
10
+ const core_1 = require("@oclif/core");
11
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
12
+ const node_os_1 = tslib_1.__importDefault(require("node:os"));
13
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
14
+ const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
15
+ const WorkflowJobSshQuery_1 = require("../../graphql/queries/WorkflowJobSshQuery");
16
+ const log_1 = tslib_1.__importDefault(require("../../log"));
17
+ const ora_1 = require("../../ora");
18
+ const promise_1 = require("../../utils/promise");
19
+ function splitConnectionHost(connectionHost) {
20
+ try {
21
+ const { hostname, port: stringPort } = new URL(`ssh://${connectionHost}`);
22
+ const port = stringPort === '' ? undefined : Number(stringPort);
23
+ return { hostname, port };
24
+ }
25
+ catch (err) {
26
+ throw new Error('Unexpected connection host reported for this ssh session. Update eas-cli and try again, or contact support if it persists.', { cause: err });
27
+ }
28
+ }
29
+ const SSH_INSECURE_OPTS = '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null';
30
+ const SESSION_OPEN_TIMEOUT_MS = 5 * 60 * 1000;
31
+ const SESSION_OPEN_POLL_INTERVAL_MS = 3000;
32
+ function resolveSshConnectStatus(connectInfo) {
33
+ if (!connectInfo) {
34
+ return 'unknown';
35
+ }
36
+ const { sshRequested, jobCompleted, session } = connectInfo;
37
+ if (session?.connectionConfig && !session.connectionConfig.reconnecting) {
38
+ return 'ready';
39
+ }
40
+ if (session?.connectionConfig?.reconnecting) {
41
+ return 'pending';
42
+ }
43
+ if (!sshRequested) {
44
+ return 'not-enabled';
45
+ }
46
+ return jobCompleted ? 'ended' : 'pending';
47
+ }
48
+ function terminalSshStatusMessage(status, resourceId) {
49
+ switch (status) {
50
+ case 'unknown':
51
+ return `No workflow job found for "${resourceId}". Pass a workflow job id from a run started with \`eas workflow:run --ssh\`.`;
52
+ case 'not-enabled':
53
+ return `SSH was not enabled for "${resourceId}". Start the run with \`eas workflow:run --ssh\` to enable it.`;
54
+ case 'ended':
55
+ return 'This ssh session has ended.';
56
+ case 'pending':
57
+ case 'ready':
58
+ return null;
59
+ }
60
+ }
61
+ function sshHostAliasForResource(resourceId) {
62
+ const suffix = resourceId.replace(/[^A-Za-z0-9]/g, '').slice(0, 8);
63
+ return suffix ? `eas-workflow-ssh-${suffix}` : 'eas-workflow-ssh';
64
+ }
65
+ function parseSshArgv(rawArgv) {
66
+ let showConnect = false;
67
+ let index = 0;
68
+ while (index < rawArgv.length && rawArgv[index].startsWith('-')) {
69
+ if (rawArgv[index] === '--show-connect' || rawArgv[index] === '--show-connect=true') {
70
+ showConnect = true;
71
+ }
72
+ else {
73
+ throw new Error(`Unknown flag "${rawArgv[index]}" before the id. The only supported flag is --show-connect; everything after the id is passed to the remote shell.`);
74
+ }
75
+ index += 1;
76
+ }
77
+ const [resourceId, ...command] = rawArgv.slice(index);
78
+ return { showConnect, resourceId, command };
79
+ }
80
+ class WorkflowSsh extends EasCommand_1.default {
81
+ static hidden = true;
82
+ static description = '[EXPERIMENTAL] open an ssh session on the worker running a workflow job';
83
+ static strict = false;
84
+ static flags = {
85
+ 'show-connect': core_1.Flags.boolean({
86
+ description: 'Print the ssh connection command (host and token) instead of opening a session',
87
+ default: false,
88
+ }),
89
+ };
90
+ static contextDefinition = {
91
+ ...this.ContextOptions.LoggedIn,
92
+ };
93
+ isRunningSubprocess = false;
94
+ async runAsync() {
95
+ const rawArgv = [...this.argv];
96
+ await this.parse(WorkflowSsh, []);
97
+ const { showConnect, resourceId, command } = parseSshArgv(rawArgv);
98
+ if (typeof resourceId !== 'string' || resourceId.length === 0) {
99
+ throw new Error('Provide a workflow job id: eas workflow:ssh <workflow-job-id> [command...]');
100
+ }
101
+ const { loggedIn: { graphqlClient }, } = await this.getContextAsync(WorkflowSsh, { nonInteractive: true });
102
+ const connectInfo = await WorkflowJobSshQuery_1.WorkflowJobSshQuery.connectInfoForResourceIdAsync(graphqlClient, resourceId);
103
+ const status = resolveSshConnectStatus(connectInfo);
104
+ const statusMessage = terminalSshStatusMessage(status, resourceId);
105
+ if (statusMessage) {
106
+ log_1.default.error(statusMessage);
107
+ process.exitCode = 1;
108
+ return;
109
+ }
110
+ const connectionConfig = (status === 'ready' ? connectInfo?.session?.connectionConfig : null) ??
111
+ (await waitForSessionToOpenAsync(graphqlClient, resourceId));
112
+ if (!connectionConfig) {
113
+ process.exitCode = 1;
114
+ return;
115
+ }
116
+ const { host: connectionHost, secret } = connectionConfig;
117
+ const { hostname, port } = splitConnectionHost(connectionHost);
118
+ const portOption = port !== undefined ? ` -p ${port}` : '';
119
+ if (showConnect) {
120
+ log_1.default.log(`ssh ${SSH_INSECURE_OPTS}${portOption} ${secret}@${hostname}`);
121
+ log_1.default.newLine();
122
+ log_1.default.log('If your network blocks the direct SSH connection, reach the session through the WebSocket relay with upterm (https://upterm.dev):');
123
+ // WSS terminates on the relay hostname (default 443). Do not paste an SSH
124
+ // :port into the wss:// URL — that port is only for the ssh destination.
125
+ log_1.default.log(` ssh -o ProxyCommand="upterm proxy wss://${secret}@${hostname}" ${SSH_INSECURE_OPTS}${portOption} ${secret}@${hostname}`);
126
+ return;
127
+ }
128
+ const configDir = await node_fs_1.default.promises.mkdtemp(node_path_1.default.join(node_os_1.default.tmpdir(), 'eas-workflow-ssh-'));
129
+ try {
130
+ const configPath = node_path_1.default.join(configDir, 'config');
131
+ const hostAlias = sshHostAliasForResource(resourceId);
132
+ await node_fs_1.default.promises.writeFile(configPath, [
133
+ `Host ${hostAlias}`,
134
+ ` HostName ${hostname}`,
135
+ ...(port !== undefined ? [` Port ${port}`] : []),
136
+ ` User ${secret}`,
137
+ ' StrictHostKeyChecking no',
138
+ ' UserKnownHostsFile /dev/null',
139
+ '',
140
+ ].join('\n'), { mode: 0o600 });
141
+ this.isRunningSubprocess = true;
142
+ await (0, spawn_async_1.default)('ssh', ['-F', configPath, hostAlias, ...command], {
143
+ stdio: 'inherit',
144
+ });
145
+ }
146
+ finally {
147
+ await node_fs_1.default.promises.rm(configDir, { recursive: true, force: true });
148
+ }
149
+ }
150
+ catch(err) {
151
+ if (this.isRunningSubprocess) {
152
+ if (err.code === 'ENOENT') {
153
+ log_1.default.error('Could not run `ssh`. Install an OpenSSH client and make sure `ssh` is on your PATH, then try again.');
154
+ process.exitCode = 1;
155
+ return Promise.resolve();
156
+ }
157
+ const status = err.status;
158
+ process.exitCode = process.exitCode ?? status ?? 1;
159
+ return Promise.resolve();
160
+ }
161
+ return super.catch(err);
162
+ }
163
+ }
164
+ exports.default = WorkflowSsh;
165
+ async function waitForSessionToOpenAsync(graphqlClient, workflowJobId) {
166
+ const spinner = (0, ora_1.ora)('Waiting for the worker to open the ssh session').start();
167
+ const deadline = Date.now() + SESSION_OPEN_TIMEOUT_MS;
168
+ try {
169
+ while (Date.now() < deadline) {
170
+ const connectInfo = await WorkflowJobSshQuery_1.WorkflowJobSshQuery.connectInfoForResourceIdAsync(graphqlClient, workflowJobId);
171
+ const status = resolveSshConnectStatus(connectInfo);
172
+ const statusMessage = terminalSshStatusMessage(status, workflowJobId);
173
+ if (statusMessage) {
174
+ spinner.fail(statusMessage);
175
+ return null;
176
+ }
177
+ if (status === 'ready') {
178
+ spinner.succeed('The ssh session is ready.');
179
+ return connectInfo?.session?.connectionConfig ?? null;
180
+ }
181
+ await (0, promise_1.sleepAsync)(SESSION_OPEN_POLL_INTERVAL_MS);
182
+ }
183
+ spinner.fail('Timed out waiting for the ssh session to open. The worker may still be starting up; try again in a moment.');
184
+ return null;
185
+ }
186
+ catch (err) {
187
+ spinner.stop();
188
+ throw err;
189
+ }
190
+ }