eas-cli 24.0.0 → 24.1.1

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.
@@ -1,5 +1,10 @@
1
1
  export declare const SIMULATOR_DOTENV_FILE_NAME = ".env.eas-simulator";
2
2
  export declare const EAS_SIMULATOR_SESSION_ID = "EAS_SIMULATOR_SESSION_ID";
3
+ export declare const EAS_SIMULATOR_EGRESS_URL = "EAS_SIMULATOR_EGRESS_URL";
4
+ export declare const EAS_SIMULATOR_EGRESS_TOKEN = "EAS_SIMULATOR_EGRESS_TOKEN";
5
+ export declare const EAS_SIMULATOR_EGRESS_FINGERPRINT = "EAS_SIMULATOR_EGRESS_FINGERPRINT";
6
+ export declare const EAS_SIMULATOR_EGRESS_PORT = "EAS_SIMULATOR_EGRESS_PORT";
7
+ export declare const EAS_SIMULATOR_EGRESS_ALLOW = "EAS_SIMULATOR_EGRESS_ALLOW";
3
8
  export declare const SIMULATOR_DOTENV_FILE_HEADER = "# Do not commit this file.\n# Do not modify these values manually. They are managed by eas-cli.\n# It holds configuration only for the current simulator session.\n\n";
4
9
  export declare function getSimulatorEnvFilePath(projectDir: string): string;
5
10
  export declare function loadSimulatorEnvAsync(projectDir: string): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SIMULATOR_DOTENV_FILE_HEADER = exports.EAS_SIMULATOR_SESSION_ID = exports.SIMULATOR_DOTENV_FILE_NAME = void 0;
3
+ exports.SIMULATOR_DOTENV_FILE_HEADER = exports.EAS_SIMULATOR_EGRESS_ALLOW = exports.EAS_SIMULATOR_EGRESS_PORT = exports.EAS_SIMULATOR_EGRESS_FINGERPRINT = exports.EAS_SIMULATOR_EGRESS_TOKEN = exports.EAS_SIMULATOR_EGRESS_URL = exports.EAS_SIMULATOR_SESSION_ID = exports.SIMULATOR_DOTENV_FILE_NAME = void 0;
4
4
  exports.getSimulatorEnvFilePath = getSimulatorEnvFilePath;
5
5
  exports.loadSimulatorEnvAsync = loadSimulatorEnvAsync;
6
6
  exports.writeSimulatorEnvAsync = writeSimulatorEnvAsync;
@@ -13,6 +13,13 @@ const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const log_1 = tslib_1.__importDefault(require("../log"));
14
14
  exports.SIMULATOR_DOTENV_FILE_NAME = '.env.eas-simulator';
15
15
  exports.EAS_SIMULATOR_SESSION_ID = 'EAS_SIMULATOR_SESSION_ID';
16
+ // Written for sessions started with `--egress local`; read by `eas simulator:egress`.
17
+ exports.EAS_SIMULATOR_EGRESS_URL = 'EAS_SIMULATOR_EGRESS_URL';
18
+ exports.EAS_SIMULATOR_EGRESS_TOKEN = 'EAS_SIMULATOR_EGRESS_TOKEN';
19
+ exports.EAS_SIMULATOR_EGRESS_FINGERPRINT = 'EAS_SIMULATOR_EGRESS_FINGERPRINT';
20
+ exports.EAS_SIMULATOR_EGRESS_PORT = 'EAS_SIMULATOR_EGRESS_PORT';
21
+ // Comma-separated host:port destinations from `--egress-allow`.
22
+ exports.EAS_SIMULATOR_EGRESS_ALLOW = 'EAS_SIMULATOR_EGRESS_ALLOW';
16
23
  exports.SIMULATOR_DOTENV_FILE_HEADER = '# Do not commit this file.\n# Do not modify these values manually. They are managed by eas-cli.\n# It holds configuration only for the current simulator session.\n\n';
