react-native-update-cli 2.22.7 → 2.22.8

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 (59) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/cli.json +5 -0
  4. package/lib/api.d.ts +7 -0
  5. package/lib/api.js +106 -38
  6. package/lib/app.js +3 -2
  7. package/lib/bin.js +16 -2
  8. package/lib/bundle-runner.d.ts +11 -4
  9. package/lib/bundle-runner.js +176 -90
  10. package/lib/bundle.d.ts +1 -0
  11. package/lib/bundle.js +2 -0
  12. package/lib/diff.d.ts +9 -0
  13. package/lib/diff.js +162 -120
  14. package/lib/locales/en.d.ts +1 -0
  15. package/lib/locales/en.js +1 -0
  16. package/lib/locales/zh.d.ts +1 -0
  17. package/lib/locales/zh.js +1 -0
  18. package/lib/package.d.ts +7 -3
  19. package/lib/package.js +22 -12
  20. package/lib/types.d.ts +2 -0
  21. package/lib/utils/dep-versions.d.ts +7 -0
  22. package/lib/utils/dep-versions.js +66 -31
  23. package/lib/utils/hbcTransform.d.ts +21 -0
  24. package/lib/utils/hbcTransform.js +146 -5
  25. package/lib/utils/hermes-base.d.ts +21 -4
  26. package/lib/utils/hermes-base.js +146 -37
  27. package/lib/utils/http-helper.d.ts +6 -1
  28. package/lib/utils/http-helper.js +23 -11
  29. package/lib/utils/index.d.ts +30 -1
  30. package/lib/utils/index.js +98 -24
  31. package/lib/utils/latest-version/index.d.ts +11 -8
  32. package/lib/utils/latest-version/index.js +63 -18
  33. package/lib/utils/zip-entries.js +20 -15
  34. package/lib/utils/zip-options.d.ts +2 -0
  35. package/lib/utils/zip-options.js +9 -4
  36. package/lib/utils/zip-range.d.ts +47 -15
  37. package/lib/utils/zip-range.js +192 -83
  38. package/lib/versions.js +19 -9
  39. package/package.json +11 -11
  40. package/src/api.ts +126 -46
  41. package/src/app.ts +3 -2
  42. package/src/bin.ts +17 -2
  43. package/src/bundle-runner.ts +225 -113
  44. package/src/bundle.ts +3 -0
  45. package/src/diff.ts +210 -153
  46. package/src/locales/en.ts +2 -0
  47. package/src/locales/zh.ts +2 -0
  48. package/src/package.ts +26 -13
  49. package/src/types.ts +2 -0
  50. package/src/utils/dep-versions.ts +76 -33
  51. package/src/utils/hbcTransform.ts +194 -5
  52. package/src/utils/hermes-base.ts +156 -45
  53. package/src/utils/http-helper.ts +24 -13
  54. package/src/utils/index.ts +136 -26
  55. package/src/utils/latest-version/index.ts +82 -29
  56. package/src/utils/zip-entries.ts +18 -16
  57. package/src/utils/zip-options.ts +8 -3
  58. package/src/utils/zip-range.ts +244 -88
  59. package/src/versions.ts +17 -7
package/src/api.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import filesizeParser from 'filesize-parser';
2
- import FormData from 'form-data';
3
2
  import fs from 'fs';
4
3
  import fetch from 'node-fetch';
5
4
  import path from 'path';
6
- import ProgressBar from 'progress';
5
+ import type ProgressBar from 'progress';
7
6
  import packageJson from '../package.json';
8
7
  import type { Package, Session } from './types';
9
8
  import { credentialFile, IS_CRESC, pricingPageUrl } from './utils/constants';
@@ -128,7 +127,7 @@ function isProxyRelatedError(error: unknown): boolean {
128
127
  }
129
128
 
