eas-cli 25.1.1 → 25.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +282 -162
  2. package/build/analytics/AnalyticsManager.d.ts +7 -1
  3. package/build/analytics/AnalyticsManager.js +12 -1
  4. package/build/billing/resolveAccount.d.ts +12 -0
  5. package/build/billing/resolveAccount.js +1 -0
  6. package/build/build/build.d.ts +3 -1
  7. package/build/build/build.js +14 -12
  8. package/build/build/context.d.ts +4 -0
  9. package/build/build/createContext.d.ts +5 -1
  10. package/build/build/createContext.js +3 -1
  11. package/build/build/freeTierLimitCheckout.d.ts +39 -0
  12. package/build/build/freeTierLimitCheckout.js +106 -0
  13. package/build/build/freeTierLimitGuidance.d.ts +19 -0
  14. package/build/build/freeTierLimitGuidance.js +39 -0
  15. package/build/build/runBuildAndSubmit.d.ts +7 -1
  16. package/build/build/runBuildAndSubmit.js +6 -2
  17. package/build/build/utils/url.d.ts +1 -0
  18. package/build/build/utils/url.js +4 -0
  19. package/build/commandUtils/EasCommand.d.ts +9 -0
  20. package/build/commandUtils/EasCommand.js +12 -1
  21. package/build/commandUtils/context/ExperimentationContextField.d.ts +13 -0
  22. package/build/commandUtils/context/ExperimentationContextField.js +79 -0
  23. package/build/commandUtils/context/contextUtils/createGraphqlClient.d.ts +3 -0
  24. package/build/commandUtils/context/contextUtils/createGraphqlClient.js +29 -2
  25. package/build/commandUtils/errors.d.ts +5 -1
  26. package/build/commandUtils/errors.js +4 -3
  27. package/build/commands/analytics.js +1 -1
  28. package/build/commands/build/index.d.ts +1 -0
  29. package/build/commands/build/index.js +4 -1
  30. package/build/commands/simulator/control.d.ts +26 -0
  31. package/build/commands/simulator/control.js +250 -0
  32. package/build/commands/simulator/index.d.ts +1 -0
  33. package/build/commands/simulator/index.js +18 -4
  34. package/build/commands/update/republish.d.ts +1 -1
  35. package/build/env.d.ts +6 -0
  36. package/build/env.js +6 -0
  37. package/build/experimentation/AnalyticsExposureLogger.d.ts +7 -0
  38. package/build/experimentation/AnalyticsExposureLogger.js +21 -0
  39. package/build/experimentation/ExperimentNamespace.d.ts +24 -0
  40. package/build/experimentation/ExperimentNamespace.js +69 -0
  41. package/build/experimentation/ExperimentOverrides.d.ts +17 -0
  42. package/build/experimentation/ExperimentOverrides.js +68 -0
  43. package/build/experimentation/ExperimentationClient.d.ts +32 -0
  44. package/build/experimentation/ExperimentationClient.js +125 -0
  45. package/build/experimentation/LazyExperimentationClient.d.ts +12 -0
  46. package/build/experimentation/LazyExperimentationClient.js +22 -0
  47. package/build/graphql/generated.d.ts +12 -0
  48. package/build/graphql/queries/ExperimentationConfigQuery.d.ts +10 -0
  49. package/build/graphql/queries/ExperimentationConfigQuery.js +49 -0
  50. package/build/graphql/queries/UserQuery.d.ts +3 -1
  51. package/build/graphql/queries/UserQuery.js +2 -1
  52. package/build/help.d.ts +4 -0
  53. package/build/help.js +56 -0
  54. package/build/simulator/hostActions.d.ts +70 -0
  55. package/build/simulator/hostActions.js +411 -0
  56. package/build/simulator/utils.d.ts +5 -0
  57. package/build/simulator/utils.js +11 -0
  58. package/build/user/SessionManager.d.ts +8 -1
  59. package/build/user/SessionManager.js +7 -2
  60. package/oclif.manifest.json +917 -3
  61. package/package.json +8 -6
