react-native-update-cli 2.29.0 → 2.29.2

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 (85) hide show
  1. package/lib/account.js +2 -4
  2. package/lib/api.d.ts +1 -1
  3. package/lib/api.js +35 -73
  4. package/lib/app.js +13 -27
  5. package/lib/auto-update.d.ts +1 -1
  6. package/lib/auto-update.js +6 -16
  7. package/lib/bin.js +4 -6
  8. package/lib/bundle-pack.js +26 -60
  9. package/lib/bundle-runner.js +89 -119
  10. package/lib/bundle.js +18 -26
  11. package/lib/diff.js +43 -133
  12. package/lib/locales/en.d.ts +0 -10
  13. package/lib/locales/en.js +0 -10
  14. package/lib/locales/zh.d.ts +0 -10
  15. package/lib/locales/zh.js +0 -10
  16. package/lib/native-package.js +27 -99
  17. package/lib/package.d.ts +6 -1
  18. package/lib/package.js +56 -108
  19. package/lib/provider.js +3 -5
  20. package/lib/symbolicate.js +1 -16
  21. package/lib/utils/add-gitignore.js +0 -1
  22. package/lib/utils/app-info-parser/aab.d.ts +5 -22
  23. package/lib/utils/app-info-parser/aab.js +89 -226
  24. package/lib/utils/app-info-parser/apk.d.ts +12 -13
  25. package/lib/utils/app-info-parser/apk.js +28 -78
  26. package/lib/utils/app-info-parser/ipa.d.ts +2 -14
  27. package/lib/utils/app-info-parser/ipa.js +9 -70
  28. package/lib/utils/app-info-parser/resource-finder.d.ts +1 -34
  29. package/lib/utils/app-info-parser/resource-finder.js +95 -234
  30. package/lib/utils/app-info-parser/xml-parser/binary.d.ts +6 -55
  31. package/lib/utils/app-info-parser/xml-parser/binary.js +152 -556
  32. package/lib/utils/app-info-parser/zip.d.ts +6 -24
  33. package/lib/utils/app-info-parser/zip.js +19 -86
  34. package/lib/utils/check-plugin.d.ts +7 -5
  35. package/lib/utils/check-plugin.js +15 -25
  36. package/lib/utils/dep-versions.d.ts +0 -6
  37. package/lib/utils/dep-versions.js +2 -27
  38. package/lib/utils/failure-fingerprint.js +3 -4
  39. package/lib/utils/fs-helpers.d.ts +18 -0
  40. package/lib/utils/fs-helpers.js +84 -0
  41. package/lib/utils/git.d.ts +0 -1
  42. package/lib/utils/git.js +0 -8
  43. package/lib/utils/hash.d.ts +3 -0
  44. package/lib/utils/hash.js +19 -0
  45. package/lib/utils/hbcTransform.d.ts +9 -2
  46. package/lib/utils/hbcTransform.js +41 -70
  47. package/lib/utils/hermes-base.d.ts +1 -5
  48. package/lib/utils/hermes-base.js +136 -196
  49. package/lib/utils/hermes-literals.d.ts +5 -3
  50. package/lib/utils/hermes-literals.js +30 -53
  51. package/lib/utils/hermes-raw.d.ts +7 -0
  52. package/lib/utils/hermes-raw.js +26 -9
  53. package/lib/utils/http-helper.d.ts +0 -1
  54. package/lib/utils/http-helper.js +0 -20
  55. package/lib/utils/i18n.js +0 -2
  56. package/lib/utils/index.d.ts +5 -19
  57. package/lib/utils/index.js +95 -189
  58. package/lib/utils/latest-version.d.ts +19 -0
  59. package/lib/utils/latest-version.js +137 -0
  60. package/lib/utils/options.d.ts +2 -1
  61. package/lib/utils/options.js +5 -7
  62. package/lib/utils/runtime.d.ts +1 -1
  63. package/lib/utils/runtime.js +2 -10
  64. package/lib/utils/upload-request.d.ts +33 -0
  65. package/lib/utils/upload-request.js +120 -0
  66. package/lib/utils/zip-entries.d.ts +23 -0
  67. package/lib/utils/zip-entries.js +130 -139
  68. package/lib/utils/zip-options.js +29 -56
  69. package/lib/utils/zip-range.js +29 -69
  70. package/lib/utils/zip-raw-writer.js +6 -5
  71. package/lib/versions.d.ts +5 -0
  72. package/lib/versions.js +86 -153
  73. package/package.json +1 -9
  74. package/lib/utils/app-info-parser/app.d.ts +0 -4
  75. package/lib/utils/app-info-parser/app.js +0 -10
  76. package/lib/utils/app-info-parser/index.d.ts +0 -16
  77. package/lib/utils/app-info-parser/index.js +0 -46
  78. package/lib/utils/app-info-parser/utils.d.ts +0 -31
  79. package/lib/utils/app-info-parser/utils.js +0 -135
  80. package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +0 -10
  81. package/lib/utils/app-info-parser/xml-parser/manifest.js +0 -202
  82. package/lib/utils/latest-version/index.d.ts +0 -149
  83. package/lib/utils/latest-version/index.js +0 -326
  84. package/lib/utils/plugin-config.d.ts +0 -9
  85. package/lib/utils/plugin-config.js +0 -61