130
129
  async function query(url: string, options: RuntimeRequestInit) {
131
- const baseUrl = await getBaseUrl;
130
+ const baseUrl = await getBaseUrl();
132
131
  const fullUrl = `${baseUrl}${url}`;
133
132
  let resp: RuntimeResponse;
134
133
  try {
@@ -209,6 +208,99 @@ export const post = queryWithBody('POST');
209
208
  export const put = queryWithBody('PUT');
210
209
  export const doDelete = queryWithBody('DELETE');
211
210
 
211
+ // Upload deadline: generous for a slow link (1 s/MB on top of a 30 s base,
212
+ // never below 60 s) but bounded, so a stalled connection cannot hang a CI job
213
+ // forever. The bar keeps ticking while bytes flow; the deadline is absolute.
214
+ const UPLOAD_TIMEOUT_BASE_MS = 30_000;
215
+ const UPLOAD_TIMEOUT_PER_MB_MS = 1_000;
216
+ const UPLOAD_TIMEOUT_MIN_MS = 60_000;
217
+ const UPLOAD_MAX_RETRIES = 1;
218
+
219
+ export function uploadTimeoutMs(fileSize: number): number {
220
+ const megabytes = Math.ceil(Math.max(0, fileSize) / 1048576);
221
+ return Math.max(
222
+ UPLOAD_TIMEOUT_MIN_MS,
223
+ UPLOAD_TIMEOUT_BASE_MS + megabytes * UPLOAD_TIMEOUT_PER_MB_MS,
224
+ );
225
+ }
226
+
227
+ const TRANSIENT_UPLOAD_ERROR_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EPIPE'];
228
+
229
+ /**
230
+ * A network-level failure worth one more attempt: a reset/timed-out/broken
231
+ * pipe connection, or our own deadline abort. HTTP responses (4xx/5xx) never
232
+ * get here — they are surfaced as-is.
233
+ */
234
+ export function isTransientUploadError(error: unknown): boolean {
235
+ if (!error || typeof error !== 'object') {
236
+ return false;
237
+ }
238
+ const { name, code, type, message } = error as {
239
+ name?: string;
240
+ code?: string;
241
+ type?: string;
242
+ message?: string;
243
+ };
244
+ if (name === 'AbortError' || type === 'aborted' || code === 'ABORT_ERR') {
245
+ return true;
246
+ }
247
+ const text = `${code ?? ''} ${message ?? ''}`;
248
+ return TRANSIENT_UPLOAD_ERROR_CODES.some((c) => text.includes(c));
249
+ }
250
+
251
+ class UploadTimeoutError extends Error {
252
+ constructor(timeoutMs: number) {
253
+ super(`Upload timed out after ${Math.round(timeoutMs / 1000)}s`);
254
+ this.name = 'UploadTimeoutError';
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Send the file with a size-scaled deadline and one retry on a transient
260
+ * network error. `buildRequest` is invoked per attempt with a fresh file
261
+ * stream (a consumed stream/form cannot be replayed).
262
+ */
263
+ async function sendUpload(
264
+ fn: string,
265
+ realUrl: string,
266
+ fileSize: number,
267
+ bar: ProgressBar,
268
+ buildRequest: (fileStream: fs.ReadStream) => fetch.RequestInit,
269
+ ): Promise<fetch.Response> {
270
+ const timeoutMs = uploadTimeoutMs(fileSize);
271
+ for (let attempt = 0; ; attempt++) {
272
+ const controller = new AbortController();
273
+ let timedOut = false;
274
+ const timer = setTimeout(() => {
275
+ timedOut = true;
276
+ controller.abort();
277
+ }, timeoutMs);
278
+ const fileStream = fs.createReadStream(fn);
279
+ fileStream.on('data', (data) => {
280
+ bar.tick(data.length);
281
+ });
282
+ try {
283
+ return await fetch(realUrl, {
284
+ ...buildRequest(fileStream),
285
+ signal: controller.signal,
286
+ });
287
+ } catch (rawError) {
288
+ fileStream.destroy();
289
+ const error = timedOut ? new UploadTimeoutError(timeoutMs) : rawError;
290
+ if (attempt < UPLOAD_MAX_RETRIES && isTransientUploadError(error)) {
291
+ const reason = error instanceof Error ? error.message : String(error);
292
+ console.warn(`\nUpload interrupted (${reason}), retrying...`);
293
+ // restart the bar from zero for the second pass
294
+ bar.curr = 0;
295
+ continue;
296
+ }
297
+ throw error;
298
+ } finally {
299
+ clearTimeout(timer);
300
+ }
301
+ }
302
+ }
303
+
212
304
  export async function uploadFile(
213
305
  fn: string,
214
306
  key?: string,
@@ -249,21 +341,29 @@ export async function uploadFile(
249
341
  );
250
342
  }
251
343
 
252
- const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
344
+ // progress/form-data are only needed here; keep them off the startup path
345
+ const ProgressBarImpl = require('progress') as typeof import('progress');
346
+ const bar = new ProgressBarImpl(' Uploading [:bar] :percent :etas', {
253
347
  complete: '=',
254
348
  incomplete: ' ',
255
349
  total: fileSize,
256
350
  });
257
351
 
352
+ const rethrowUploadError = (error: unknown): never => {
353
+ if (isProxyRelatedError(error)) {
354
+ const rawMessage = error instanceof Error ? error.message : String(error);
355
+ throw new Error(
356
+ `${rawMessage}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
357
+ );
358
+ }
359
+ throw createRequestError(error, realUrl);
360
+ };
361
+
258
362
  // 自托管节点的 s3 直传:服务端下发预签名 PUT,字节直达用户的对象存储
259
363
  if (resp.method === 'PUT') {
260
- const fileStream = fs.createReadStream(fn);
261
- fileStream.on('data', (data) => {
262
- bar.tick(data.length);
263
- });
264
364
  let putRes: fetch.Response;
265
365
  try {
266
- putRes = await fetch(realUrl, {
366
+ putRes = await sendUpload(fn, realUrl, fileSize, bar, (fileStream) => ({
267
367
  method: 'PUT',
268
368
  body: fileStream,
269
369
  // 预签名 PUT 不接受 chunked 传输,必须显式声明长度
@@ -271,16 +371,9 @@ export async function uploadFile(
271
371
  'content-length': String(fileSize),
272
372
  ...(resp.headers || {}),
273
373
  },
274
- });
374
+ }));
275
375
  } catch (error) {
276
- if (isProxyRelatedError(error)) {
277
- const rawMessage =
278
- error instanceof Error ? error.message : String(error);
279
- throw new Error(
280
- `${rawMessage}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
281
- );
282
- }
283
- throw createRequestError(error, realUrl);
376
+ return rethrowUploadError(error);
284
377
  }
285
378
  if (putRes.status > 299) {
286
379
  throw createRequestError(
@@ -291,38 +384,25 @@ export async function uploadFile(
291
384
  return { hash: resp.key };
292
385
  }
293
386
 
294
- const form = new FormData();
295
-
296
- for (const [k, v] of Object.entries(formData)) {
297
- form.append(k, v);
298
- }
299
- const fileStream = fs.createReadStream(fn);
300
- fileStream.on('data', (data) => {
301
- bar.tick(data.length);
302
- });
303
-
304
- if (key) {
305
- form.append('key', key);
306
- }
307
- form.append('file', fileStream);
308
- // form.append('file', fileStream, {
309
- // contentType: 'application/octet-stream',
310
- // });
311
-
387
+ const FormData = require('form-data') as typeof import('form-data');
312
388
  let res: fetch.Response;
313
389
  try {
314
- res = await fetch(realUrl, {
315
- method: 'POST',
316
- body: form,
390
+ res = await sendUpload(fn, realUrl, fileSize, bar, (fileStream) => {
391
+ const form = new FormData();
392
+ for (const [k, v] of Object.entries(formData)) {
393
+ form.append(k, v);
394
+ }
395
+ if (key) {
396
+ form.append('key', key);
397
+ }
398
+ form.append('file', fileStream);
399
+ // form.append('file', fileStream, {
400
+ // contentType: 'application/octet-stream',
401
+ // });
402
+ return { method: 'POST', body: form };
317
403
  });
318
404
  } catch (error) {
319
- if (isProxyRelatedError(error)) {
320
- const rawMessage = error instanceof Error ? error.message : String(error);
321
- throw new Error(
322
- `${rawMessage}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
323
- );
324
- }
325
- throw createRequestError(error, realUrl);
405
+ return rethrowUploadError(error);
326
406
  }
327
407
 
328
408
  if (res.status > 299) {
package/src/app.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import fs from 'fs';
2
- import Table from 'tty-table';
3
2
  import { doDelete, get, post } from './api';
4
3
  import type { Platform } from './types';
5
- import { question } from './utils';
4
+ import { loadTtyTable, question } from './utils';
6
5
  import { t } from './utils/i18n';
7
6
 
8
7
  interface AppSummary {
@@ -70,6 +69,8 @@ export async function listApp(platform: Platform | '' = '') {
70
69
  rows.push([app.id, app.name, app.platform]);
71
70
  }
72
71
 
72
+ // tty-table is ~25 ms to load; only pay for it when a table is rendered
73
+ const Table = loadTtyTable();
73
74
  console.log(Table(header, rows).render());
74
75
 
75
76
  console.log(`\n${t('totalApps', { count: list.length, platform })}`);
package/src/bin.ts CHANGED
@@ -57,10 +57,21 @@ const commandHandlers: Record<string, CliCommandHandler> = {
57
57
  };
58
58
 
59
59
  async function run() {
60
- await printVersionCommand();
61
- if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
60
+ const versionOnly =
61
+ process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version';
62
+ // The registry check for newer versions runs alongside the command (from a
63
+ // 1-day cache when possible) and only ever delays `-v`/`version` itself; its
64
+ // hint is printed once the command is done, or at exit for commands that
65
+ // exit on their own.
66
+ const versionCheck = await printVersionCommand({ wait: versionOnly });
67
+ if (versionOnly) {
62
68
  process.exit();
63
69
  }
70
+ process.on('exit', (code) => {
71
+ if (code === 0) {
72
+ versionCheck.printHints();
73
+ }
74
+ });
64
75
 
65
76
  const argv: CliArgv = require('cli-arguments').parse(require('../cli.json'));
66
77
  global.NO_INTERACTIVE =
@@ -79,6 +90,10 @@ async function run() {
79
90
  } else if (commandHandlers[argv.command]) {
80
91
  const handler = commandHandlers[argv.command];
81
92
  await handler(argv);
93
+ // a check still in flight (cold cache) gets a short grace period; the
94
+ // registry request itself is unref'd, so exiting never waits on it
95
+ await versionCheck.settle(500);
96
+ versionCheck.printHints();
82
97
  } else {
83
98
  throw new Error(t('unknownCommand', { command: argv.command }));
84
99
  }