eas-cli 27.4.1 → 27.5.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 (57) hide show
  1. package/README.md +369 -198
  2. package/build/build/simulatorsLaunchHint.js +1 -1
  3. package/build/commands/simulator/availability.d.ts +1 -0
  4. package/build/commands/simulator/availability.js +3 -1
  5. package/build/commands/simulator/control/connection.d.ts +19 -0
  6. package/build/commands/simulator/control/connection.js +93 -0
  7. package/build/commands/simulator/control.d.ts +7 -0
  8. package/build/commands/simulator/control.js +249 -110
  9. package/build/commands/simulator/egress.d.ts +1 -0
  10. package/build/commands/simulator/egress.js +3 -1
  11. package/build/commands/simulator/events.d.ts +1 -0
  12. package/build/commands/simulator/events.js +3 -1
  13. package/build/commands/simulator/exec.d.ts +1 -0
  14. package/build/commands/simulator/exec.js +3 -1
  15. package/build/commands/simulator/get.d.ts +1 -0
  16. package/build/commands/simulator/get.js +3 -1
  17. package/build/commands/simulator/index.d.ts +2 -0
  18. package/build/commands/simulator/index.js +286 -76
  19. package/build/commands/simulator/list.d.ts +1 -0
  20. package/build/commands/simulator/list.js +3 -1
  21. package/build/commands/simulator/logs.d.ts +1 -0
  22. package/build/commands/simulator/logs.js +3 -1
  23. package/build/commands/simulator/stop.d.ts +1 -0
  24. package/build/commands/simulator/stop.js +3 -1
  25. package/build/commands/workflow/ssh.d.ts +0 -1
  26. package/build/commands/workflow/ssh.js +0 -1
  27. package/build/graphql/generated.d.ts +8 -0
  28. package/build/graphql/types/Actor.js +3 -0
  29. package/build/help.js +2 -1
  30. package/build/project/accountSelection.js +5 -8
  31. package/build/simulator/commandAliases.d.ts +10 -0
  32. package/build/simulator/commandAliases.js +24 -0
  33. package/build/simulator/controlActions.d.ts +32 -0
  34. package/build/simulator/controlActions.js +128 -0
  35. package/build/simulator/controlConfig.d.ts +43 -0
  36. package/build/simulator/controlConfig.js +156 -0
  37. package/build/simulator/controlConnection.d.ts +28 -0
  38. package/build/simulator/controlConnection.js +337 -0
  39. package/build/simulator/controlConnectionProtocol.d.ts +64 -0
  40. package/build/simulator/controlConnectionProtocol.js +155 -0
  41. package/build/simulator/controlConnectionWorker.d.ts +7 -0
  42. package/build/simulator/controlConnectionWorker.js +278 -0
  43. package/build/simulator/controlSession.d.ts +3 -0
  44. package/build/simulator/controlSession.js +28 -0
  45. package/build/simulator/hostActions.d.ts +22 -3
  46. package/build/simulator/hostActions.js +78 -19
  47. package/build/simulator/sessionConfig.d.ts +16 -0
  48. package/build/simulator/sessionConfig.js +36 -0
  49. package/build/simulator/startConfig.d.ts +7 -0
  50. package/build/simulator/startConfig.js +89 -0
  51. package/build/simulator/startSetup.d.ts +7 -0
  52. package/build/simulator/startSetup.js +17 -0
  53. package/build/user/User.d.ts +9 -1
  54. package/build/user/User.js +25 -3
  55. package/build/user/accountPermissions.js +3 -1
  56. package/oclif.manifest.json +1403 -1212
  57. package/package.json +8 -6