17
24
  function getSimulatorEnvFilePath(projectDir) {
18
25
  return path_1.default.join(projectDir, exports.SIMULATOR_DOTENV_FILE_NAME);
@@ -20,6 +27,40 @@ function getSimulatorEnvFilePath(projectDir) {
20
27
  async function loadSimulatorEnvAsync(projectDir) {
21
28
  const simulatorDotenvFilePath = getSimulatorEnvFilePath(projectDir);
22
29
  (0, env_1.loadProjectEnv)(projectDir, { silent: true });
30
+ try {
31
+ const simulatorEnv = (0, dotenv_1.parse)(await fs.readFile(simulatorDotenvFilePath, 'utf8'));
32
+ if (simulatorEnv[exports.EAS_SIMULATOR_SESSION_ID] || simulatorEnv[exports.EAS_SIMULATOR_EGRESS_URL]) {
33
+ // loadEnvFiles never replaces existing variables, even with force: true.
34
+ // Keep this session's credentials and destination policy together rather
35
+ // than combining them with values exported for an older session.
36
+ for (const key of [
37
+ exports.EAS_SIMULATOR_SESSION_ID,
38
+ 'AGENT_DEVICE_DAEMON_BASE_URL',
39
+ 'AGENT_DEVICE_DAEMON_AUTH_TOKEN',
40
+ 'ARGENT_TOOLS_URL',
41
+ 'ARGENT_AUTH_TOKEN',
42
+ 'APPIUM_URL',
43
+ 'APPIUM_CAPS',
44
+ exports.EAS_SIMULATOR_EGRESS_URL,
45
+ exports.EAS_SIMULATOR_EGRESS_TOKEN,
46
+ exports.EAS_SIMULATOR_EGRESS_FINGERPRINT,
47
+ exports.EAS_SIMULATOR_EGRESS_PORT,
48
+ ]) {
49
+ if (simulatorEnv[key] === undefined) {
50
+ delete process.env[key];
51
+ }
52
+ else {
53
+ process.env[key] = simulatorEnv[key];
54
+ }
55
+ }
56
+ process.env[exports.EAS_SIMULATOR_EGRESS_ALLOW] = simulatorEnv[exports.EAS_SIMULATOR_EGRESS_ALLOW] ?? '';
57
+ }
58
+ }
59
+ catch (err) {
60
+ if (!(typeof err === 'object' && err !== null && 'code' in err && err.code === 'ENOENT')) {
61
+ throw err;
62
+ }
63
+ }
23
64
  (0, env_1.loadEnvFiles)([simulatorDotenvFilePath], { force: true });
24
65
  }
25
66
  async function writeSimulatorEnvAsync(projectDir, environmentVariables) {
@@ -13,7 +13,53 @@ export declare const DEVICE_RUN_SESSION_TYPE_BY_FLAG_VALUE: Record<string, Devic
13
13
  export declare function deviceRunSessionTypeToFlagValue(type: DeviceRunSessionType): string;
14
14
  export declare const DEVICE_RUN_SESSION_RESOURCE_CLASS_FLAG_VALUES: Record<DeviceRunSessionResourceClass, string>;
15
15
  export declare const DEVICE_RUN_SESSION_RESOURCE_CLASS_BY_FLAG_VALUE: Record<string, DeviceRunSessionResourceClass>;
16
- export declare function getRemoteSessionEnvironmentVariables(remoteConfig: DeviceRunSessionRemoteConfig): Record<string, string>;
16
+ export type LocalEgressConfig = {
17
+ url: string;
18
+ /** Secret for the tunnel server; the client pairs it with the fixed egress username. */
19
+ token: string;
20
+ fingerprint: string;
21
+ port: number;
22
+ /**
23
+ * Normalized `host:port` destinations on the developer's machine or network
24
+ * that the simulator may reach through the proxy (`--egress-allow`).
25
+ */
26
+ allow: string[];
27
+ };
28
+ export type LocalEgressOptions = {
29
+ egressAllow?: readonly string[];
30
+ /**
31
+ * Whether the calling command runs the egress client itself in the current
32
+ * terminal, as interactive `simulator:start` does. When false the reader must
33
+ * start `eas simulator:egress` in another process.
34
+ */
35
+ egressClientRunsInline?: boolean;
36
+ };
37
+ /**
38
+ * Connection details for the local egress client, present only for sessions
39
+ * started with `--egress local`. `allow` comes from the developer's flags, not
40
+ * from the worker.
41
+ */
42
+ export declare function getLocalEgressConfig(remoteConfig: DeviceRunSessionRemoteConfig, allow?: readonly string[]): LocalEgressConfig | null;
43
+ export type LoopbackForwardPlan = {
44
+ /** Ports the tunnel client forwards on the device host's loopback interface. */
45
+ ports: number[];
46
+ /** Loopback allow entries that stay reachable by name through the proxy only. */
47
+ skipped: string[];
48
+ };
49
+ /**
50
+ * Which `--egress-allow` entries also become loopback port forwards. iOS never
51
+ * sends loopback-literal requests to the system proxy, and Expo CLI rewrites
52
+ * `localhost` to `127.0.0.1` in manifests, so the proxy alone cannot serve a dev
53
+ * server allowed as `localhost:<port>`. For each entry naming `localhost` or
54
+ * `127.0.0.1`, the tunnel client opens a reverse remote that makes
55
+ * `127.0.0.1:<port>` on the device host reach the same port here, like
56
+ * `adb reverse`. The device host only permits unprivileged ports, and the proxy
57
+ * port is already taken by the tunnel server, so those entries are skipped.
58
+ */
59
+ export declare function getLoopbackForwardPlan(allow: readonly string[], proxyPort: number): LoopbackForwardPlan;
60
+ export declare function formatLoopbackForwardNotice({ ports, skipped }: LoopbackForwardPlan): string[];
61
+ export declare function getLocalEgressEnvironmentVariables(egress: LocalEgressConfig | null): Record<string, string>;
62
+ export declare function getRemoteSessionEnvironmentVariables(remoteConfig: DeviceRunSessionRemoteConfig, { egressAllow }?: LocalEgressOptions): Record<string, string>;
17
63
  type RemoteSessionInstructionsConfigType = 'env' | 'dotenv';
18
64
  /**
19
65
  * Preview link for a session. A gated serve-sim needs the session token, and a browser cannot send
@@ -26,5 +72,5 @@ export declare function formatPreviewUrl(url: string, token: string | null | und
26
72
  * it has to know to combine.
27
73
  */
28
74
  export declare function sanitizeRemoteConfigForJson(remoteConfig: DeviceRunSessionRemoteConfig): DeviceRunSessionRemoteConfig;
29
- export declare function formatRemoteSessionInstructions(remoteConfig: DeviceRunSessionRemoteConfig, configType: RemoteSessionInstructionsConfigType): string;
75
+ export declare function formatRemoteSessionInstructions(remoteConfig: DeviceRunSessionRemoteConfig, configType: RemoteSessionInstructionsConfigType, { egressAllow, egressClientRunsInline }?: LocalEgressOptions): string;
30
76
  export {};
@@ -3,12 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEVICE_RUN_SESSION_RESOURCE_CLASS_BY_FLAG_VALUE = exports.DEVICE_RUN_SESSION_RESOURCE_CLASS_FLAG_VALUES = exports.DEVICE_RUN_SESSION_TYPE_BY_FLAG_VALUE = exports.DEVICE_RUN_SESSION_TYPE_FLAG_VALUES = exports.EAS_SIMULATOR_WAITLIST_URL = void 0;
4
4
  exports.formatSimulatorUnavailableMessage = formatSimulatorUnavailableMessage;
5
5
  exports.deviceRunSessionTypeToFlagValue = deviceRunSessionTypeToFlagValue;
6
+ exports.getLocalEgressConfig = getLocalEgressConfig;
7
+ exports.getLoopbackForwardPlan = getLoopbackForwardPlan;
8
+ exports.formatLoopbackForwardNotice = formatLoopbackForwardNotice;
9
+ exports.getLocalEgressEnvironmentVariables = getLocalEgressEnvironmentVariables;
6
10
  exports.getRemoteSessionEnvironmentVariables = getRemoteSessionEnvironmentVariables;
7
11
  exports.formatPreviewUrl = formatPreviewUrl;
8
12
  exports.sanitizeRemoteConfigForJson = sanitizeRemoteConfigForJson;
9
13
  exports.formatRemoteSessionInstructions = formatRemoteSessionInstructions;
10
14
  const generated_1 = require("../graphql/generated");
11
15
  const log_1 = require("../log");
16
+ const env_1 = require("./env");
12
17
  /** Landing page where accounts without access can request it. */
13
18
  exports.EAS_SIMULATOR_WAITLIST_URL = 'https://expo.dev/services/simulators';
14
19
  /**
@@ -39,7 +44,84 @@ exports.DEVICE_RUN_SESSION_RESOURCE_CLASS_FLAG_VALUES = {
39
44
  [generated_1.DeviceRunSessionResourceClass.Medium]: 'medium',
40
45
  };
41
46
  exports.DEVICE_RUN_SESSION_RESOURCE_CLASS_BY_FLAG_VALUE = Object.fromEntries(Object.entries(exports.DEVICE_RUN_SESSION_RESOURCE_CLASS_FLAG_VALUES).map(([resourceClass, value]) => [value, resourceClass]));
42
- function getRemoteSessionEnvironmentVariables(remoteConfig) {
47
+ /**
48
+ * Connection details for the local egress client, present only for sessions
49
+ * started with `--egress local`. `allow` comes from the developer's flags, not
50
+ * from the worker.
51
+ */
52
+ function getLocalEgressConfig(remoteConfig, allow = []) {
53
+ const { egressUrl, egressToken, egressFingerprint, egressPort } = remoteConfig;
54
+ if (!egressUrl || !egressToken || !egressFingerprint || egressPort == null) {
55
+ return null;
56
+ }
57
+ return {
58
+ url: egressUrl,
59
+ token: egressToken,
60
+ fingerprint: egressFingerprint,
61
+ port: egressPort,
62
+ allow: [...allow],
63
+ };
64
+ }
65
+ /**
66
+ * Which `--egress-allow` entries also become loopback port forwards. iOS never
67
+ * sends loopback-literal requests to the system proxy, and Expo CLI rewrites
68
+ * `localhost` to `127.0.0.1` in manifests, so the proxy alone cannot serve a dev
69
+ * server allowed as `localhost:<port>`. For each entry naming `localhost` or
70
+ * `127.0.0.1`, the tunnel client opens a reverse remote that makes
71
+ * `127.0.0.1:<port>` on the device host reach the same port here, like
72
+ * `adb reverse`. The device host only permits unprivileged ports, and the proxy
73
+ * port is already taken by the tunnel server, so those entries are skipped.
74
+ */
75
+ function getLoopbackForwardPlan(allow, proxyPort) {
76
+ const ports = new Set();
77
+ const skipped = [];
78
+ for (const destination of allow) {
79
+ const match = /^(?:localhost|127\.0\.0\.1):(\d+)$/.exec(destination);
80
+ if (!match) {
81
+ continue;
82
+ }
83
+ const port = Number(match[1]);
84
+ if (port < 1024 || port === proxyPort) {
85
+ skipped.push(destination);
86
+ continue;
87
+ }
88
+ ports.add(port);
89
+ }
90
+ return { ports: [...ports].sort((a, b) => a - b), skipped };
91
+ }
92
+ function formatLoopbackForwardNotice({ ports, skipped }) {
93
+ const lines = [];
94
+ if (ports.length > 0) {
95
+ const addresses = ports.map(port => `127.0.0.1:${port}`).join(', ');
96
+ lines.push(`${addresses} in the simulator ${ports.length === 1 ? 'reaches' : 'reach'} the same ` +
97
+ `${ports.length === 1 ? 'port' : 'ports'} on this machine (like adb reverse), so dev server ` +
98
+ 'URLs that use 127.0.0.1 work.');
99
+ }
100
+ if (skipped.length > 0) {
101
+ lines.push(`${skipped.join(', ')} ${skipped.length === 1 ? 'is' : 'are'} reachable by name only: ` +
102
+ 'privileged ports and the egress proxy port are not forwarded to 127.0.0.1 in the simulator.');
103
+ }
104
+ return lines;
105
+ }
106
+ function getLocalEgressEnvironmentVariables(egress) {
107
+ if (!egress) {
108
+ return {};
109
+ }
110
+ return {
111
+ [env_1.EAS_SIMULATOR_EGRESS_URL]: egress.url,
112
+ [env_1.EAS_SIMULATOR_EGRESS_TOKEN]: egress.token,
113
+ [env_1.EAS_SIMULATOR_EGRESS_FINGERPRINT]: egress.fingerprint,
114
+ [env_1.EAS_SIMULATOR_EGRESS_PORT]: String(egress.port),
115
+ [env_1.EAS_SIMULATOR_EGRESS_ALLOW]: egress.allow.join(','),
116
+ };
117
+ }
118
+ function getRemoteSessionEnvironmentVariables(remoteConfig, { egressAllow } = {}) {
119
+ return {
120
+ ...getControllerEnvironmentVariables(remoteConfig),
121
+ ...getLocalEgressEnvironmentVariables(getLocalEgressConfig(remoteConfig, egressAllow)),
122
+ };
123
+ }
124
+ function getControllerEnvironmentVariables(remoteConfig) {
43
125
  switch (remoteConfig.__typename) {
44
126
  case 'AgentDeviceRunSessionRemoteConfig':
45
127
  return {
@@ -98,10 +180,46 @@ function sanitizeRemoteConfigForJson(remoteConfig) {
98
180
  }
99
181
  }
100
182
  }
101
- function formatRemoteSessionInstructions(remoteConfig, configType) {
183
+ function formatRemoteSessionInstructions(remoteConfig, configType, { egressAllow, egressClientRunsInline = false } = {}) {
184
+ const instructions = formatControllerInstructions(remoteConfig, configType);
185
+ const egress = getLocalEgressConfig(remoteConfig, egressAllow);
186
+ if (!egress) {
187
+ return instructions;
188
+ }
189
+ const egressCommand = configType === 'env' ? 'eas simulator:egress --config-type env' : 'eas simulator:egress';
190
+ return [
191
+ instructions,
192
+ '',
193
+ '🔀 This session can route proxied HTTP(S) requests through this machine.',
194
+ ...(configType === 'env'
195
+ ? Object.entries(getLocalEgressEnvironmentVariables(egress)).map(([key, value]) => `export ${key}='${value}'`)
196
+ : []),
197
+ ...(egressClientRunsInline
198
+ ? [
199
+ 'The egress client runs in this terminal for the life of the session. If this process exits, reconnect the tunnel from another shell with:',
200
+ '',
201
+ egressCommand,
202
+ ]
203
+ : [
204
+ 'Run the egress client to connect the tunnel:',
205
+ '',
206
+ egressCommand,
207
+ '',
208
+ 'Keep it running for the life of the session.',
209
+ ]),
210
+ ...(egress.allow.length > 0
211
+ ? [
212
+ '',
213
+ `The simulator may reach ${egress.allow.join(', ')} on this machine's network.`,
214
+ ...formatLoopbackForwardNotice(getLoopbackForwardPlan(egress.allow, egress.port)),
215
+ ]
216
+ : []),
217
+ ].join('\n');
218
+ }
219
+ function formatControllerInstructions(remoteConfig, configType) {
102
220
  switch (remoteConfig.__typename) {
103
221
  case 'AgentDeviceRunSessionRemoteConfig': {
104
- const environmentVariables = getRemoteSessionEnvironmentVariables(remoteConfig);
222
+ const environmentVariables = getControllerEnvironmentVariables(remoteConfig);
105
223
  const lines = configType === 'dotenv'
106
224
  ? [
107
225
  '🔑 Run the following to use agent-device with the simulator:',
@@ -119,7 +237,7 @@ function formatRemoteSessionInstructions(remoteConfig, configType) {
119
237
  return lines.join('\n');
120
238
  }
121
239
  case 'ArgentRunSessionRemoteConfig': {
122
- const environmentVariables = getRemoteSessionEnvironmentVariables(remoteConfig);
240
+ const environmentVariables = getControllerEnvironmentVariables(remoteConfig);
123
241
  const lines = configType === 'dotenv'
124
242
  ? [
125
243
  '🔑 Run the following to link your local Argent client to this simulator session:',
@@ -149,7 +267,7 @@ function formatRemoteSessionInstructions(remoteConfig, configType) {
149
267
  return lines.join('\n');
150
268
  }
151
269
  case 'AppiumRunSessionRemoteConfig': {
152
- const environmentVariables = getRemoteSessionEnvironmentVariables(remoteConfig);
270
+ const environmentVariables = getControllerEnvironmentVariables(remoteConfig);
153
271
  const lines = configType === 'dotenv'
154
272
  ? [
155
273
  'Run an Appium client with the simulator session environment:',