eas-cli 22.0.0 → 22.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.
@@ -70,6 +70,11 @@ exports.DeviceRunSessionQuery = {
70
70
  toolsAuthToken
71
71
  webPreviewUrl
72
72
  }
73
+ ... on AppiumRunSessionRemoteConfig {
74
+ appiumUrl
75
+ capabilities
76
+ webPreviewUrl
77
+ }
73
78
  ... on ServeSimRunSessionRemoteConfig {
74
79
  previewUrl
75
80
  }
@@ -4,4 +4,4 @@ export declare const SIMULATOR_DOTENV_FILE_HEADER = "# Do not commit this file.\
4
4
  export declare function getSimulatorEnvFilePath(projectDir: string): string;
5
5
  export declare function loadSimulatorEnvAsync(projectDir: string): Promise<void>;
6
6
  export declare function writeSimulatorEnvAsync(projectDir: string, environmentVariables: Record<string, string>): Promise<void>;
7
- export declare function resetSimulatorEnvAsync(projectDir: string): Promise<void>;
7
+ export declare function resetSimulatorEnvAsync(projectDir: string, expectedDeviceRunSessionId: string): Promise<void>;
@@ -7,8 +7,10 @@ exports.writeSimulatorEnvAsync = writeSimulatorEnvAsync;
7
7
  exports.resetSimulatorEnvAsync = resetSimulatorEnvAsync;
8
8
  const tslib_1 = require("tslib");
9
9
  const env_1 = require("@expo/env");
10
+ const dotenv_1 = require("dotenv");
10
11
  const fs = tslib_1.__importStar(require("fs-extra"));
11
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
+ const log_1 = tslib_1.__importDefault(require("../log"));
12
14
  exports.SIMULATOR_DOTENV_FILE_NAME = '.env.eas-simulator';
13
15
  exports.EAS_SIMULATOR_SESSION_ID = 'EAS_SIMULATOR_SESSION_ID';
14
16
  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';
@@ -24,14 +26,22 @@ async function writeSimulatorEnvAsync(projectDir, environmentVariables) {
24
26
  const simulatorDotenvFilePath = getSimulatorEnvFilePath(projectDir);
25
27
  const simulatorDotenvContent = exports.SIMULATOR_DOTENV_FILE_HEADER +
26
28
  Object.entries(environmentVariables)
27
- .map(([key, value]) => `${key}=${JSON.stringify(value)}`)
29
+ .map(([key, value]) => `${key}='${value}'`)
28
30
  .join('\n') +
29
31
  '\n';
30
32
  await fs.writeFile(simulatorDotenvFilePath, simulatorDotenvContent);
31
33
  }