package/lib/account.js CHANGED
@@ -8,12 +8,12 @@ exports.accountCacheFile = accountCacheFile;
8
8
  exports.showCurrentAccount = showCurrentAccount;
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
10
  const child_process_1 = require("child_process");
11
- const crypto_1 = require("crypto");
12
11
  const fs_1 = __importDefault(require("fs"));
13
12
  const os_1 = __importDefault(require("os"));
14
13
  const path_1 = __importDefault(require("path"));
15
14
  const api_1 = require("./api");
16
15
  const constants_1 = require("./utils/constants");
16
+ const hash_1 = require("./utils/hash");
17
17
  const i18n_1 = require("./utils/i18n");
18
18
  const DAY_MS = 24 * 60 * 60 * 1000;
19
19
  function printAccountInfo(account, isCresc = constants_1.IS_CRESC, now = Date.now()) {
@@ -41,9 +41,7 @@ function printAccountInfo(account, isCresc = constants_1.IS_CRESC, now = Date.no
41
41
  }
42
42
  }
43
43
  function accountCacheFile(token, apiToken = '') {
44
- const key = (0, crypto_1.createHash)('sha256')
45
- .update(JSON.stringify([constants_1.IS_CRESC, process.cwd(), token, apiToken]))
46
- .digest('hex');
44
+ const key = (0, hash_1.sha256Hex)(JSON.stringify([constants_1.IS_CRESC, process.cwd(), token, apiToken]));
47
45
  return path_1.default.join(os_1.default.homedir(), '.cache', 'react-native-update-cli', 'accounts', `${key}.json`);
48
46
  }