@@ -8,7 +8,7 @@ const createGraphqlClient_1 = require("../commandUtils/context/contextUtils/crea
8
8
  const UserPreferenceMutation_1 = require("../graphql/mutations/UserPreferenceMutation");
9
9
  const UserPreferenceQuery_1 = require("../graphql/queries/UserPreferenceQuery");
10
10
  const log_1 = tslib_1.__importStar(require("../log"));
11
- const SIMULATORS_LAUNCH_AT = new Date('2026-11-10T18:00:00Z');
11
+ const SIMULATORS_LAUNCH_AT = new Date('2026-11-12T18:00:00Z');
12
12
  const SIMULATORS_LAUNCH_HINT_PREFERENCE_KEY = 'simulators-launch-cli-hint-seen';
13
13
  const REQUEST_TIMEOUT_MS = 3000;
14
14
  const SIMULATORS_QUICKSTART_URL = 'https://docs.expo.dev/preview/simulators/get-started/?utm_source=eas-cli&utm_medium=cli&utm_campaign=simulators-launch';
@@ -1,6 +1,7 @@
1
1
  import EasCommand from '../../commandUtils/EasCommand';
2
2
  export default class SimulatorAvailability extends EasCommand {
3
3
  static aliases: string[];
4
+ static hiddenAliases: string[];
4
5
  static description: string;
5
6
  static flags: {
6
7
  json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -8,8 +8,10 @@ const log_1 = tslib_1.__importDefault(require("../../log"));
8
8
  const ora_1 = require("../../ora");
9
9
  const utils_1 = require("../../simulator/utils");
10
10
  const json_1 = require("../../utils/json");
11
+ const commandAliases_1 = require("../../simulator/commandAliases");
11
12
  class SimulatorAvailability extends EasCommand_1.default {
12
- static aliases = ['sim:availability'];
13
+ static aliases = (0, commandAliases_1.getSimulatorCommandAliases)('availability');
14
+ static hiddenAliases = (0, commandAliases_1.getSimulatorCommandHiddenAliases)('availability');
13
15
  static description = '[EXPERIMENTAL] check whether EAS Simulator is enabled for the current project account';
14
16
  static flags = {
15
17
  ...flags_1.EasNonInteractiveAndJsonFlags,
@@ -0,0 +1,19 @@
1
+ import EasCommand from '../../../commandUtils/EasCommand';
2
+ export default class SimulatorControlConnection extends EasCommand {
3
+ static description: string;
4
+ static args: {
5
+ operation: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
6
+ };
7
+ static flags: {
8
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
+ 'idle-timeout': import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
12
+ };
13
+ static examples: string[];
14
+ static contextDefinition: {
15
+ projectDir: import("../../../commandUtils/context/ProjectDirContextField").default;
16
+ loggedIn: import("../../../commandUtils/context/LoggedInContextField").default;
17
+ };
18
+ runAsync(): Promise<void>;
19
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const EasCommand_1 = tslib_1.__importDefault(require("../../../commandUtils/EasCommand"));
6
+ const flags_1 = require("../../../commandUtils/flags");
7
+ const log_1 = tslib_1.__importDefault(require("../../../log"));
8
+ const controlConnection_1 = require("../../../simulator/controlConnection");
9
+ const controlSession_1 = require("../../../simulator/controlSession");
10
+ const env_1 = require("../../../simulator/env");
11
+ const json_1 = require("../../../utils/json");
12
+ const terminalText_1 = require("../../../utils/terminalText");
13
+ const timer_1 = require("../../../utils/timer");
14
+ class SimulatorControlConnection extends EasCommand_1.default {
15
+ static description = 'optionally keep a simulator control connection available between commands';
16
+ static args = {
17
+ operation: core_1.Args.string({
18
+ required: true,
19
+ options: ['open', 'status', 'close'],
20
+ description: 'Open, inspect or close the local control connection',
21
+ }),
22
+ };
23
+ static flags = {
24
+ id: core_1.Flags.string({
25
+ description: `Simulator session ID. Defaults to ${env_1.SIMULATOR_DOTENV_FILE_NAME}.`,
26
+ }),
27
+ 'idle-timeout': core_1.Flags.integer({
28
+ min: 1,
29
+ max: 86_400,
30
+ description: 'Seconds of idle time before closing the control connection (default: 120)',
31
+ }),
32
+ ...flags_1.EasNonInteractiveAndJsonFlags,
33
+ };
34
+ static examples = [
35
+ '$ eas simulator:control:connection open --idle-timeout 300',
36
+ '$ eas simulator:control:connection status --id <session-id> --json',
37
+ '$ eas simulator:control:connection close',
38
+ ];
39
+ static contextDefinition = {
40
+ ...this.ContextOptions.LoggedIn,
41
+ ...this.ContextOptions.ProjectDir,
42
+ };
43
+ async runAsync() {
44
+ const { args, flags } = await this.parse(SimulatorControlConnection);
45
+ const { json, nonInteractive } = (0, flags_1.resolveNonInteractiveAndJsonFlags)(flags);
46
+ if (json) {
47
+ (0, json_1.enableJsonOutput)();
48
+ }
49
+ if (flags.id === '') {
50
+ throw new Error('--id needs a simulator session ID.');
51
+ }
52
+ if (flags['idle-timeout'] !== undefined && args.operation !== 'open') {
53
+ throw new Error('--idle-timeout applies only to connection open.');
54
+ }
55
+ const idleTimeoutMs = flags['idle-timeout'] !== undefined ? flags['idle-timeout'] * 1_000 : undefined;
56
+ (0, controlConnection_1.assertControlKeepAliveSupported)();
57
+ const { projectDir, loggedIn: { graphqlClient, authenticationInfo }, } = await this.getContextAsync(SimulatorControlConnection, { nonInteractive });
58
+ await (0, env_1.loadSimulatorEnvAsync)(projectDir);
59
+ const sessionId = flags.id ?? process.env[env_1.EAS_SIMULATOR_SESSION_ID];
60
+ if (!sessionId) {
61
+ throw new Error('No simulator session ID provided. Pass --id, or run eas simulator:start first.');
62
+ }
63
+ const identity = await (0, controlConnection_1.createControlConnectionIdentityAsync)(sessionId, projectDir, authenticationInfo);
64
+ const info = args.operation === 'open'
65
+ ? await (0, controlConnection_1.openControlConnectionAsync)(identity, () => (0, controlSession_1.loadControlSessionAsync)(graphqlClient, sessionId), idleTimeoutMs)
66
+ : await (0, controlConnection_1.inspectControlConnectionAsync)(identity, {
67
+ operation: args.operation === 'close' ? 'close' : 'status',
68
+ });
69
+ if (json) {
70
+ (0, json_1.printJsonOnlyOutput)({
71
+ connected: Boolean(info) && args.operation !== 'close',
72
+ id: sessionId,
73
+ connection: args.operation === 'close' ? null : info,
74
+ });
75
+ }
76
+ else if (args.operation === 'close') {
77
+ log_1.default.succeed(info
78
+ ? 'Control connection closing. The simulator session continues.'
79
+ : 'No control connection is open.');
80
+ }
81
+ else if (!info) {
82
+ log_1.default.log('No control connection is open. Regular control commands are available.');
83
+ }
84
+ else {
85
+ log_1.default.log(`${(0, terminalText_1.sanitizeTerminalText)(info.session.device.name ?? 'iOS Simulator')} · ${sessionId}`);
86
+ log_1.default.log(`Control connection ${info.busy ? 'busy' : 'ready'} · idle timeout: ${(0, timer_1.formatMilliseconds)(info.idleTimeoutMs)}`);
87
+ if (info.idleDeadline !== null) {
88
+ log_1.default.log(`Closes in ${(0, timer_1.formatMilliseconds)(Math.max(0, info.idleDeadline - Date.now())) || '<1s'}`);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ exports.default = SimulatorControlConnection;
@@ -1,6 +1,7 @@
1
1
  import EasCommand from '../../commandUtils/EasCommand';
2
2
  export default class SimulatorControl extends EasCommand {
3
3
  static aliases: string[];
4
+ static hiddenAliases: string[];
4
5
  static description: string;
5
6
  static strict: boolean;
6
7
  static examples: string[];
@@ -14,13 +15,19 @@ export default class SimulatorControl extends EasCommand {
14
15
  id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
16
  list: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
17
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ import: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
19
+ 'keep-alive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ 'idle-timeout': import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
17
21
  };
18
22
  static contextDefinition: {
19
23
  projectDir: import("../../commandUtils/context/ProjectDirContextField").default;
20
24
  loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
21
25
  };
22
26
  runAsync(): Promise<void>;
27
+ private importConfigAsync;
28
+ private printConfigResult;
23
29
  private printCatalog;
24
30
  private printActionHelp;
31
+ private printSessionHeader;
25
32
  private runActionAsync;
26
33
  }
@@ -3,27 +3,52 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const core_1 = require("@oclif/core");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const fs = tslib_1.__importStar(require("fs-extra"));
7
- const path_1 = tslib_1.__importDefault(require("path"));
6
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
+ const node_util_1 = require("node:util");
8
8
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
9
9
  const flags_1 = require("../../commandUtils/flags");
10
- const generated_1 = require("../../graphql/generated");
11
- const DeviceRunSessionQuery_1 = require("../../graphql/queries/DeviceRunSessionQuery");
12
10
  const log_1 = tslib_1.__importDefault(require("../../log"));
13
11
  const ora_1 = require("../../ora");
12
+ const controlConnection_1 = require("../../simulator/controlConnection");
13
+ const controlSession_1 = require("../../simulator/controlSession");
14
+ const controlActions_1 = require("../../simulator/controlActions");
15
+ const controlConfig_1 = require("../../simulator/controlConfig");
14
16
  const env_1 = require("../../simulator/env");
15
17
  const hostActions_1 = require("../../simulator/hostActions");
16
- const utils_1 = require("../../simulator/utils");
17
18
  const json_1 = require("../../utils/json");
19
+ const commandAliases_1 = require("../../simulator/commandAliases");
20
+ const formatFields_1 = tslib_1.__importDefault(require("../../utils/formatFields"));
21
+ const terminalText_1 = require("../../utils/terminalText");
22
+ const timer_1 = require("../../utils/timer");
18
23
  class SimulatorControl extends EasCommand_1.default {
19
- static aliases = ['sim:control'];
20
- static description = '[EXPERIMENTAL] run a serve-sim action on a remote iOS simulator session on EAS. Run without an action to list the actions the session supports. To save a screenshot locally, run `eas simulator:control screenshot.capture --output ./screenshot.png`';
24
+ static aliases = (0, commandAliases_1.getSimulatorCommandAliases)('control');
25
+ static hiddenAliases = (0, commandAliases_1.getSimulatorCommandHiddenAliases)('control');
26
+ static description = `[EXPERIMENTAL] control a remote iOS simulator session on EAS
27
+
28
+ Run without an action to list available actions. Use <action> --help for usage.
29
+
30
+ Use --keep-alive to reuse the connection across commands, or prepare it with simulator:control:connection open. Connections close after 120 seconds idle by default; use --idle-timeout to change the timeout in seconds.
31
+
32
+ To save a screenshot locally, run \`eas simulator:control screenshot.capture --output ./screenshot.png\`.
33
+
34
+ Use --import to run the actions from a JSON file. The start section is used only by simulator:start:
35
+
36
+ {
37
+ "version": 1,
38
+ "start": {"device": "iPhone 17 Pro", "type": "web-preview-only"},
39
+ "actions": [{"action": "appearance.set", "params": {"value": "dark"}}]
40
+ }
41
+
42
+ The file is checked before any actions run. Actions run in order and stop on the first failure. Local paths are relative to the JSON file; paths in params refer to the simulator host.
43
+
44
+ Existing output files are overwritten. When saving to a directory, an existing file with the generated name causes the action to fail.`;
21
45
  static strict = false;
22
46
  static examples = [
23
47
  '$ eas simulator:control',
24
48
  '$ eas simulator:control --id <session-id>',
25
49
  '$ eas simulator:control screenshot.capture --help',
26
50
  '$ eas simulator:control clipboard.write -- --some-text',
51
+ '$ eas simulator:control --import ./simulator-control.json',
27
52
  '$ eas simulator:control hardwareKeyboard.set off',
28
53
  '$ eas simulator:control permissions.set grant camera com.example.app',
29
54
  '$ eas simulator:control app.install ./MyApp.ipa',
@@ -32,22 +57,34 @@ class SimulatorControl extends EasCommand_1.default {
32
57
  ];
33
58
  static args = {
34
59
  action: core_1.Args.string({
35
- description: 'Action to run, followed by its values in order or as name=value. Omit to list the actions. Put -- before values that start with --.',
60
+ description: 'Action name, followed by values or name=value pairs. Omit to list actions. Use -- before values starting with --.',
36
61
  }),
37
62
  };
38
63
  static flags = {
39
64
  help: core_1.Flags.boolean({
40
65
  char: 'h',
41
- description: 'Show command help, or usage for the selected action from the session.',
66
+ description: 'Show help for this command or the selected action',
42
67
  }),
43
68
  id: core_1.Flags.string({
44
69
  description: `Simulator session ID. Defaults to ${env_1.SIMULATOR_DOTENV_FILE_NAME}.`,
45
70
  }),
46
71
  list: core_1.Flags.boolean({
47
- description: 'List the actions the session supports.',
72
+ description: 'List available actions',
48
73
  }),
49
74
  output: core_1.Flags.string({
50
- description: 'Local path to save a returned file. For screenshots, --output ./screenshot.png sets the local filename; omit it to save with a generated filename in the current directory.',
75
+ description: 'Local file or existing directory for saved output',
76
+ }),
77
+ import: core_1.Flags.string({
78
+ description: 'Run saved actions from a JSON file',
79
+ }),
80
+ 'keep-alive': core_1.Flags.boolean({
81
+ description: 'Keep the control connection available for subsequent commands (macOS and Linux)',
82
+ }),
83
+ 'idle-timeout': core_1.Flags.integer({
84
+ min: 1,
85
+ max: 86_400,
86
+ description: 'Seconds of idle time before closing the kept-alive connection (default: 120)',
87
+ dependsOn: ['keep-alive'],
51
88
  }),
52
89
  ...flags_1.EasNonInteractiveAndJsonFlags,
53
90
  };
@@ -64,8 +101,19 @@ class SimulatorControl extends EasCommand_1.default {
64
101
  if (flags.id === '') {
65
102
  throw new Error('--id needs a simulator session ID.');
66
103
  }
104
+ const idleTimeoutMs = flags['idle-timeout'] !== undefined ? flags['idle-timeout'] * 1_000 : undefined;
105
+ if (flags['keep-alive']) {
106
+ (0, controlConnection_1.assertControlKeepAliveSupported)();
107
+ }
67
108
  const action = flags.list && !flags.help ? undefined : args.action;
68
- const { projectDir, loggedIn: { graphqlClient }, } = await this.getContextAsync(SimulatorControl, {
109
+ const importing = flags.import !== undefined;
110
+ if (importing && (args.action || flags.list || flags.output !== undefined)) {
111
+ throw new Error('--import cannot be combined with an action, --list, or --output.');
112
+ }
113
+ if (!action && flags.output) {
114
+ throw new Error('--output requires an action.');
115
+ }
116
+ const { projectDir, loggedIn: { graphqlClient, authenticationInfo }, } = await this.getContextAsync(SimulatorControl, {
69
117
  nonInteractive,
70
118
  });
71
119
  await (0, env_1.loadSimulatorEnvAsync)(projectDir);
@@ -77,40 +125,176 @@ class SimulatorControl extends EasCommand_1.default {
77
125
  let connection;
78
126
  try {
79
127
  let catalog;
128
+ let controlSession;
80
129
  try {
81
- const session = await DeviceRunSessionQuery_1.DeviceRunSessionQuery.byIdAsync(graphqlClient, sessionId);
82
- connection = await (0, hostActions_1.connectHostActionsAsync)(assertControllableSession(session));
83
- catalog = await (0, hostActions_1.fetchHostActionCatalogAsync)(connection);
84
- spinner.succeed(`Connected to simulator session ${sessionId}`);
130
+ const identity = await (0, controlConnection_1.createControlConnectionIdentityAsync)(sessionId, projectDir, authenticationInfo);
131
+ if (flags['keep-alive']) {
132
+ await (0, controlConnection_1.openControlConnectionAsync)(identity, () => (0, controlSession_1.loadControlSessionAsync)(graphqlClient, sessionId), idleTimeoutMs);
133
+ }
134
+ const borrowed = await (0, controlConnection_1.borrowControlConnectionAsync)(identity);
135
+ if (flags['keep-alive'] && !borrowed) {
136
+ throw new Error('The control helper closed before it could be used. Open the connection again.');
137
+ }
138
+ if (borrowed) {
139
+ connection = borrowed.connection;
140
+ catalog = borrowed.catalog;
141
+ controlSession = borrowed.info.session;
142
+ spinner.stop();
143
+ if (flags['keep-alive'] && !action && !importing && !flags.list && !flags.help) {
144
+ if (jsonFlag) {
145
+ (0, json_1.printJsonOnlyOutput)({ connected: true, id: sessionId, connection: borrowed.info });
146
+ }
147
+ else {
148
+ log_1.default.succeed(`Control connection ready · idle timeout: ${(0, timer_1.formatMilliseconds)(borrowed.info.idleTimeoutMs)}`);
149
+ }
150
+ return;
151
+ }
152
+ }
153
+ else {
154
+ const { access, session } = await (0, controlSession_1.loadControlSessionAsync)(graphqlClient, sessionId);
155
+ connection = await (0, hostActions_1.connectHostActionsAsync)(access);
156
+ catalog = await (0, hostActions_1.fetchHostActionCatalogAsync)(connection);
157
+ controlSession = {
158
+ ...session,
159
+ device: importing || (jsonFlag && Boolean(action) && !flags.list && !flags.help)
160
+ ? await (0, hostActions_1.fetchHostActionDeviceAsync)(access, connection.udid)
161
+ : { udid: connection.udid },
162
+ };
163
+ spinner.succeed(`Connected to simulator session ${sessionId}`);
164
+ }
85
165
  }
86
166
  catch (err) {
87
167
  spinner.fail(`Failed to connect to simulator session ${sessionId}`);
88
168
  throw err;
89
169
  }
90
- if (!action) {
170
+ if (!action && !importing) {
91
171
  this.printCatalog(catalog, jsonFlag);
92
172
  return;
93
173
  }
94
- const entry = Object.hasOwn(catalog, action) ? catalog[action] : undefined;
95
- if (!entry) {
96
- throw new Error(`Unknown simulator action "${action}". Run \`eas simulator:control\` to see the actions.`);
97
- }
98
- if (flags.help) {
174
+ if (flags.help && action) {
175
+ const entry = Object.hasOwn(catalog, action) ? catalog[action] : undefined;
176
+ if (!entry) {
177
+ throw new Error(`Unknown simulator action "${action}". Run \`eas simulator:control --list\` to see the actions.`);
178
+ }
99
179
  this.printActionHelp(action, entry, jsonFlag);
100
180
  return;
101
181
  }
102
- await this.runActionAsync(connection, entry, {
103
- sessionId,
104
- action,
105
- values: argv.slice(1).map(String),
106
- outputPath: flags.output,
107
- jsonFlag,
108
- });
182
+ if (importing) {
183
+ await this.importConfigAsync(connection, catalog, flags.import, {
184
+ session: controlSession,
185
+ jsonFlag,
186
+ });
187
+ }
188
+ else {
189
+ const entry = Object.hasOwn(catalog, action) ? catalog[action] : undefined;
190
+ await this.runActionAsync(connection, catalog, {
191
+ action: action,
192
+ params: entry ? (0, hostActions_1.buildHostActionParams)(action, entry, argv.slice(1).map(String)) : {},
193
+ outputPath: flags.output,
194
+ }, { session: controlSession, jsonFlag });
195
+ }
109
196
  }
110
197
  finally {
111
198
  connection?.close();
112
199
  }
113
200
  }
201
+ async importConfigAsync(connection, catalog, filePath, { session, jsonFlag }) {
202
+ const spinner = jsonFlag ? undefined : (0, ora_1.ora)(`Validating ${node_path_1.default.basename(filePath)}`).start();
203
+ const startedAt = Date.now();
204
+ let stepStartedAt = startedAt;
205
+ let config;
206
+ let results;
207
+ try {
208
+ config = await (0, controlConfig_1.prepareControlConfigAsync)(catalog, filePath, connection.udid);
209
+ if (spinner) {
210
+ spinner.succeed(`Validated ${formatActionCount(config.actions.length)}`);
211
+ this.printSessionHeader(session);
212
+ log_1.default.log(chalk_1.default.bold(node_path_1.default.basename(config.path)));
213
+ log_1.default.gray(config.path);
214
+ for (const { plan } of config.actions) {
215
+ if (plan.localFile) {
216
+ log_1.default.gray(` Read: ${plan.localFile.path}`);
217
+ }
218
+ if (plan.outputPath) {
219
+ log_1.default.gray(` Output: ${plan.outputPath}`);
220
+ }
221
+ }
222
+ if (config.actions.some(({ plan }) => plan.outputPath)) {
223
+ log_1.default.gray('Explicit output files are overwritten; directory outputs use simulator filenames and fail if the file exists.');
224
+ }
225
+ log_1.default.newLine();
226
+ }
227
+ const prepared = config;
228
+ results = await (0, controlConfig_1.executeControlConfigAsync)(connection, prepared, {
229
+ onProgress: spinner
230
+ ? progress => {
231
+ const label = `[${progress.step}/${progress.total}] ${progress.action}`;
232
+ if (progress.status === 'running') {
233
+ stepStartedAt = Date.now();
234
+ spinner.start(label);
235
+ }
236
+ else {
237
+ spinner.succeed(`${label} ${chalk_1.default.dim(formatElapsed(stepStartedAt))}`);
238
+ this.printConfigResult(progress.result);
239
+ }
240
+ }
241
+ : undefined,
242
+ });
243
+ }
244
+ catch (error) {
245
+ if (error instanceof controlConfig_1.ControlConfigExecutionError && config) {
246
+ spinner?.fail(`[${error.step}/${config.actions.length}] ${error.action} ${chalk_1.default.dim(formatElapsed(stepStartedAt))}`);
247
+ if (jsonFlag) {
248
+ (0, json_1.printJsonOnlyOutput)({
249
+ id: session.id,
250
+ session,
251
+ config: config.path,
252
+ results: (0, controlConfig_1.serializeControlConfigResults)(error.completed),
253
+ error: { step: error.step, action: error.action, message: error.message },
254
+ });
255
+ process.exitCode = 1;
256
+ return;
257
+ }
258
+ const skipped = config.actions.length - error.step;
259
+ log_1.default.newLine();
260
+ log_1.default.log(`${error.completed.length} completed · 1 failed · ${skipped} skipped`);
261
+ for (const [index, { plan }] of config.actions.entries()) {
262
+ if (index >= error.step) {
263
+ log_1.default.gray(` [${index + 1}/${config.actions.length}] ${plan.action} skipped`);
264
+ }
265
+ }
266
+ }
267
+ else {
268
+ spinner?.fail(config ? 'Import failed' : 'Validation failed. No actions were run.');
269
+ }
270
+ throw error;
271
+ }
272
+ if (jsonFlag) {
273
+ (0, json_1.printJsonOnlyOutput)({
274
+ id: session.id,
275
+ session,
276
+ config: config.path,
277
+ results: (0, controlConfig_1.serializeControlConfigResults)(results),
278
+ });
279
+ }
280
+ else {
281
+ log_1.default.newLine();
282
+ log_1.default.succeed(`Import complete · ${formatActionCount(results.length)} · ${formatElapsed(startedAt)}`);
283
+ }
284
+ }
285
+ printConfigResult(result) {
286
+ if (result.file) {
287
+ log_1.default.log(` Saved: ${result.file}`);
288
+ }
289
+ else if (result.output) {
290
+ const output = (0, controlActions_1.parseControlActionOutput)(result.output);
291
+ const text = typeof output === 'string' ? output : JSON.stringify(output, null, 2);
292
+ log_1.default.log(text
293
+ .split('\n')
294
+ .map(line => ` ${line}`)
295
+ .join('\n'));
296
+ }
297
+ }
114
298
  printCatalog(catalog, jsonFlag) {
115
299
  if (jsonFlag) {
116
300
  (0, json_1.printJsonOnlyOutput)(Object.fromEntries(Object.entries(catalog).map(([name, entry]) => [name, withUploadPathHelp(entry)])));
@@ -163,47 +347,48 @@ class SimulatorControl extends EasCommand_1.default {
163
347
  }
164
348
  log_1.default.newLine();
165
349
  }
166
- async runActionAsync(connection, entry, { sessionId, action, values, outputPath, jsonFlag, }) {
167
- const params = (0, hostActions_1.buildHostActionParams)(action, entry, values);
168
- await (0, hostActions_1.assertHostActionOutputAsync)(action, entry, outputPath);
169
- const localFile = await findLocalUploadAsync(entry, params);
170
- const spinner = (0, ora_1.ora)(`Running ${action} on simulator session ${sessionId}`).start();
171
- let uploadId;
172
- let succeeded = false;
350
+ printSessionHeader(session) {
351
+ const clean = (value) => (0, terminalText_1.sanitizeTerminalText)((0, node_util_1.stripVTControlCharacters)(value).replace(/[\u202A-\u202E\u2066-\u2069]/g, ''));
352
+ const runtime = clean(session.device.runtime ?? '')
353
+ .replace(/^([A-Za-z]+)-/, '$1 ')
354
+ .replaceAll('-', '.');
355
+ log_1.default.newLine();
356
+ log_1.default.log(chalk_1.default.bold('Simulator controls'));
357
+ log_1.default.log((0, formatFields_1.default)([
358
+ { label: 'Session', value: (0, terminalText_1.truncate)(clean(session.name ?? '') || 'Unnamed session', 80) },
359
+ { label: 'Project', value: clean(session.project) },
360
+ {
361
+ label: 'Device',
362
+ value: [(0, terminalText_1.truncate)(clean(session.device.name ?? '') || 'Unavailable', 80), runtime]
363
+ .filter(Boolean)
364
+ .join(' · '),
365
+ },
366
+ { label: 'State', value: session.status.toLowerCase().replaceAll('_', ' ') },
367
+ { label: 'Session ID', value: clean(session.id) },
368
+ { label: 'Device ID', value: clean(session.device.udid) },
369
+ ]));
370
+ log_1.default.newLine();
371
+ }
372
+ async runActionAsync(connection, catalog, selection, { session, jsonFlag }) {
373
+ const { action } = selection;
374
+ const plan = await (0, controlActions_1.prepareControlActionAsync)(catalog, selection);
375
+ const spinner = (0, ora_1.ora)(`Running ${action} on simulator session ${session.id}`).start();
173
376
  let output;
174
377
  let savedFile;
175
378
  try {
176
- if (localFile) {
177
- spinner.text = `Uploading ${localFile.path}`;
178
- const upload = await (0, hostActions_1.uploadFileAsync)(connection, localFile.path);
179
- uploadId = upload.uploadId;
180
- params[localFile.param] = entry.uploadAs === 'id' ? upload.uploadId : upload.path;
181
- spinner.text = `Running ${action} on simulator session ${sessionId}`;
182
- }
183
- const result = await connection.requestAsync(action, params);
184
- if (result.exitCode !== 0) {
185
- const detail = (result.stderr || result.stdout).trim() || `exit code ${result.exitCode}`;
186
- throw new Error(`The simulator could not run ${action}: ${detail}`);
187
- }
188
- succeeded = true;
189
- savedFile = await (0, hostActions_1.saveHostActionOutputAsync)(connection, entry, result.stdout, outputPath);
190
- output = savedFile ? '' : result.stdout.trim();
191
- spinner.succeed(`Ran ${action} on simulator session ${sessionId}`);
379
+ ({ output, file: savedFile } = await (0, controlActions_1.executeControlActionAsync)(connection, plan));
380
+ spinner.succeed(`Ran ${action} on simulator session ${session.id}`);
192
381
  }
193
382
  catch (err) {
194
- spinner.fail(`Failed to run ${action} on simulator session ${sessionId}`);
383
+ spinner.fail(`Failed to run ${action} on simulator session ${session.id}`);
195
384
  throw err;
196
385
  }
197
- finally {
198
- if (uploadId && (!entry.keepUpload || !succeeded)) {
199
- await connection.requestAsync('upload.remove', { uploadId }).catch(() => { });
200
- }
201
- }
202
386
  if (jsonFlag) {
203
387
  (0, json_1.printJsonOnlyOutput)({
204
- id: sessionId,
388
+ id: session.id,
389
+ session,
205
390
  action,
206
- output: parseJsonOutput(output),
391
+ output: (0, controlActions_1.parseControlActionOutput)(output),
207
392
  file: savedFile,
208
393
  });
209
394
  return;
@@ -231,55 +416,9 @@ function withUploadPathHelp(entry) {
231
416
  ? { ...entry, description: [entry.description, help].filter(Boolean).join('\n\n') }
232
417
  : entry;
233
418
  }
234
- async function findLocalUploadAsync({ upload: param, uploadWhen = {}, uploadAs }, params) {
235
- const value = param ? params[param] : undefined;
236
- const applies = Object.entries(uploadWhen).every(([name, expected]) => params[name] === expected);
237
- if (!param || typeof value !== 'string' || !applies) {
238
- return null;
239
- }
240
- if (value.startsWith('host:')) {
241
- if (uploadAs === 'id') {
242
- throw new Error('This action requires a local file to upload; host: paths are not supported.');
243
- }
244
- const hostPath = value.slice('host:'.length);
245
- if (!path_1.default.posix.isAbsolute(hostPath)) {
246
- throw new Error(`A host: path must be absolute, for example host:/tmp/app.tar.gz. For a local filename beginning with host:, use ./${value}.`);
247
- }
248
- params[param] = hostPath;
249
- return null;
250
- }
251
- const stat = await fs.stat(value).catch((error) => {
252
- if (error.code === 'ENOENT' || error.code === 'ENOTDIR') {
253
- return null;
254
- }
255
- throw error;
256
- });
257
- if (stat?.isDirectory()) {
258
- throw new Error(`${value} is a folder. Pass the path of a file.`);
259
- }
260
- if (!stat) {
261
- throw new Error(`${value} does not exist on this computer. Pass a local file, or prefix an absolute simulator-host path with host:.`);
262
- }
263
- return stat ? { param, path: value } : null;
419
+ function formatElapsed(startedAt) {
420
+ return (0, timer_1.formatMilliseconds)(Date.now() - startedAt) || '<1s';
264
421
  }
265
- function assertControllableSession(session) {
266
- if (session.status !== generated_1.DeviceRunSessionStatus.InProgress) {
267
- throw new Error(`Simulator session ${session.id} is ${session.status.toLowerCase()}. Simulator actions need a running session. Start one with \`eas simulator:start\`.`);
268
- }
269
- if (session.platform !== generated_1.AppPlatform.Ios) {
270
- throw new Error(`Simulator session ${session.id} runs on ${session.platform.toLowerCase()}. Simulator actions are available only for iOS sessions.`);
271
- }
272
- const access = session.remoteConfig ? (0, utils_1.getPreviewApiAccess)(session.remoteConfig) : null;
273
- if (!access) {
274
- 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\`.`);
275
- }
276
- return access;
277
- }
278
- function parseJsonOutput(output) {
279
- try {
280
- return JSON.parse(output);
281
- }
282
- catch {
283
- return output;
284
- }
422
+ function formatActionCount(count) {
423
+ return `${count} action${count === 1 ? '' : 's'}`;
285
424
  }
@@ -1,6 +1,7 @@
1
1
  import EasCommand from '../../commandUtils/EasCommand';
2
2
  export default class SimulatorEgress extends EasCommand {
3
3
  static aliases: string[];
4
+ static hiddenAliases: string[];
4
5
  static description: string;
5
6
  static flags: {
6
7
  'config-type': import("@oclif/core/lib/interfaces").OptionFlag<"env" | "dotenv", import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -6,8 +6,10 @@ const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasComm
6
6
  const log_1 = tslib_1.__importDefault(require("../../log"));
7
7
  const egress_1 = require("../../simulator/egress");
8
8
  const env_1 = require("../../simulator/env");
9
+ const commandAliases_1 = require("../../simulator/commandAliases");
9
10
  class SimulatorEgress extends EasCommand_1.default {
10
- static aliases = ['sim:egress'];
11
+ static aliases = (0, commandAliases_1.getSimulatorCommandAliases)('egress');
12
+ static hiddenAliases = (0, commandAliases_1.getSimulatorCommandHiddenAliases)('egress');
11
13
  static description = `[EXPERIMENTAL] run the local egress client for a simulator session to route proxied HTTP(S) requests through this machine`;
12
14
  static flags = {
13
15
  'config-type': core_1.Flags.option({