32
- async function resetSimulatorEnvAsync(projectDir) {
34
+ async function resetSimulatorEnvAsync(projectDir, expectedDeviceRunSessionId) {
33
35
  const simulatorDotenvFilePath = getSimulatorEnvFilePath(projectDir);
34
36
  try {
37
+ const currentEnv = (0, dotenv_1.parse)(await fs.readFile(simulatorDotenvFilePath, 'utf8'));
38
+ if (currentEnv[exports.EAS_SIMULATOR_SESSION_ID] !== expectedDeviceRunSessionId) {
39
+ // The file was overwritten by a newer simulator session, so it is no longer
40
+ // ours to reset. This is expected when sessions overlap; log at debug level
41
+ // for troubleshooting without surfacing noise during normal use.
42
+ log_1.default.debug(`Skipping ${exports.SIMULATOR_DOTENV_FILE_NAME} reset: it belongs to simulator session ${currentEnv[exports.EAS_SIMULATOR_SESSION_ID] ?? '(unknown)'}, not ${expectedDeviceRunSessionId}.`);
43
+ return;
44
+ }
35
45
  await fs.writeFile(simulatorDotenvFilePath, exports.SIMULATOR_DOTENV_FILE_HEADER, { flag: 'r+' });
36
46
  await fs.truncate(simulatorDotenvFilePath, Buffer.byteLength(exports.SIMULATOR_DOTENV_FILE_HEADER));
37
47
  }
@@ -23,6 +23,7 @@ function formatSimulatorUnavailableMessage(accountName) {
23
23
  // so adding a new enum value in codegen fails the build until it is wired up here.
24
24
  exports.DEVICE_RUN_SESSION_TYPE_FLAG_VALUES = {
25
25
  [generated_1.DeviceRunSessionType.AgentDevice]: 'agent-device',
26
+ [generated_1.DeviceRunSessionType.Appium]: 'appium',
26
27
  [generated_1.DeviceRunSessionType.Argent]: 'argent',
27
28
  [generated_1.DeviceRunSessionType.ServeSim]: 'serve-sim',
28
29
  };
@@ -42,6 +43,11 @@ function getRemoteSessionEnvironmentVariables(remoteConfig) {
42
43
  ARGENT_TOOLS_URL: remoteConfig.toolsUrl,
43
44
  ...(remoteConfig.toolsAuthToken ? { ARGENT_AUTH_TOKEN: remoteConfig.toolsAuthToken } : {}),
44
45
  };
46
+ case 'AppiumRunSessionRemoteConfig':
47
+ return {
48
+ APPIUM_URL: remoteConfig.appiumUrl,
49
+ APPIUM_CAPS: JSON.stringify(remoteConfig.capabilities),
50
+ };
45
51
  case 'ServeSimRunSessionRemoteConfig':
46
52
  return {};
47
53
  }
@@ -96,6 +102,26 @@ function formatRemoteSessionInstructions(remoteConfig, configType) {
96
102
  }
97
103
  return lines.join('\n');
98
104
  }
105
+ case 'AppiumRunSessionRemoteConfig': {
106
+ const environmentVariables = getRemoteSessionEnvironmentVariables(remoteConfig);
107
+ const lines = configType === 'dotenv'
108
+ ? [
109
+ 'Run an Appium client with the simulator session environment:',
110
+ '',
111
+ 'eas simulator:exec <appium-client> [args...]',
112
+ ]
113
+ : [
114
+ 'Run the following in your shell to attach an Appium client to this session:',
115
+ '',
116
+ ...Object.entries(environmentVariables).map(([key, value]) => `export ${key}='${value}'`),
117
+ '',
118
+ '<appium-client> [args...]',
119
+ ];
120
+ if (remoteConfig.webPreviewUrl) {
121
+ lines.push('', 'Open the iOS simulator preview:', '', remoteConfig.webPreviewUrl);
122
+ }
123
+ return lines.join('\n');
124
+ }
99
125
  case 'ServeSimRunSessionRemoteConfig':
100
126
  return [
101
127
  '🌐 Open the following URL in your browser to access the simulator:',
@@ -20,3 +20,8 @@ export declare function uploadAppScopedFileAtPathToGCSAsync(graphqlClient: ExpoG
20
20
  handleProgressEvent?: ProgressHandler;
21
21
  }): Promise<string>;
22
22
  export declare function uploadWithPresignedPostWithRetryAsync(file: string, presignedPost: PresignedPost, onAssetUploadBegin: () => void): Promise<Response>;
23
+ /**
24
+ * Computes the base64-encoded MD5 checksum of a file, the format GCS expects
25
+ * in the `Content-MD5` request header.
26
+ */
27
+ export declare function computeFileMd5Base64Async(file: string): Promise<string>;
package/build/uploads.js CHANGED
@@ -4,7 +4,9 @@ exports.uploadFileAtPathToGCSAsync = uploadFileAtPathToGCSAsync;
4
4
  exports.uploadAccountScopedFileAtPathToGCSAsync = uploadAccountScopedFileAtPathToGCSAsync;
5
5
  exports.uploadAppScopedFileAtPathToGCSAsync = uploadAppScopedFileAtPathToGCSAsync;
6
6
  exports.uploadWithPresignedPostWithRetryAsync = uploadWithPresignedPostWithRetryAsync;
7
+ exports.computeFileMd5Base64Async = computeFileMd5Base64Async;
7
8
  const tslib_1 = require("tslib");
9
+ const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
8
10
  const form_data_1 = tslib_1.__importDefault(require("form-data"));
9
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
10
12
  const promise_retry_1 = tslib_1.__importDefault(require("promise-retry"));
@@ -78,12 +80,18 @@ async function uploadWithPresignedPostAsync(file, presignedPost) {
78
80
  async function uploadWithSignedUrlWithProgressAsync(file, signedUrl, handleProgressEvent) {
79
81
  const fileStat = await fs_extra_1.default.stat(file);
80
82
  const fileSize = fileStat.size;
83
+ if (fileSize === 0) {
84
+ throw new Error(`Failed to upload ${file}: the file is empty. It may not have been written correctly. Retry the command, and report this issue if it persists.`);
85
+ }
86
+ const contentMd5 = await computeFileMd5Base64Async(file);
81
87
  const readStream = fs_extra_1.default.createReadStream(file);
82
88
  const uploadPromise = (0, fetch_1.default)(signedUrl.url, {
83
89
  method: 'PUT',
84
90
  body: readStream,
85
91
  headers: {
86
92
  ...signedUrl.headers,
93
+ 'Content-Length': String(fileSize), // make GCS reject the request if the file size changes during the upload
94
+ 'Content-MD5': contentMd5, // make GCS reject the request if the uploaded bytes do not match this checksum
87
95
  },
88
96
  });
89
97
  let currentSize = 0;
@@ -99,6 +107,9 @@ async function uploadWithSignedUrlWithProgressAsync(file, signedUrl, handleProgr
99
107
  });
100
108
  try {
101
109
  const response = await uploadPromise;
110
+ if (currentSize !== fileSize) {
111
+ throw new Error(`Failed to upload ${file}: sent ${currentSize} of ${fileSize} bytes. The file may have changed during the upload. Retry the command, and report this issue if it persists.`);
112
+ }
102
113
  handleProgressEvent({ isComplete: true });
103
114
  return response;
104
115
  }
@@ -107,3 +118,14 @@ async function uploadWithSignedUrlWithProgressAsync(file, signedUrl, handleProgr
107
118
  throw error;
108
119
  }
109
120
  }
121
+ /**
122
+ * Computes the base64-encoded MD5 checksum of a file, the format GCS expects
123
+ * in the `Content-MD5` request header.
124
+ */
125
+ async function computeFileMd5Base64Async(file) {
126
+ const hash = node_crypto_1.default.createHash('md5');
127
+ for await (const chunk of fs_extra_1.default.createReadStream(file)) {
128
+ hash.update(chunk);
129
+ }
130
+ return hash.digest('base64');
131
+ }