49
47
  function printCachedAccount(entry) {
package/lib/api.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare function uploadTimeoutMs(fileSize: number): number;
22
22
  * get here — they are surfaced as-is.
23
23
  */
24
24
  export declare function isTransientUploadError(error: unknown): boolean;
25
- export declare function uploadFile(fn: string, key?: string, appId?: string | number): Promise<{
25
+ export declare function uploadFile(fn: string, appId?: string | number): Promise<{
26
26
  hash: any;
27
27
  }>;
28
28
  /**
package/lib/api.js CHANGED
@@ -17,6 +17,7 @@ const constants_1 = require("./utils/constants");
17
17
  const http_helper_1 = require("./utils/http-helper");
18
18
  const i18n_1 = require("./utils/i18n");
19
19
  const runtime_1 = require("./utils/runtime");
20
+ const upload_request_1 = require("./utils/upload-request");
20
21
  let session;
21
22
  let savedSession;
22
23
  let apiToken;
@@ -141,6 +142,14 @@ function isProxyRelatedError(error) {
141
142
  const lower = parts.join('\n').toLowerCase();
142
143
  return PROXY_ERROR_PATTERNS.some((p) => lower.includes(p.toLowerCase()));
143
144
  }
145
+ /** A request error for `url`, with the proxy hints when a proxy is the likely cause. */
146
+ function networkError(error, url) {
147
+ const baseError = createRequestError(error, url);
148
+ if (isProxyRelatedError(error)) {
149
+ return new Error(`${baseError.message}\n\n${(0, i18n_1.t)('proxyNetworkError')}\n${(0, i18n_1.t)('proxyNetworkErrorTips')}`, { cause: baseError });
150
+ }
151
+ return baseError;
152
+ }
144
153
  async function query(url, options) {
145
154
  const baseUrl = await (0, http_helper_1.getBaseUrl)();
146
155
  const fullUrl = `${baseUrl}${url}`;
@@ -149,11 +158,7 @@ async function query(url, options) {
149
158
  resp = await (0, runtime_1.runtimeFetch)(fullUrl, options);
150
159
  }
151
160
  catch (error) {
152
- const baseError = createRequestError(error, fullUrl);
153
- if (isProxyRelatedError(error)) {
154
- throw new Error(`${baseError.message}\n\n${(0, i18n_1.t)('proxyNetworkError')}\n${(0, i18n_1.t)('proxyNetworkErrorTips')}`, { cause: baseError });
155
- }
156
- throw baseError;
161
+ throw networkError(error, fullUrl);
157
162
  }
158
163
  const text = await resp.text();
159
164
  let json;
@@ -176,29 +181,12 @@ async function query(url, options) {
176
181
  }
177
182
  return json;
178
183
  }
179
- function queryWithoutBody(method) {
180
- return (api) => {
181
- const headers = {
182
- 'User-Agent': userAgent,
183
- };
184
- if (apiToken) {
185
- headers['x-api-token'] = apiToken;
186
- }
187
- else if (session?.token) {
188
- headers['X-AccessToken'] = session.token;
189
- }
190
- return query(api, {
191
- method,
192
- headers,
193
- });
194
- };
195
- }
196
- function queryWithBody(method) {
184
+ function queryWith(method, withBody) {
197
185
  return (api, body) => {
198
- const headers = {
199
- 'User-Agent': userAgent,
200
- 'Content-Type': 'application/json',
201
- };
186
+ const headers = { 'User-Agent': userAgent };
187
+ if (withBody) {
188
+ headers['Content-Type'] = 'application/json';
189
+ }
202
190
  if (apiToken) {
203
191
  headers['x-api-token'] = apiToken;
204
192
  }
@@ -208,14 +196,14 @@ function queryWithBody(method) {
208
196
  return query(api, {
209
197
  method,
210
198
  headers,
211
- body: JSON.stringify(body),
199
+ ...(withBody ? { body: JSON.stringify(body) } : {}),
212
200
  });
213
201
  };
214
202
  }
215
- exports.get = queryWithoutBody('GET');
216
- exports.post = queryWithBody('POST');
217
- exports.put = queryWithBody('PUT');
218
- exports.doDelete = queryWithBody('DELETE');
203
+ exports.get = queryWith('GET', false);
204
+ exports.post = queryWith('POST', true);
205
+ exports.put = queryWith('PUT', true);
206
+ exports.doDelete = queryWith('DELETE', true);
219
207
  // Upload deadline: generous for a slow link (5 s/MB, i.e. ~200 KB/s, on top
220
208
  // of a 30 s base, never below 60 s) but bounded, so a stalled connection cannot
221
209
  // hang a CI job forever. The bar keeps ticking while bytes flow; the deadline
@@ -252,16 +240,6 @@ class UploadTimeoutError extends Error {
252
240
  this.name = 'UploadTimeoutError';
253
241
  }
254
242
  }
255
- /**
256
- * node-fetch is only needed for the streaming multipart / PUT upload below
257
- * (the built-in fetch cannot stream a form-data body). Loading it eagerly
258
- * pulled whatwg-url → punycode into every command, which Node ≥ 21 greets
259
- * with a DEP0040 deprecation warning on stderr; so it is loaded on first use.
260
- */
261
- function loadNodeFetch() {
262
- const mod = require('node-fetch');
263
- return (mod.default ?? mod);
264
- }
265
243
  /**
266
244
  * Send the file (or one slice of it) with a size-scaled deadline and retries
267
245
  * on a transient network error. `buildRequest` is invoked per attempt with a
@@ -269,7 +247,6 @@ function loadNodeFetch() {
269
247
  */
270
248
  async function sendUpload(fn, realUrl, fileSize, bar, buildRequest, slice = { start: 0, end: fileSize, retries: UPLOAD_MAX_RETRIES }) {
271
249
  const timeoutMs = uploadTimeoutMs(slice.end - slice.start);
272
- const nodeFetch = loadNodeFetch();
273
250
  // HTTP(S)_PROXY / NO_PROXY, like every other request of the CLI
274
251
  const agent = (0, runtime_1.proxyAgentFor)(realUrl);
275
252
  for (let attempt = 0;; attempt++) {
@@ -290,10 +267,10 @@ async function sendUpload(fn, realUrl, fileSize, bar, buildRequest, slice = { st
290
267
  bar.tick(data.length);
291
268
  });
292
269
  try {
293
- return await nodeFetch(realUrl, {
294
- ...buildRequest(fileStream),
270
+ return await (0, upload_request_1.sendUploadRequest)(realUrl, buildRequest(fileStream), {
295
271
  agent,
296
272
  signal: controller.signal,
273
+ userAgent,
297
274
  });
298
275
  }
299
276
  catch (rawError) {
@@ -349,7 +326,7 @@ async function sendChunks(fn, realUrl, fileSize, bar, chunked, postForm) {
349
326
  throw failure;
350
327
  }
351
328
  }
352
- async function uploadFile(fn, key, appId) {
329
+ async function uploadFile(fn, appId) {
353
330
  const fileSize = fs_1.default.statSync(fn).size;
354
331
  // appId 用于服务端路由:绑定了自托管节点(rnu-node)的应用,
355
332
  // 上传指令会指向节点或其对象存储。chunked + size 让支持的服务端(GCS)
@@ -357,7 +334,8 @@ async function uploadFile(fn, key, appId) {
357
334
  const resp = await (0, exports.post)('/upload', {
358
335
  ext: path_1.default.extname(fn),
359
336
  ...(appId ? { appId: Number(appId) } : {}),
360
- ...(key ? {} : { chunked: true, size: fileSize }),
337
+ chunked: true,
338
+ size: fileSize,
361
339
  });
362
340
  const { url, backupUrl, formData, maxSize } = resp;
363
341
  let realUrl = url;
@@ -377,7 +355,6 @@ async function uploadFile(fn, key, appId) {
377
355
  realUrl = backupUrl;
378
356
  }
379
357
  }
380
- // console.log({realUrl});
381
358
  }
382
359
  if (maxSize && fileSize > (0, filesize_parser_1.default)(maxSize)) {
383
360
  const readableFileSize = `${(fileSize / 1048576).toFixed(1)}m`;
@@ -387,7 +364,7 @@ async function uploadFile(fn, key, appId) {
387
364
  pricingPageUrl: constants_1.pricingPageUrl,
388
365
  }));
389
366
  }
390
- // progress/form-data are only needed here; keep them off the startup path
367
+ // progress is only needed here; keep it off the startup path
391
368
  const progressModule = require('progress');
392
369
  const ProgressBarImpl = (progressModule.default ??
393
370
  progressModule);
@@ -397,11 +374,7 @@ async function uploadFile(fn, key, appId) {
397
374
  total: fileSize,
398
375
  });
399
376
  const rethrowUploadError = (error) => {
400
- const baseError = createRequestError(error, realUrl);
401
- if (isProxyRelatedError(error)) {
402
- throw new Error(`${baseError.message}\n\n${(0, i18n_1.t)('proxyNetworkError')}\n${(0, i18n_1.t)('proxyNetworkErrorTips')}`, { cause: baseError });
403
- }
404
- throw baseError;
377
+ throw networkError(error, realUrl);
405
378
  };
406
379
  // 自托管节点的 s3 直传:服务端下发预签名 PUT,字节直达用户的对象存储
407
380
  if (resp.method === 'PUT') {
@@ -425,22 +398,12 @@ async function uploadFile(fn, key, appId) {
425
398
  }
426
399
  return { hash: resp.key };
427
400
  }
428
- const formDataModule = require('form-data');
429
- const FormData = (formDataModule.default ??
430
- formDataModule);
431
- const postForm = (fields, byteCount) => (fileStream) => {
432
- const form = new FormData();
433
- for (const [k, v] of Object.entries(fields)) {
434
- form.append(k, v);
435
- }
436
- // With every part's length known node-fetch sends Content-Length
437
- // instead of a chunked body: what object stores expect, and the only
438
- // framing that survives http-proxy-agent's rewrite of the buffered
439
- // request head.
440
- form.append('file', fileStream, { knownLength: byteCount });
441
- return { method: 'POST', body: form };
442
- };
443
- if (resp.chunked && !key) {
401
+ const postForm = (fields, byteCount) => (fileStream) => (0, upload_request_1.multipartRequest)(fields, {
402
+ name: fn,
403
+ size: byteCount,
404
+ stream: fileStream,
405
+ });
406
+ if (resp.chunked) {
444
407
  try {
445
408
  await sendChunks(fn, realUrl, fileSize, bar, resp.chunked, postForm);
446
409
  }
@@ -458,7 +421,7 @@ async function uploadFile(fn, key, appId) {
458
421
  }
459
422
  let res;
460
423
  try {
461
- res = await sendUpload(fn, realUrl, fileSize, bar, postForm(key ? { ...formData, key } : formData, fileSize));
424
+ res = await sendUpload(fn, realUrl, fileSize, bar, postForm(formData, fileSize));
462
425
  }
463
426
  catch (error) {
464
427
  return rethrowUploadError(error);
@@ -466,8 +429,7 @@ async function uploadFile(fn, key, appId) {
466
429
  if (res.status > 299) {
467
430
  throw createRequestError(`${res.status}: ${res.statusText || 'Upload failed'}`, realUrl);
468
431
  }
469
- // const body = await response.json();
470
- return { hash: key || formData.key };
432
+ return { hash: formData.key };
471
433
  }
472
434
  /**
473
435
  * Ask the server for the Hermes base of (app, HBC version): the earliest
package/lib/app.js CHANGED
@@ -44,28 +44,30 @@ function parsePositiveIntegerId(value) {
44
44
  }
45
45
  return id;
46
46
  }
47
- /** Read the selected app for a platform from the requested config file. */
48
- async function getSelectedApp(platform, configPath) {
49
- assertPlatform(platform);
50
- const resolvedConfigPath = configPath || constants_1.updateJson;
47
+ /** The parsed config file, or undefined when it does not exist. */
48
+ async function readUpdateInfo(configPath) {
51
49
  let raw;
52
50
  try {
53
- raw = await fs_1.default.promises.readFile(resolvedConfigPath, 'utf8');
51
+ raw = await fs_1.default.promises.readFile(configPath, 'utf8');
54
52
  }
55
53
  catch (e) {
56
54
  if (e.code === 'ENOENT') {
57
- throw new AppNotSelectedError(platform);
55
+ return undefined;
58
56
  }
59
57
  throw e;
60
58
  }
61
- let updateInfo;
62
59
  try {
63
- updateInfo = JSON.parse(raw);
60
+ return JSON.parse(raw);
64
61
  }
65
62
  catch {
66
- throw new Error((0, i18n_1.t)('failedToParseUpdateJson', { configPath: resolvedConfigPath }));
63
+ throw new Error((0, i18n_1.t)('failedToParseUpdateJson', { configPath }));
67
64
  }
68
- const info = updateInfo[platform];
65
+ }
66
+ /** Read the selected app for a platform from the requested config file. */
67
+ async function getSelectedApp(platform, configPath) {
68
+ assertPlatform(platform);
69
+ const updateInfo = await readUpdateInfo(configPath || constants_1.updateJson);
70
+ const info = updateInfo?.[platform];
69
71
  if (!info) {
70
72
  throw new AppNotSelectedError(platform);
71
73
  }
@@ -151,25 +153,13 @@ async function selectApp({ args, options, }) {
151
153
  const id = args[0]
152
154
  ? parsePositiveIntegerId(args[0])
153
155
  : (await chooseApp(platform)).id;
154
- if (!Number.isSafeInteger(id) || id <= 0) {
155
- throw new Error((0, i18n_1.t)('invalidId', { id: args[0] }));
156
- }
157
156
  const app = await assertAppPlatform(String(id), platform);
158
157
  if (typeof app.appKey !== 'string' || !app.appKey) {
159
158
  throw new Error((0, i18n_1.t)('appKeyMissing', { appId: id }));
160
159
  }
161
160
  const appKey = app.appKey;
162
161
  const configPath = options.config || constants_1.updateJson;
163
- let updateInfo = {};
164
- try {
165
- updateInfo = JSON.parse(await fs_1.default.promises.readFile(configPath, 'utf8'));
166
- }
167
- catch (e) {
168
- if (e.code !== 'ENOENT') {
169
- console.error((0, i18n_1.t)('failedToParseUpdateJson', { configPath }));
170
- throw e;
171
- }
172
- }
162
+ const updateInfo = (await readUpdateInfo(configPath)) ?? {};
173
163
  updateInfo[platform] = {
174
164
  appId: id,
175
165
  appKey,
@@ -197,10 +187,6 @@ function getAppCommands() {
197
187
  const id = args[0]
198
188
  ? parsePositiveIntegerId(args[0])
199
189
  : (await chooseApp(platform)).id;
200
- if (!id) {
201
- console.log((0, i18n_1.t)('cancelled'));
202
- return;
203
- }
204
190
  await (0, api_1.doDelete)(`/app/${id}`);
205
191
  console.log((0, i18n_1.t)('operationSuccess'));
206
192
  },
@@ -1,4 +1,4 @@
1
- export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
1
+ import type { PackageManager } from './utils/runtime';
2
2
  export interface AutoUpdateNotice {
3
3
  kind: 'updated' | 'permission';
4
4
  currentVersion: string;
@@ -9,8 +9,9 @@ exports.launchAutoUpdate = launchAutoUpdate;
9
9
  exports.consumeAutoUpdateNotice = consumeAutoUpdateNotice;
10
10
  const child_process_1 = require("child_process");
11
11
  const fs_1 = require("fs");
12
- const os_1 = require("os");
13
12
  const path_1 = __importDefault(require("path"));
13
+ const fs_helpers_1 = require("./utils/fs-helpers");
14
+ const options_1 = require("./utils/options");
14
15
  const PACKAGE_NAME = 'react-native-update-cli';
15
16
  const WORKER_ENV = 'RNU_AUTO_UPDATE_WORKER';
16
17
  const CANDIDATE_ENV = 'RNU_AUTO_UPDATE_CANDIDATE';
@@ -21,17 +22,7 @@ const FAILURE_RETRY_MS = 24 * 60 * 60 * 1000;
21
22
  const PERMISSION_RETRY_MS = 7 * 24 * 60 * 60 * 1000;
22
23
  const OUTPUT_LIMIT = 32 * 1024;
23
24
  function cacheDir() {
24
- if (process.env.XDG_CACHE_HOME) {
25
- return path_1.default.join(process.env.XDG_CACHE_HOME, PACKAGE_NAME);
26
- }
27
- switch (process.platform) {
28
- case 'darwin':
29
- return path_1.default.join((0, os_1.homedir)(), 'Library', 'Caches', PACKAGE_NAME);
30
- case 'win32':
31
- return path_1.default.join(process.env.LOCALAPPDATA ?? path_1.default.join((0, os_1.homedir)(), 'AppData', 'Local'), PACKAGE_NAME, 'Cache');
32
- default:
33
- return path_1.default.join((0, os_1.homedir)(), '.cache', PACKAGE_NAME);
34
- }
25
+ return (0, fs_helpers_1.userCacheDir)(PACKAGE_NAME);
35
26
  }
36
27
  function stateFile() {
37
28
  return path_1.default.join(cacheDir(), 'auto-update.json');
@@ -233,11 +224,10 @@ function inferNpmPrefix(packageRoot, npmGlobalDir, npmPrefix) {
233
224
  }
234
225
  function isDisabled(env) {
235
226
  const disabled = (value) => value === '0' || value?.toLowerCase() === 'false';
236
- const enabled = (value) => value === '1' || value?.toLowerCase() === 'true';
237
227
  return (disabled(env.RNU_AUTO_UPDATE) ||
238
- enabled(env.RNU_DISABLE_AUTO_UPDATE) ||
239
- enabled(env.NO_UPDATE_NOTIFIER) ||
240
- enabled(env.CI));
228
+ (0, options_1.isTruthyEnv)(env.RNU_DISABLE_AUTO_UPDATE) ||
229
+ (0, options_1.isTruthyEnv)(env.NO_UPDATE_NOTIFIER) ||
230
+ (0, options_1.isTruthyEnv)(env.CI));
241
231
  }
242
232
  function shouldRetry(state, target) {
243
233
  if (!state || state.targetVersion !== target)
package/lib/bin.js CHANGED
@@ -6,9 +6,7 @@ const api_1 = require("./api");
6
6
  const commands_1 = require("./commands");
7
7
  const utils_1 = require("./utils");
8
8
  const i18n_1 = require("./utils/i18n");
9
- function isTruthyEnv(value) {
10
- return value === '1' || value?.toLowerCase() === 'true';
11
- }
9
+ const options_1 = require("./utils/options");
12
10
  function printUsage(exitCode = 1) {
13
11
  console.log('React Native Update CLI');
14
12
  console.log('');
@@ -30,7 +28,7 @@ function printUsage(exitCode = 1) {
30
28
  * when the CLI itself is at fault, is printed on request (RNU_DEBUG=1).
31
29
  */
32
30
  function reportError(err) {
33
- if (isTruthyEnv(process.env.RNU_DEBUG)) {
31
+ if ((0, options_1.isTruthyEnv)(process.env.RNU_DEBUG)) {
34
32
  console.error(err instanceof Error ? err.stack : err);
35
33
  // fetch failures wrap the real reason (ECONNREFUSED, TLS, ...) as `cause`
36
34
  for (let cause = err?.cause; cause; cause = cause?.cause) {
@@ -64,9 +62,9 @@ async function run() {
64
62
  const argv = require('cli-arguments').parse(require('../cli.json'));
65
63
  global.NO_INTERACTIVE =
66
64
  Boolean(argv.options['no-interactive']) ||
67
- isTruthyEnv(process.env.NO_INTERACTIVE);
65
+ (0, options_1.isTruthyEnv)(process.env.NO_INTERACTIVE);
68
66
  global.USE_ACC_OSS =
69
- Boolean(argv.options.acc) || isTruthyEnv(process.env.USE_ACC_OSS);
67
+ Boolean(argv.options.acc) || (0, options_1.isTruthyEnv)(process.env.USE_ACC_OSS);
70
68
  await (0, api_1.loadSession)();
71
69
  if (argv.command === 'help' || argv.command === 'list') {
72
70
  printUsage(0);
@@ -1,46 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.packBundle = packBundle;
40
- const fs = __importStar(require("fs-extra"));
7
+ const fs_1 = __importDefault(require("fs"));
41
8
  const path_1 = __importDefault(require("path"));
42
- const yazl_1 = require("yazl");
43
9
  const i18n_1 = require("./utils/i18n");
10
+ const zip_entries_1 = require("./utils/zip-entries");
44
11
  const zip_options_1 = require("./utils/zip-options");
45
12
  const ignorePackingExtensions = ['DS_Store', 'txt.map'];
46
13
  async function packBundle(dir, output, bundleName) {
@@ -52,35 +19,34 @@ async function packBundle(dir, output, bundleName) {
52
19
  ignorePackingFileNames.push(`${bundleName}.map`);
53
20
  }
54
21
  console.log((0, i18n_1.t)('packing'));
55
- fs.ensureDirSync(path_1.default.dirname(output));
56
- await new Promise((resolve, reject) => {
57
- const zipfile = new yazl_1.ZipFile();
58
- function addDirectory(root, rel) {
59
- if (rel) {
60
- zipfile.addEmptyDirectory(rel);
22
+ const { zipfile, writePromise, abort } = (0, zip_entries_1.createOutputZip)(output);
23
+ function addDirectory(root, rel) {
24
+ if (rel) {
25
+ zipfile.addEmptyDirectory(rel);
26
+ }
27
+ for (const name of fs_1.default.readdirSync(root)) {
28
+ if (ignorePackingFileNames.includes(name) ||
29
+ ignorePackingExtensions.some((ext) => name.endsWith(`.${ext}`))) {
30
+ continue;
31
+ }
32
+ const fullPath = path_1.default.join(root, name);
33
+ const stat = fs_1.default.statSync(fullPath);
34
+ if (stat.isFile()) {
35
+ zipfile.addFile(fullPath, rel + name, (0, zip_options_1.zipOptionsForPayloadFile)(fullPath, rel + name));
61
36
  }
62
- const children = fs.readdirSync(root);
63
- for (const name of children) {
64
- if (ignorePackingFileNames.includes(name) ||
65
- ignorePackingExtensions.some((ext) => name.endsWith(`.${ext}`))) {
66
- continue;
67
- }
68
- const fullPath = path_1.default.join(root, name);
69
- const stat = fs.statSync(fullPath);
70
- if (stat.isFile()) {
71
- zipfile.addFile(fullPath, rel + name, (0, zip_options_1.zipOptionsForPayloadFile)(fullPath, rel + name));
72
- }
73
- else if (stat.isDirectory()) {
74
- addDirectory(fullPath, `${rel}${name}/`);
75
- }
37
+ else if (stat.isDirectory()) {
38
+ addDirectory(fullPath, `${rel}${name}/`);
76
39
  }
77
40
  }
41
+ }
42
+ try {
78
43
  addDirectory(dir, '');
79
- zipfile.outputStream.on('error', (err) => reject(err));
80
- zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
81
- resolve();
82
- });
83
44
  zipfile.end();
84
- });
45
+ await writePromise;
46
+ }
47
+ catch (error) {
48
+ await abort();
49
+ throw error;
50
+ }
85
51
  console.log((0, i18n_1.t)('fileGenerated', { file: output }));
86
52
  }