@@ -0,0 +1,13 @@
1
+ import ContextField, { ContextOptions } from './ContextField';
2
+ import { LazyExperimentationClient } from '../../experimentation/LazyExperimentationClient';
3
+ /**
4
+ * Never prompts, throws, writes files, or reads the app config. A failed config fetch disables
5
+ * all scopes. CI runs skip the fetch and get defaults.
6
+ * The config fetch runs on the first `getClientAsync` call, so commands that never read a variant
7
+ * make no request.
8
+ */
9
+ export default class ExperimentationContextField extends ContextField<LazyExperimentationClient> {
10
+ private readonly clientByAnalytics;
11
+ getValueAsync(options: ContextOptions): Promise<LazyExperimentationClient>;
12
+ private buildClientAsync;
13
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const ContextField_1 = tslib_1.__importDefault(require("./ContextField"));
5
+ const createGraphqlClient_1 = require("./contextUtils/createGraphqlClient");
6
+ const ExperimentOverrides_1 = require("../../experimentation/ExperimentOverrides");
7
+ const ExperimentationClient_1 = require("../../experimentation/ExperimentationClient");
8
+ const LazyExperimentationClient_1 = require("../../experimentation/LazyExperimentationClient");
9
+ const ExperimentationConfigQuery_1 = require("../../graphql/queries/ExperimentationConfigQuery");
10
+ const log_1 = tslib_1.__importDefault(require("../../log"));
11
+ /** Caps how long the config fetch and the actor lookup can delay a command. */
12
+ const REQUEST_TIMEOUT_MS = 3000;
13
+ const CI_ENVIRONMENT_FLAGS = ['EAS_BUILD', 'CI'];
14
+ function isRunningInCi() {
15
+ return CI_ENVIRONMENT_FLAGS.some(flag => !!process.env[flag]);
16
+ }
17
+ /**
18
+ * Never prompts, throws, writes files, or reads the app config. A failed config fetch disables
19
+ * all scopes. CI runs skip the fetch and get defaults.
20
+ * The config fetch runs on the first `getClientAsync` call, so commands that never read a variant
21
+ * make no request.
22
+ */
23
+ class ExperimentationContextField extends ContextField_1.default {
24
+ // One handle per command run, so repeated getContextAsync calls cannot log duplicate exposures.
25
+ clientByAnalytics = new WeakMap();
26
+ async getValueAsync(options) {
27
+ let client = this.clientByAnalytics.get(options.analytics);
28
+ if (!client) {
29
+ client = new LazyExperimentationClient_1.LazyExperimentationClient(() => this.buildClientAsync(options));
30
+ this.clientByAnalytics.set(options.analytics, client);
31
+ }
32
+ return client;
33
+ }
34
+ async buildClientAsync({ sessionManager, analytics, }) {
35
+ const overrides = ExperimentOverrides_1.ExperimentOverrides.fromEnv();
36
+ if (isRunningInCi()) {
37
+ log_1.default.debug('[experimentation] Running in CI. Experiments return defaults.');
38
+ return ExperimentationClient_1.ExperimentationClient.createDisabled(overrides);
39
+ }
40
+ const deviceId = analytics.getDeviceId();
41
+ if (deviceId === null) {
42
+ log_1.default.debug('[experimentation] Analytics is disabled. Experiments return defaults.');
43
+ return ExperimentationClient_1.ExperimentationClient.createDisabled(overrides);
44
+ }
45
+ try {
46
+ const graphqlClient = (0, createGraphqlClient_1.createGraphqlClient)({
47
+ accessToken: sessionManager.getAccessToken(),
48
+ sessionSecret: sessionManager.getSessionSecret(),
49
+ }, { requestTimeoutMs: REQUEST_TIMEOUT_MS });
50
+ // The session manager skips the request once an actor is cached. Without a cached actor
51
+ // (for example, a stale session) it makes its own request, so it needs the same cap.
52
+ const [actorResult, configsResult] = await Promise.allSettled([
53
+ sessionManager.getUserAsync({ requestTimeoutMs: REQUEST_TIMEOUT_MS }),
54
+ ExperimentationConfigQuery_1.ExperimentationConfigQuery.getConfigsAsync(graphqlClient),
55
+ ]);
56
+ if (configsResult.status === 'rejected') {
57
+ log_1.default.debug('[experimentation] Failed to fetch the experiment config. Experiments return defaults.', errorMessage(configsResult.reason));
58
+ return ExperimentationClient_1.ExperimentationClient.createDisabled(overrides);
59
+ }
60
+ const configs = configsResult.value;
61
+ return new ExperimentationClient_1.ExperimentationClient({
62
+ user: configs.userConfig,
63
+ account: configs.accountConfig,
64
+ device: configs.deviceConfig,
65
+ }, {
66
+ user: actorResult.status === 'fulfilled' ? (actorResult.value?.id ?? null) : null,
67
+ device: deviceId,
68
+ }, overrides, (0, ExperimentationClient_1.createLoggerConfig)(analytics));
69
+ }
70
+ catch (error) {
71
+ log_1.default.debug('[experimentation] Failed to initialize experiments. Experiments return defaults.', errorMessage(error));
72
+ return ExperimentationClient_1.ExperimentationClient.createDisabled(overrides);
73
+ }
74
+ }
75
+ }
76
+ exports.default = ExperimentationContextField;
77
+ function errorMessage(error) {
78
+ return error instanceof Error ? error.message : String(error);
79
+ }
@@ -4,4 +4,7 @@ export interface ExpoGraphqlClient extends Client {
4
4
  export declare function createGraphqlClient(authInfo: {
5
5
  accessToken: string | null;
6
6
  sessionSecret: string | null;
7
+ }, options?: {
8
+ /** Request timeout. Kept at the client level: a per-operation `fetchOptions` in urql would replace the auth headers. */
9
+ requestTimeoutMs?: number;
7
10
  }): ExpoGraphqlClient;
@@ -7,7 +7,34 @@ const exchange_retry_1 = require("@urql/exchange-retry");
7
7
  const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
8
8
  const api_1 = require("../../../api");
9
9
  const fetch_1 = require("../../../fetch");
10
- function createGraphqlClient(authInfo) {
10
+ function createGraphqlClient(authInfo, options = {}) {
11
+ const { requestTimeoutMs } = options;
12
+ // urql overwrites `fetchOptions.signal`, so the timeout must be added inside fetch.
13
+ const fetchWithTimeoutAsync = async (url, init) => {
14
+ if (!requestTimeoutMs) {
15
+ return await (0, node_fetch_1.default)(url, init);
16
+ }
17
+ const timeoutSignal = AbortSignal.timeout(requestTimeoutMs);
18
+ try {
19
+ return await (0, node_fetch_1.default)(url, {
20
+ ...init,
21
+ signal: AbortSignal.any([
22
+ ...(init?.signal ? [init.signal] : []),
23
+ timeoutSignal,
24
+ ]),
25
+ });
26
+ }
27
+ catch (error) {
28
+ if (timeoutSignal.aborted) {
29
+ const timeoutError = new Error(`Request timed out after ${requestTimeoutMs} ms`, {
30
+ cause: error,
31
+ });
32
+ timeoutError.name = 'TimeoutError';
33
+ throw timeoutError;
34
+ }
35
+ throw error;
36
+ }
37
+ };
11
38
  return (0, core_1.createClient)({
12
39
  url: (0, api_1.getExpoApiBaseUrl)() + '/graphql',
13
40
  exchanges: [
@@ -23,7 +50,7 @@ function createGraphqlClient(authInfo) {
23
50
  core_1.fetchExchange,
24
51
  ],
25
52
  // @ts-expect-error Type 'typeof fetch' is not assignable to type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.
26
- fetch: node_fetch_1.default,
53
+ fetch: fetchWithTimeoutAsync,
27
54
  fetchOptions: () => {
28
55
  const headers = {};
29
56
  if (authInfo.accessToken) {
@@ -1,3 +1,7 @@
1
1
  export declare class EasCommandError extends Error {
2
- constructor(message: string);
2
+ /** True when the command already printed the message, so `EasCommand.catch` must not print it again. */
3
+ readonly messageAlreadyPrinted: boolean;
4
+ constructor(message: string, { messageAlreadyPrinted }?: {
5
+ messageAlreadyPrinted?: boolean;
6
+ });
3
7
  }
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EasCommandError = void 0;
4
4
  class EasCommandError extends Error {
5
- // constructor is not useless, since the constructor for Error allows for optional `message`
6
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor
7
- constructor(message) {
5
+ /** True when the command already printed the message, so `EasCommand.catch` must not print it again. */
6
+ messageAlreadyPrinted;
7
+ constructor(message, { messageAlreadyPrinted = false } = {}) {
8
8
  super(message);
9
+ this.messageAlreadyPrinted = messageAlreadyPrinted;
9
10
  }
10
11
  }
11
12
  exports.EasCommandError = EasCommandError;
@@ -6,7 +6,7 @@ const AnalyticsManager_1 = require("../analytics/AnalyticsManager");
6
6
  const EasCommand_1 = tslib_1.__importDefault(require("../commandUtils/EasCommand"));
7
7
  const log_1 = tslib_1.__importDefault(require("../log"));
8
8
  class AnalyticsView extends EasCommand_1.default {
9
- static description = 'display or change analytics settings';
9
+ static description = 'display or change analytics settings (disabling analytics also disables experiments)';
10
10
  static args = {
11
11
  STATUS: core_1.Args.string({
12
12
  options: ['on', 'off'],
@@ -25,6 +25,7 @@ export default class Build extends EasCommand {
25
25
  'verbose-logs': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
26
  };
27
27
  static contextDefinition: {
28
+ experimentation: import("../../commandUtils/context/ExperimentationContextField").default;
28
29
  vcsClient: import("../../commandUtils/context/VcsClientContextField").default;
29
30
  analytics: import("../../commandUtils/context/AnalyticsContextField").default;
30
31
  projectDir: import("../../commandUtils/context/ProjectDirContextField").default;
@@ -108,6 +108,7 @@ class Build extends EasCommand_1.default {
108
108
  ...this.ContextOptions.ProjectDir,
109
109
  ...this.ContextOptions.Analytics,
110
110
  ...this.ContextOptions.Vcs,
111
+ ...this.ContextOptions.Experimentation,
111
112
  };
112
113
  async runAsync() {
113
114
  const { flags: rawFlags } = await this.parse(Build);
@@ -115,7 +116,7 @@ class Build extends EasCommand_1.default {
115
116
  (0, json_1.enableJsonOutput)();
116
117
  }
117
118
  const flags = this.sanitizeFlags(rawFlags);
118
- const { loggedIn: { actor, graphqlClient }, getDynamicPrivateProjectConfigAsync, projectDir, analytics, vcsClient, } = await this.getContextAsync(Build, {
119
+ const { loggedIn: { actor, graphqlClient, authenticationInfo }, getDynamicPrivateProjectConfigAsync, projectDir, analytics, vcsClient, experimentation, } = await this.getContextAsync(Build, {
119
120
  nonInteractive: flags.nonInteractive,
120
121
  withServerSideEnvironment: null,
121
122
  });
@@ -134,6 +135,8 @@ class Build extends EasCommand_1.default {
134
135
  flags: flagsWithPlatform,
135
136
  actor,
136
137
  getDynamicPrivateProjectConfigAsync,
138
+ experimentation,
139
+ authenticationInfo,
137
140
  });
138
141
  this.maybeSuggestUsingEasBuildDev({
139
142
  buildProfiles,
@@ -0,0 +1,26 @@
1
+ import EasCommand from '../../commandUtils/EasCommand';
2
+ export default class SimulatorControl extends EasCommand {
3
+ static aliases: string[];
4
+ static description: string;
5
+ static strict: boolean;
6
+ static examples: string[];
7
+ static args: {
8
+ action: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
9
+ };
10
+ static flags: {
11
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
+ help: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
+ list: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
17
+ };
18
+ static contextDefinition: {
19
+ projectDir: import("../../commandUtils/context/ProjectDirContextField").default;
20
+ loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
21
+ };
22
+ runAsync(): Promise<void>;
23
+ private printCatalog;
24
+ private printActionHelp;
25
+ private runActionAsync;
26
+ }
@@ -0,0 +1,250 @@
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 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"));
8
+ const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
9
+ const flags_1 = require("../../commandUtils/flags");
10
+ const generated_1 = require("../../graphql/generated");
11
+ const DeviceRunSessionQuery_1 = require("../../graphql/queries/DeviceRunSessionQuery");
12
+ const log_1 = tslib_1.__importDefault(require("../../log"));
13
+ const ora_1 = require("../../ora");
14
+ const env_1 = require("../../simulator/env");
15
+ const hostActions_1 = require("../../simulator/hostActions");
16
+ const utils_1 = require("../../simulator/utils");
17
+ const json_1 = require("../../utils/json");
18
+ 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`.';
21
+ static strict = false;
22
+ static examples = [
23
+ '$ eas simulator:control',
24
+ '$ eas simulator:control --id <session-id>',
25
+ '$ eas simulator:control screenshot.capture --help',
26
+ '$ eas simulator:control clipboard.write -- --some-text',
27
+ '$ eas simulator:control hardwareKeyboard.set off',
28
+ '$ eas simulator:control permissions.set grant camera com.example.app',
29
+ '$ eas simulator:control app.install ./MyApp.ipa',
30
+ '$ eas simulator:control screenshot.capture --output ./screenshot.png',
31
+ '$ eas simulator:control screenshot.capture --output ./screenshot.png --id <session-id>',
32
+ ];
33
+ static args = {
34
+ 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 --.',
36
+ }),
37
+ };
38
+ static flags = {
39
+ help: core_1.Flags.boolean({
40
+ char: 'h',
41
+ description: 'Show command help, or usage for the selected action from the session.',
42
+ }),
43
+ id: core_1.Flags.string({
44
+ description: `Simulator session ID. Defaults to ${env_1.SIMULATOR_DOTENV_FILE_NAME}.`,
45
+ }),
46
+ list: core_1.Flags.boolean({
47
+ description: 'List the actions the session supports.',
48
+ }),
49
+ 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.',
51
+ }),
52
+ ...flags_1.EasNonInteractiveAndJsonFlags,
53
+ };
54
+ static contextDefinition = {
55
+ ...this.ContextOptions.LoggedIn,
56
+ ...this.ContextOptions.ProjectDir,
57
+ };
58
+ async runAsync() {
59
+ const { args, argv, flags } = await this.parse(SimulatorControl);
60
+ const { json: jsonFlag, nonInteractive } = (0, flags_1.resolveNonInteractiveAndJsonFlags)(flags);
61
+ if (jsonFlag) {
62
+ (0, json_1.enableJsonOutput)();
63
+ }
64
+ if (flags.id === '') {
65
+ throw new Error('--id needs a simulator session ID.');
66
+ }
67
+ const action = flags.list && !flags.help ? undefined : args.action;
68
+ const { projectDir, loggedIn: { graphqlClient }, } = await this.getContextAsync(SimulatorControl, {
69
+ nonInteractive,
70
+ });
71
+ await (0, env_1.loadSimulatorEnvAsync)(projectDir);
72
+ const sessionId = flags.id ?? process.env[env_1.EAS_SIMULATOR_SESSION_ID];
73
+ if (!sessionId) {
74
+ throw new Error(`No simulator session ID provided. Pass --id, or run \`eas simulator:start\` first to write ${env_1.SIMULATOR_DOTENV_FILE_NAME}.`);
75
+ }
76
+ const spinner = (0, ora_1.ora)(`Connecting to simulator session ${sessionId}`).start();
77
+ let connection;
78
+ try {
79
+ let catalog;
80
+ 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}`);
85
+ }
86
+ catch (err) {
87
+ spinner.fail(`Failed to connect to simulator session ${sessionId}`);
88
+ throw err;
89
+ }
90
+ if (!action) {
91
+ this.printCatalog(catalog, jsonFlag);
92
+ return;
93
+ }
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) {
99
+ this.printActionHelp(action, entry, jsonFlag);
100
+ return;
101
+ }
102
+ await this.runActionAsync(connection, entry, {
103
+ sessionId,
104
+ action,
105
+ values: argv.slice(1).map(String),
106
+ outputPath: flags.output,
107
+ jsonFlag,
108
+ });
109
+ }
110
+ finally {
111
+ connection?.close();
112
+ }
113
+ }
114
+ printCatalog(catalog, jsonFlag) {
115
+ if (jsonFlag) {
116
+ (0, json_1.printJsonOnlyOutput)(catalog);
117
+ return;
118
+ }
119
+ const names = Object.keys(catalog).sort();
120
+ const width = Math.max(0, ...names.map(name => name.length)) + 3;
121
+ const columns = Math.max(1, Math.min(3, Math.floor((process.stdout.columns || 80) / width)));
122
+ const rows = Math.ceil(names.length / columns);
123
+ for (let row = 0; row < rows; row++) {
124
+ const cells = Array.from({ length: columns }, (_, column) => (names[row + column * rows] ?? '').padEnd(width));
125
+ log_1.default.log(cells.join('').trimEnd());
126
+ }
127
+ log_1.default.newLine();
128
+ log_1.default.log('For action usage: eas simulator:control <action> --help');
129
+ }
130
+ printActionHelp(action, entry, jsonFlag) {
131
+ if (jsonFlag) {
132
+ (0, json_1.printJsonOnlyOutput)({ ...entry, action });
133
+ return;
134
+ }
135
+ log_1.default.newLine();
136
+ log_1.default.log(` ${chalk_1.default.bold(action)}`);
137
+ if (entry.description) {
138
+ log_1.default.log(` ${entry.description}`);
139
+ }
140
+ log_1.default.newLine();
141
+ log_1.default.log(` ${chalk_1.default.bold('USAGE')}`);
142
+ log_1.default.log(` eas simulator:control ${(0, hostActions_1.formatHostActionUsage)(action, entry)}`);
143
+ const outputFlag = entry.output === 'base64' ? '--output <path>' : '[--output <path>]';
144
+ log_1.default.log(` ${entry.output ? `${outputFlag} ` : ''}[--id <session-id>] [--json]`);
145
+ log_1.default.newLine();
146
+ log_1.default.log(` ${chalk_1.default.bold('OPTIONS')}`);
147
+ log_1.default.log(` --id <session-id> Defaults to ${env_1.SIMULATOR_DOTENV_FILE_NAME}.`);
148
+ log_1.default.log(' --json Print the action schema as JSON. Implies --non-interactive.');
149
+ if (entry.output) {
150
+ log_1.default.log(entry.output === 'base64'
151
+ ? ' --output <path> Required local filename for the returned file.'
152
+ : ' --output <path> Local filename or existing directory.');
153
+ if (entry.output === 'path') {
154
+ log_1.default.log(' Omit to save with the generated filename.');
155
+ }
156
+ log_1.default.newLine();
157
+ log_1.default.log(' Action arguments refer to the simulator host. Use --output for the local filename.');
158
+ }
159
+ log_1.default.newLine();
160
+ }
161
+ async runActionAsync(connection, entry, { sessionId, action, values, outputPath, jsonFlag, }) {
162
+ const params = (0, hostActions_1.buildHostActionParams)(action, entry, values);
163
+ await (0, hostActions_1.assertHostActionOutputAsync)(action, entry, outputPath);
164
+ const localFile = await findLocalUploadAsync(entry, params);
165
+ const spinner = (0, ora_1.ora)(`Running ${action} on simulator session ${sessionId}`).start();
166
+ let uploadId;
167
+ let succeeded = false;
168
+ let output;
169
+ let savedFile;
170
+ try {
171
+ if (localFile) {
172
+ spinner.text = `Uploading ${localFile.path}`;
173
+ const upload = await (0, hostActions_1.uploadFileAsync)(connection, localFile.path);
174
+ uploadId = upload.uploadId;
175
+ params[localFile.param] = entry.uploadAs === 'id' ? upload.uploadId : upload.path;
176
+ spinner.text = `Running ${action} on simulator session ${sessionId}`;
177
+ }
178
+ const result = await connection.requestAsync(action, params);
179
+ if (result.exitCode !== 0) {
180
+ const detail = (result.stderr || result.stdout).trim() || `exit code ${result.exitCode}`;
181
+ throw new Error(`The simulator could not run ${action}: ${detail}`);
182
+ }
183
+ succeeded = true;
184
+ savedFile = await (0, hostActions_1.saveHostActionOutputAsync)(connection, entry, result.stdout, outputPath);
185
+ output = savedFile ? '' : result.stdout.trim();
186
+ spinner.succeed(`Ran ${action} on simulator session ${sessionId}`);
187
+ }
188
+ catch (err) {
189
+ spinner.fail(`Failed to run ${action} on simulator session ${sessionId}`);
190
+ throw err;
191
+ }
192
+ finally {
193
+ if (uploadId && (!entry.keepUpload || !succeeded)) {
194
+ await connection.requestAsync('upload.remove', { uploadId }).catch(() => { });
195
+ }
196
+ }
197
+ if (jsonFlag) {
198
+ (0, json_1.printJsonOnlyOutput)({
199
+ id: sessionId,
200
+ action,
201
+ output: parseJsonOutput(output),
202
+ file: savedFile,
203
+ });
204
+ return;
205
+ }
206
+ if (savedFile) {
207
+ log_1.default.log(`Saved ${savedFile}`);
208
+ }
209
+ else if (output) {
210
+ log_1.default.log(output);
211
+ }
212
+ }
213
+ }
214
+ exports.default = SimulatorControl;
215
+ async function findLocalUploadAsync({ upload: param, uploadWhen = {} }, params) {
216
+ const value = param ? params[param] : undefined;
217
+ const applies = Object.entries(uploadWhen).every(([name, expected]) => params[name] === expected);
218
+ if (!param || typeof value !== 'string' || !applies) {
219
+ return null;
220
+ }
221
+ const stat = await fs.stat(value).catch(() => null);
222
+ if (stat?.isDirectory()) {
223
+ throw new Error(`${value} is a folder. Pass the path of a file.`);
224
+ }
225
+ if (!stat && !path_1.default.isAbsolute(value)) {
226
+ throw new Error(`${value} does not exist on this computer. Pass the path of a local file, or an absolute path on the simulator host.`);
227
+ }
228
+ return stat ? { param, path: value } : null;
229
+ }
230
+ function assertControllableSession(session) {
231
+ if (session.status !== generated_1.DeviceRunSessionStatus.InProgress) {
232
+ throw new Error(`Simulator session ${session.id} is ${session.status.toLowerCase()}. Simulator actions need a running session. Start one with \`eas simulator:start\`.`);
233
+ }
234
+ if (session.platform !== generated_1.AppPlatform.Ios) {
235
+ throw new Error(`Simulator session ${session.id} runs on ${session.platform.toLowerCase()}. Simulator actions are available only for iOS sessions.`);
236
+ }
237
+ const access = session.remoteConfig ? (0, utils_1.getPreviewApiAccess)(session.remoteConfig) : null;
238
+ if (!access) {
239
+ 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\`.`);
240
+ }
241
+ return access;
242
+ }
243
+ function parseJsonOutput(output) {
244
+ try {
245
+ return JSON.parse(output);
246
+ }
247
+ catch {
248
+ return output;
249
+ }
250
+ }
@@ -10,6 +10,7 @@ export default class Simulator extends EasCommand {
10
10
  name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
11
  tag: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
12
12
  device: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
+ 'system-image': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
14
  'build-id': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
14
15
  'build-fingerprint': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
16
  'application-archive-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -57,6 +57,9 @@ class Simulator extends EasCommand_1.default {
57
57
  device: core_1.Flags.string({
58
58
  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.',
59
59
  }),
60
+ 'system-image': core_1.Flags.string({
61
+ description: 'Android SDK system image package to use for the emulator (e.g. "system-images;android-35-ext15;google_apis_playstore;x86_64"). Defaults to a system image chosen by the runner. Only supported with --platform android.',
62
+ }),
60
63
  'build-id': core_1.Flags.string({
61
64
  description: 'EAS Build to install and launch before the simulator session is ready.',
62
65
  exclusive: ['build-fingerprint', 'application-archive-url', 'expo-go'],
@@ -173,6 +176,7 @@ class Simulator extends EasCommand_1.default {
173
176
  const name = flags.name?.trim() || undefined;
174
177
  const tags = flags.tag?.map(tag => tag.trim()).filter(tag => tag.length > 0);
175
178
  const deviceIdentifier = flags.device?.trim() || undefined;
179
+ const systemImagePackage = flags['system-image']?.trim() || undefined;
176
180
  const buildId = flags['build-id']?.trim() || undefined;
177
181
  const buildFingerprint = flags['build-fingerprint']?.trim() || undefined;
178
182
  const applicationArchiveUrlFromFlag = flags['application-archive-url']?.trim() || undefined;
@@ -207,6 +211,9 @@ class Simulator extends EasCommand_1.default {
207
211
  }
208
212
  const platform = await resolvePlatformAsync(flags.platform, nonInteractive);
209
213
  const egress = flags.egress === 'local' ? generated_1.DeviceRunSessionEgress.Local : undefined;
214
+ if (systemImagePackage && platform !== generated_1.AppPlatform.Android) {
215
+ throw new errors_1.EasCommandError('--system-image is only supported with --platform android.');
216
+ }
210
217
  let egressAllow = [];
211
218
  try {
212
219
  egressAllow = (0, egress_1.parseEgressAllowList)(flags['egress-allow'] ?? []);
@@ -271,11 +278,18 @@ class Simulator extends EasCommand_1.default {
271
278
  packageVersion: flags['package-version'],
272
279
  networkCapture: flags['network-capture'],
273
280
  ...(networkCaptureFields.length ? { networkCaptureFields } : {}),
274
- ...(deviceIdentifier
275
- ? platform === generated_1.AppPlatform.Ios
281
+ ...(platform === generated_1.AppPlatform.Ios
282
+ ? deviceIdentifier
276
283
  ? { ios: { deviceIdentifier } }
277
- : { android: { deviceIdentifier } }
278
- : {}),
284
+ : {}
285
+ : deviceIdentifier || systemImagePackage
286
+ ? {
287
+ android: {
288
+ ...(deviceIdentifier ? { deviceIdentifier } : {}),
289
+ ...(systemImagePackage ? { systemImagePackage } : {}),
290
+ },
291
+ }
292
+ : {}),
279
293
  ...(buildId ? { buildId } : {}),
280
294
  ...(buildFingerprint ? { buildFingerprint } : {}),
281
295
  ...(applicationArchiveUrlFromFlag
@@ -10,7 +10,7 @@ export default class UpdateRepublish extends EasCommand {
10
10
  'destination-channel': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
11
  'destination-branch': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
12
12
  message: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
- platform: import("@oclif/core/lib/interfaces").OptionFlag<"android" | "ios" | "all" | "web", import("@oclif/core/lib/interfaces").CustomOptions>;
13
+ platform: import("@oclif/core/lib/interfaces").OptionFlag<"android" | "ios" | "web" | "all", import("@oclif/core/lib/interfaces").CustomOptions>;
14
14
  'private-key-path': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
15
  'rollout-percentage': import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
16
16
  'force-end-active-rollout': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
package/build/env.d.ts CHANGED
@@ -20,5 +20,11 @@ declare const _default: {
20
20
  * Comma separated list of feature gate keys of feature gates to evaluate override to false.
21
21
  */
22
22
  featureGateDisable: string | undefined;
23
+ /**
24
+ * Comma separated list of experiment overrides in the form `namespace:param=value`.
25
+ * Overrides apply in every scope, even when analytics is disabled. A namespace with any override
26
+ * returns defaults for its other params and logs no exposure.
27
+ */
28
+ experimentOverride: string | undefined;
23
29
  };
24
30
  export default _default;
package/build/env.js CHANGED
@@ -22,4 +22,10 @@ exports.default = {
22
22
  * Comma separated list of feature gate keys of feature gates to evaluate override to false.
23
23
  */
24
24
  featureGateDisable: process.env.EAS_FG_DISABLE,
25
+ /**
26
+ * Comma separated list of experiment overrides in the form `namespace:param=value`.
27
+ * Overrides apply in every scope, even when analytics is disabled. A namespace with any override
28
+ * returns defaults for its other params and logs no exposure.
29
+ */
30
+ experimentOverride: process.env.EAS_EXPERIMENT_OVERRIDE,
25
31
  };
@@ -0,0 +1,7 @@
1
+ import type { ExposureData, ExposureLogger } from '@expo/experimentation';
2
+ import { Analytics } from '../analytics/AnalyticsManager';
3
+ export declare class AnalyticsExposureLogger implements ExposureLogger<Record<string, any>> {
4
+ private readonly analytics;
5
+ constructor(analytics: Analytics);
6
+ logExposure(data: ExposureData<Record<string, any>>): void;
7
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnalyticsExposureLogger = void 0;
4
+ const AnalyticsManager_1 = require("../analytics/AnalyticsManager");
5
+ class AnalyticsExposureLogger {
6
+ analytics;
7
+ constructor(analytics) {
8
+ this.analytics = analytics;
9
+ }
10
+ logExposure(data) {
11
+ const { variant } = data.params;
12
+ this.analytics.logEvent(AnalyticsManager_1.ExperimentationEvent.EXPERIMENT_VIEWED, {
13
+ experimentName: data.name,
14
+ // Analytics properties cannot be undefined. Fall back to all params when there is no variant.
15
+ variationName: variant !== undefined ? String(variant) : JSON.stringify(data.params),
16
+ // The unit is always a single value (actor ID, account ID, or device ID).
17
+ unit: String(data.unit[0]),
18
+ });
19
+ }
20
+ }
21
+ exports.AnalyticsExposureLogger = AnalyticsExposureLogger;
@@ -0,0 +1,24 @@
1
+ import type { Namespace } from '@expo/experimentation';
2
+ import { ExperimentOverrides } from './ExperimentOverrides';
3
+ export type ExperimentNamespace = {
4
+ getParam<T>(paramName: string, defaultValue: T): T;
5
+ isOverridden: boolean;
6
+ };
7
+ export declare const FALLBACK_NAMESPACE: ExperimentNamespace;
8
+ /** Serves overrides without consulting the real namespace, so no exposure is logged. */
9
+ export declare class OverrideFallbackNamespace implements ExperimentNamespace {
10
+ private readonly namespaceName;
11
+ private readonly overrides;
12
+ readonly isOverridden = true;
13
+ constructor(namespaceName: string, overrides: ExperimentOverrides);
14
+ getParam<T>(paramName: string, defaultValue: T): T;
15
+ }
16
+ /** Returns the default instead of throwing when the library rejects a param on first read. */
17
+ export declare class SafeNamespace implements ExperimentNamespace {
18
+ private readonly namespace;
19
+ private readonly namespaceName;
20
+ readonly isOverridden = false;
21
+ constructor(namespace: Namespace, namespaceName: string);
22
+ getParam<T>(paramName: string, defaultValue: T): T;
23
+ }
24
+ export declare function coerceOverrideValue<T>(overrideValue: string | undefined, defaultValue: T): T;