react-native-update-cli 2.11.0 → 2.12.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 (46) hide show
  1. package/README.md +4 -0
  2. package/README.zh-CN.md +4 -0
  3. package/cli.json +6 -0
  4. package/lib/api.js +10 -12
  5. package/lib/app.d.ts +1 -1
  6. package/lib/app.js +1 -1
  7. package/lib/bin.js +5 -2
  8. package/lib/bundle-runner.js +22 -12
  9. package/lib/install.js +3 -4
  10. package/lib/locales/en.d.ts +1 -0
  11. package/lib/locales/en.js +1 -0
  12. package/lib/locales/zh.d.ts +1 -0
  13. package/lib/locales/zh.js +1 -0
  14. package/lib/package.d.ts +3 -0
  15. package/lib/package.js +6 -2
  16. package/lib/provider.d.ts +2 -2
  17. package/lib/provider.js +23 -22
  18. package/lib/types.d.ts +17 -4
  19. package/lib/utils/app-info-parser/zip.d.ts +3 -3
  20. package/lib/utils/app-info-parser/zip.js +33 -19
  21. package/lib/utils/http-helper.js +2 -7
  22. package/lib/utils/index.d.ts +1 -0
  23. package/lib/utils/index.js +9 -1
  24. package/lib/utils/runtime.d.ts +28 -0
  25. package/lib/utils/runtime.js +185 -0
  26. package/lib/versions.d.ts +6 -3
  27. package/lib/versions.js +80 -23
  28. package/package.json +1 -6
  29. package/src/api.ts +23 -15
  30. package/src/app.ts +1 -1
  31. package/src/bin.ts +9 -2
  32. package/src/bundle-runner.ts +91 -50
  33. package/src/install.ts +3 -1
  34. package/src/locales/en.ts +1 -0
  35. package/src/locales/zh.ts +1 -0
  36. package/src/package.ts +11 -2
  37. package/src/provider.ts +47 -40
  38. package/src/types.ts +18 -4
  39. package/src/utils/app-info-parser/zip.ts +41 -24
  40. package/src/utils/http-helper.ts +2 -2
  41. package/src/utils/index.ts +8 -1
  42. package/src/utils/runtime.ts +190 -0
  43. package/src/versions.ts +105 -32
  44. package/lib/utils/latest-version/cli.d.ts +0 -1
  45. package/lib/utils/latest-version/cli.js +0 -308
  46. package/src/utils/latest-version/cli.ts +0 -445
@@ -22,13 +22,8 @@ _export(exports, {
22
22
  return testUrls;
23
23
  }
24
24
  });
25
- const _nodefetch = /*#__PURE__*/ _interop_require_default(require("node-fetch"));
26
25
  const _constants = require("./constants");
27
- function _interop_require_default(obj) {
28
- return obj && obj.__esModule ? obj : {
29
- default: obj
30
- };
31
- }
26
+ const _runtime = require("./runtime");
32
27
  function promiseAny(promises) {
33
28
  return new Promise((resolve, reject)=>{
34
29
  let count = 0;
@@ -45,7 +40,7 @@ function promiseAny(promises) {
45
40
  const ping = async (url)=>{
46
41
  let pingFinished = false;
47
42
  return Promise.race([
48
- (0, _nodefetch.default)(url, {
43
+ (0, _runtime.runtimeFetch)(url, {
49
44
  method: 'HEAD'
50
45
  }).then(({ status })=>{
51
46
  pingFinished = true;
@@ -1,4 +1,5 @@
1
1
  import { checkPlugins } from './check-plugin';
2
+ export declare function isNonInteractive(): boolean;
2
3
  export declare function question(query: string, password?: boolean): Promise<string>;
3
4
  export declare function translateOptions<T extends Record<string, unknown>>(options: T): T & Record<string, unknown>;
4
5
  export declare function getApkInfo(fn: string): Promise<{
@@ -24,6 +24,9 @@ _export(exports, {
24
24
  get getIpaInfo () {
25
25
  return getIpaInfo;
26
26
  },
27
+ get isNonInteractive () {
28
+ return isNonInteractive;
29
+ },
27
30
  get printVersionCommand () {
28
31
  return printVersionCommand;
29
32
  },
@@ -51,8 +54,13 @@ function _interop_require_default(obj) {
51
54
  default: obj
52
55
  };
53
56
  }
57
+ function isNonInteractive() {
58
+ var _process_env_NO_INTERACTIVE;
59
+ const envValue = (_process_env_NO_INTERACTIVE = process.env.NO_INTERACTIVE) == null ? void 0 : _process_env_NO_INTERACTIVE.toLowerCase();
60
+ return global.NO_INTERACTIVE === true || envValue === 'true' || envValue === '1';
61
+ }
54
62
  async function question(query, password) {
55
- if (NO_INTERACTIVE) {
63
+ if (isNonInteractive()) {
56
64
  return '';
57
65
  }
58
66
  return (0, _read.read)({
@@ -0,0 +1,28 @@
1
+ import { type ChildProcessWithoutNullStreams, type SpawnOptionsWithoutStdio, type SpawnSyncOptions } from 'child_process';
2
+ export type RuntimeRequestInit = {
3
+ method?: string;
4
+ headers?: Record<string, string>;
5
+ body?: any;
6
+ signal?: AbortSignal;
7
+ };
8
+ export type RuntimeResponse = {
9
+ status: number;
10
+ statusText: string;
11
+ text: () => Promise<string>;
12
+ };
13
+ export type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn';
14
+ export type JavaScriptRuntime = 'bun' | 'node';
15
+ export declare const isBunRuntime: boolean;
16
+ export declare function runtimeFetch(url: string, options?: RuntimeRequestInit): Promise<RuntimeResponse>;
17
+ export declare function measureTcpLatency(input: string, { attempts, timeout, }?: {
18
+ attempts?: number;
19
+ timeout?: number;
20
+ }): Promise<number>;
21
+ export declare function detectPackageManager(cwd?: string, env?: NodeJS.ProcessEnv): PackageManager;
22
+ export declare function getInstallCommand(installArgs: string[], cwd?: string): {
23
+ command: string;
24
+ args: string[];
25
+ };
26
+ export declare function getJavaScriptRuntime(env?: NodeJS.ProcessEnv): JavaScriptRuntime;
27
+ export declare function spawnJavaScript(args: string[], options?: SpawnOptionsWithoutStdio, env?: NodeJS.ProcessEnv): ChildProcessWithoutNullStreams;
28
+ export declare function spawnJavaScriptSync(args: string[], options?: SpawnSyncOptions, env?: NodeJS.ProcessEnv): import("node:child_process").SpawnSyncReturns<string | NonSharedBuffer>;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get detectPackageManager () {
13
+ return detectPackageManager;
14
+ },
15
+ get getInstallCommand () {
16
+ return getInstallCommand;
17
+ },
18
+ get getJavaScriptRuntime () {
19
+ return getJavaScriptRuntime;
20
+ },
21
+ get isBunRuntime () {
22
+ return isBunRuntime;
23
+ },
24
+ get measureTcpLatency () {
25
+ return measureTcpLatency;
26
+ },
27
+ get runtimeFetch () {
28
+ return runtimeFetch;
29
+ },
30
+ get spawnJavaScript () {
31
+ return spawnJavaScript;
32
+ },
33
+ get spawnJavaScriptSync () {
34
+ return spawnJavaScriptSync;
35
+ }
36
+ });
37
+ const _child_process = require("child_process");
38
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
39
+ const _net = require("net");
40
+ const _nodefetch = /*#__PURE__*/ _interop_require_default(require("node-fetch"));
41
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
42
+ function _interop_require_default(obj) {
43
+ return obj && obj.__esModule ? obj : {
44
+ default: obj
45
+ };
46
+ }
47
+ const isBunRuntime = typeof process.versions.bun === 'string';
48
+ function runtimeFetch(url, options) {
49
+ const fetchImpl = typeof globalThis.fetch === 'function' ? globalThis.fetch.bind(globalThis) : _nodefetch.default;
50
+ return fetchImpl(url, options);
51
+ }
52
+ function resolveTcpTarget(input) {
53
+ try {
54
+ const parsed = new URL(input);
55
+ const port = parsed.port || (parsed.protocol === 'http:' ? '80' : '443');
56
+ return {
57
+ host: parsed.hostname,
58
+ port: Number(port)
59
+ };
60
+ } catch (unused) {
61
+ const [host, port] = input.split(':');
62
+ return {
63
+ host,
64
+ port: port ? Number(port) : 443
65
+ };
66
+ }
67
+ }
68
+ function measureTcpConnectOnce(host, port, timeout) {
69
+ return new Promise((resolve)=>{
70
+ const startedAt = Date.now();
71
+ const socket = (0, _net.createConnection)({
72
+ host,
73
+ port
74
+ });
75
+ const finish = (latency)=>{
76
+ socket.removeAllListeners();
77
+ socket.destroy();
78
+ resolve(latency);
79
+ };
80
+ socket.setTimeout(timeout);
81
+ socket.once('connect', ()=>{
82
+ finish(Date.now() - startedAt);
83
+ });
84
+ socket.once('timeout', ()=>{
85
+ finish(Number.POSITIVE_INFINITY);
86
+ });
87
+ socket.once('error', ()=>{
88
+ finish(Number.POSITIVE_INFINITY);
89
+ });
90
+ });
91
+ }
92
+ async function measureTcpLatency(input, { attempts = 4, timeout = 1000 } = {}) {
93
+ const { host, port } = resolveTcpTarget(input);
94
+ const latencies = [];
95
+ for(let i = 0; i < attempts; i++){
96
+ const latency = await measureTcpConnectOnce(host, port, timeout);
97
+ if (Number.isFinite(latency)) {
98
+ latencies.push(latency);
99
+ }
100
+ }
101
+ if (latencies.length === 0) {
102
+ return Number.POSITIVE_INFINITY;
103
+ }
104
+ return latencies.reduce((sum, latency)=>sum + latency, 0) / latencies.length;
105
+ }
106
+ function detectPackageManager(cwd = process.cwd(), env = process.env) {
107
+ var _env_npm_config_user_agent;
108
+ const lockFiles = [
109
+ [
110
+ 'bun.lock',
111
+ 'bun'
112
+ ],
113
+ [
114
+ 'bun.lockb',
115
+ 'bun'
116
+ ],
117
+ [
118
+ 'pnpm-lock.yaml',
119
+ 'pnpm'
120
+ ],
121
+ [
122
+ 'yarn.lock',
123
+ 'yarn'
124
+ ],
125
+ [
126
+ 'package-lock.json',
127
+ 'npm'
128
+ ]
129
+ ];
130
+ for (const [lockFile, manager] of lockFiles){
131
+ if (_fs.default.existsSync(_path.default.join(cwd, lockFile))) {
132
+ return manager;
133
+ }
134
+ }
135
+ const userAgent = (_env_npm_config_user_agent = env.npm_config_user_agent) != null ? _env_npm_config_user_agent : '';
136
+ if (userAgent.startsWith('bun/')) {
137
+ return 'bun';
138
+ }
139
+ if (userAgent.startsWith('pnpm/')) {
140
+ return 'pnpm';
141
+ }
142
+ if (userAgent.startsWith('yarn/')) {
143
+ return 'yarn';
144
+ }
145
+ if (userAgent.startsWith('npm/')) {
146
+ return 'npm';
147
+ }
148
+ return isBunRuntime ? 'bun' : 'npm';
149
+ }
150
+ function getInstallCommand(installArgs, cwd = process.cwd()) {
151
+ const packageManager = detectPackageManager(cwd);
152
+ if (packageManager === 'npm') {
153
+ return {
154
+ command: 'npm',
155
+ args: [
156
+ 'install',
157
+ ...installArgs
158
+ ]
159
+ };
160
+ }
161
+ return {
162
+ command: packageManager,
163
+ args: [
164
+ 'add',
165
+ ...installArgs
166
+ ]
167
+ };
168
+ }
169
+ function getJavaScriptRuntime(env = process.env) {
170
+ var _env_RNU_JS_RUNTIME;
171
+ const configured = (_env_RNU_JS_RUNTIME = env.RNU_JS_RUNTIME) == null ? void 0 : _env_RNU_JS_RUNTIME.toLowerCase();
172
+ if (configured === 'bun') {
173
+ return 'bun';
174
+ }
175
+ if (configured === 'auto') {
176
+ return isBunRuntime ? 'bun' : 'node';
177
+ }
178
+ return 'node';
179
+ }
180
+ function spawnJavaScript(args, options, env = process.env) {
181
+ return (0, _child_process.spawn)(getJavaScriptRuntime(env), args, options != null ? options : {});
182
+ }
183
+ function spawnJavaScriptSync(args, options, env = process.env) {
184
+ return (0, _child_process.spawnSync)(getJavaScriptRuntime(env), args, options != null ? options : {});
185
+ }
package/lib/versions.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { Package, Platform } from './types';
1
+ import type { Package, Platform, Version } from './types';
2
2
  interface VersionCommandOptions {
3
+ [key: string]: unknown;
3
4
  appId?: string;
4
5
  name?: string;
5
6
  description?: string;
@@ -11,14 +12,16 @@ interface VersionCommandOptions {
11
12
  minPackageVersion?: string;
12
13
  maxPackageVersion?: string;
13
14
  packageVersionRange?: string;
14
- rollout?: string;
15
+ rollout?: number | string;
15
16
  dryRun?: boolean;
16
17
  versionDeps?: Record<string, string>;
17
18
  warnDepsChanges?: boolean;
19
+ 'no-interactive'?: boolean | string;
18
20
  }
21
+ export declare function fetchVersions(appId: string, offset?: number, limit?: number): Promise<Version[]>;
19
22
  export declare const bindVersionToPackages: ({ appId, versionId, pkgs, rollout, dryRun, }: {
20
23
  appId: string;
21
- versionId: string;
24
+ versionId: string | null;
22
25
  pkgs: Package[];
23
26
  rollout?: number;
24
27
  dryRun?: boolean;
package/lib/versions.js CHANGED
@@ -12,6 +12,9 @@ _export(exports, {
12
12
  get bindVersionToPackages () {
13
13
  return bindVersionToPackages;
14
14
  },
15
+ get fetchVersions () {
16
+ return fetchVersions;
17
+ },
15
18
  get versionCommands () {
16
19
  return versionCommands;
17
20
  }
@@ -26,6 +29,7 @@ const _utils = require("./utils");
26
29
  const _depversions = require("./utils/dep-versions");
27
30
  const _git = require("./utils/git");
28
31
  const _i18n = require("./utils/i18n");
32
+ const _options = require("./utils/options");
29
33
  function _interop_require_default(obj) {
30
34
  return obj && obj.__esModule ? obj : {
31
35
  default: obj
@@ -207,8 +211,13 @@ async function printDepsChangesForPublish({ appId, versionId, pkgs, providedVers
207
211
  console.log(_chalk.default.yellow((0, _i18n.t)('depsChangeNonBlockingHint')));
208
212
  }
209
213
  }
214
+ const versionPageLimit = 10;
215
+ async function fetchVersions(appId, offset = 0, limit = versionPageLimit) {
216
+ const { data } = await (0, _api.get)(`/app/${appId}/version/list?offset=${offset}&limit=${limit}`);
217
+ return Array.isArray(data) ? data : [];
218
+ }
210
219
  async function showVersion(appId, offset) {
211
- const { data } = await (0, _api.get)(`/app/${appId}/version/list`);
220
+ const data = await fetchVersions(appId, offset, versionPageLimit);
212
221
  console.log((0, _i18n.t)('offset', {
213
222
  offset
214
223
  }));
@@ -220,7 +229,7 @@ async function showVersion(appId, offset) {
220
229
  packageInfo = 'no package';
221
230
  } else {
222
231
  var _version_packages1;
223
- packageInfo = (_version_packages1 = version.packages) == null ? void 0 : _version_packages1.slice(0, 3).map((pkg)=>pkg.name).join(', ');
232
+ packageInfo = ((_version_packages1 = version.packages) != null ? _version_packages1 : []).slice(0, 3).map((pkg)=>pkg.name).join(', ');
224
233
  if (pkgCount > 3) {
225
234
  packageInfo += `...and ${pkgCount - 3} more`;
226
235
  } else {
@@ -231,10 +240,13 @@ async function showVersion(appId, offset) {
231
240
  }
232
241
  return data;
233
242
  }
234
- async function listVersions(appId) {
243
+ async function listVersions(appId, interactive = true) {
235
244
  let offset = 0;
236
245
  while(true){
237
- await showVersion(appId, offset);
246
+ const data = await showVersion(appId, offset);
247
+ if (!interactive) {
248
+ return data;
249
+ }
238
250
  const cmd = await (0, _utils.question)('page Up/page Down/Begin/Quit(U/D/B/Q)');
239
251
  switch(cmd.toLowerCase()){
240
252
  case 'u':
@@ -247,7 +259,9 @@ async function listVersions(appId) {
247
259
  offset = 0;
248
260
  break;
249
261
  case 'q':
250
- return;
262
+ return data;
263
+ case '':
264
+ return data;
251
265
  }
252
266
  }
253
267
  }
@@ -255,6 +269,9 @@ async function chooseVersion(appId) {
255
269
  let offset = 0;
256
270
  while(true){
257
271
  const data = await showVersion(appId, offset);
272
+ if ((0, _utils.isNonInteractive)()) {
273
+ throw new Error((0, _i18n.t)('versionIdRequired'));
274
+ }
258
275
  const cmd = await (0, _utils.question)('Enter versionId or page Up/page Down/Begin(U/D/B)');
259
276
  switch(cmd.toUpperCase()){
260
277
  case 'U':
@@ -314,13 +331,14 @@ const versionCommands = {
314
331
  }
315
332
  const platform = await (0, _app.getPlatform)(options.platform);
316
333
  const { appId } = await (0, _app.getSelectedApp)(platform);
334
+ const nonInteractive = (0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)();
317
335
  const { hash } = await (0, _api.uploadFile)(fn);
318
- const versionName = name || await (0, _utils.question)((0, _i18n.t)('versionNameQuestion')) || (0, _i18n.t)('unnamed');
336
+ const versionName = name || (nonInteractive ? '' : await (0, _utils.question)((0, _i18n.t)('versionNameQuestion'))) || (0, _i18n.t)('unnamed');
319
337
  const { id } = await (0, _api.post)(`/app/${appId}/version/create`, {
320
338
  name: versionName,
321
339
  hash,
322
- description: description || await (0, _utils.question)((0, _i18n.t)('versionDescriptionQuestion')),
323
- metaInfo: metaInfo || await (0, _utils.question)((0, _i18n.t)('versionMetaInfoQuestion')),
340
+ description: description != null ? description : nonInteractive ? '' : await (0, _utils.question)((0, _i18n.t)('versionDescriptionQuestion')),
341
+ metaInfo: metaInfo != null ? metaInfo : nonInteractive ? '' : await (0, _utils.question)((0, _i18n.t)('versionMetaInfoQuestion')),
324
342
  deps: _depversions.depVersions,
325
343
  commit: await (0, _git.getCommitInfo)()
326
344
  });
@@ -344,7 +362,7 @@ const versionCommands = {
344
362
  warnDepsChanges: true
345
363
  }
346
364
  });
347
- } else {
365
+ } else if (!nonInteractive) {
348
366
  const q = await (0, _utils.question)((0, _i18n.t)('updateNativePackageQuestion'));
349
367
  if (q.toLowerCase() === 'y') {
350
368
  await versionCommands.update({
@@ -360,16 +378,33 @@ const versionCommands = {
360
378
  return versionName;
361
379
  },
362
380
  versions: async ({ options })=>{
363
- const platform = await (0, _app.getPlatform)(options.platform);
364
- const { appId } = await (0, _app.getSelectedApp)(platform);
365
- await listVersions(String(appId));
381
+ let appId = options.appId;
382
+ if (!appId) {
383
+ const platform = await (0, _app.getPlatform)(options.platform);
384
+ appId = (await (0, _app.getSelectedApp)(platform)).appId;
385
+ }
386
+ const interactive = !((0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)());
387
+ await listVersions(String(appId), interactive);
366
388
  },
367
389
  update: async ({ options })=>{
368
- const platform = await (0, _app.getPlatform)(options.platform);
369
- const appId = options.appId || (await (0, _app.getSelectedApp)(platform)).appId;
370
- let versionId = options.versionId || (await chooseVersion(String(appId))).id;
390
+ const nonInteractive = (0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)();
391
+ let appId = options.appId;
392
+ let platform = options.platform;
393
+ if (!appId) {
394
+ platform = await (0, _app.getPlatform)(platform);
395
+ appId = (await (0, _app.getSelectedApp)(platform)).appId;
396
+ } else if (platform) {
397
+ platform = await (0, _app.getPlatform)(platform);
398
+ }
399
+ let versionId = options.versionId;
400
+ if (!versionId) {
401
+ if (nonInteractive) {
402
+ throw new Error((0, _i18n.t)('versionIdRequired'));
403
+ }
404
+ versionId = (await chooseVersion(String(appId))).id;
405
+ }
371
406
  if (versionId === 'null') {
372
- versionId = undefined;
407
+ versionId = null;
373
408
  }
374
409
  let pkgId = options.packageId;
375
410
  let pkgVersion = options.packageVersion;
@@ -378,7 +413,7 @@ const versionCommands = {
378
413
  let packageVersionRange = options.packageVersionRange;
379
414
  let rollout;
380
415
  if (options.rollout !== undefined) {
381
- rollout = Number.parseInt(options.rollout, 10);
416
+ rollout = Number.parseInt(String(options.rollout), 10);
382
417
  if (Number.isNaN(rollout) || rollout < 1 || rollout > 100) {
383
418
  throw new Error((0, _i18n.t)('rolloutRangeError'));
384
419
  }
@@ -392,7 +427,7 @@ const versionCommands = {
392
427
  let pkgsToBind = [];
393
428
  if (minPkgVersion) {
394
429
  minPkgVersion = String(minPkgVersion).trim();
395
- pkgsToBind = allPkgs.filter((pkg)=>(0, _compareversions.satisfies)(pkg.name, `>=${minPkgVersion}`));
430
+ pkgsToBind = allPkgs.filter((pkg)=>(0, _compareversions.compare)(pkg.name, minPkgVersion, '>='));
396
431
  if (pkgsToBind.length === 0) {
397
432
  throw new Error((0, _i18n.t)('nativeVersionNotFoundGte', {
398
433
  version: minPkgVersion
@@ -400,7 +435,9 @@ const versionCommands = {
400
435
  }
401
436
  } else if (maxPkgVersion) {
402
437
  maxPkgVersion = String(maxPkgVersion).trim();
403
- pkgsToBind = allPkgs.filter((pkg)=>(0, _compareversions.satisfies)(pkg.name, `<=${maxPkgVersion}`));
438
+ pkgsToBind = allPkgs.filter((pkg)=>{
439
+ return (0, _compareversions.compare)(pkg.name, maxPkgVersion, '<=');
440
+ });
404
441
  if (pkgsToBind.length === 0) {
405
442
  throw new Error((0, _i18n.t)('nativeVersionNotFoundLte', {
406
443
  version: maxPkgVersion
@@ -428,6 +465,9 @@ const versionCommands = {
428
465
  }
429
466
  } else {
430
467
  if (!pkgId) {
468
+ if (nonInteractive) {
469
+ throw new Error((0, _i18n.t)('packageIdRequired'));
470
+ }
431
471
  pkgId = (await (0, _package.choosePackage)(String(appId))).id;
432
472
  }
433
473
  if (!pkgId) {
@@ -444,7 +484,7 @@ const versionCommands = {
444
484
  }));
445
485
  }
446
486
  }
447
- if (options.warnDepsChanges) {
487
+ if (options.warnDepsChanges && versionId) {
448
488
  await printDepsChangesForPublish({
449
489
  appId: String(appId),
450
490
  versionId: String(versionId),
@@ -461,9 +501,22 @@ const versionCommands = {
461
501
  });
462
502
  },
463
503
  updateVersionInfo: async ({ options })=>{
464
- const platform = await (0, _app.getPlatform)(options.platform);
465
- const { appId } = await (0, _app.getSelectedApp)(platform);
466
- const versionId = options.versionId || (await chooseVersion(String(appId))).id;
504
+ const nonInteractive = (0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)();
505
+ let appId = options.appId;
506
+ let platform = options.platform;
507
+ if (!appId) {
508
+ platform = await (0, _app.getPlatform)(platform);
509
+ appId = (await (0, _app.getSelectedApp)(platform)).appId;
510
+ } else if (platform) {
511
+ await (0, _app.getPlatform)(platform);
512
+ }
513
+ let versionId = options.versionId;
514
+ if (!versionId) {
515
+ if (nonInteractive) {
516
+ throw new Error((0, _i18n.t)('versionIdRequired'));
517
+ }
518
+ versionId = (await chooseVersion(String(appId))).id;
519
+ }
467
520
  const updateParams = {};
468
521
  if (options.name) updateParams.name = options.name;
469
522
  if (options.description) updateParams.description = options.description;
@@ -472,6 +525,7 @@ const versionCommands = {
472
525
  console.log((0, _i18n.t)('operationSuccess'));
473
526
  },
474
527
  deleteVersion: async ({ options })=>{
528
+ const nonInteractive = (0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)();
475
529
  let appId = options.appId;
476
530
  if (!appId) {
477
531
  const platform = await (0, _app.getPlatform)(options.platform);
@@ -479,6 +533,9 @@ const versionCommands = {
479
533
  }
480
534
  let versionId = options.versionId;
481
535
  if (!versionId) {
536
+ if (nonInteractive) {
537
+ throw new Error((0, _i18n.t)('versionIdRequired'));
538
+ }
482
539
  versionId = (await chooseVersion(String(appId))).id;
483
540
  }
484
541
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
@@ -59,13 +59,11 @@
59
59
  },
60
60
  "homepage": "https://github.com/reactnativecn/react-native-update-cli",
61
61
  "dependencies": {
62
- "@colors/colors": "^1.6.0",
63
62
  "bplist-parser": "^0.3.2",
64
63
  "bytebuffer": "^5.0.1",
65
64
  "cgbi-to-png": "^1.0.7",
66
65
  "chalk": "4",
67
66
  "cli-arguments": "^0.2.1",
68
- "commander": "^13",
69
67
  "compare-versions": "^6.1.1",
70
68
  "filesize-parser": "^1.5.1",
71
69
  "form-data": "^4.0.5",
@@ -74,7 +72,6 @@
74
72
  "gradle-to-js": "^2.0.1",
75
73
  "i18next": "^26.0.4",
76
74
  "isomorphic-git": "^1.37.5",
77
- "isomorphic-unzip": "^1.1.5",
78
75
  "node-fetch": "^2.6.1",
79
76
  "plist": "^3.1.0",
80
77
  "progress": "^2.0.3",
@@ -83,7 +80,6 @@
83
80
  "read": "^4.1.0",
84
81
  "registry-auth-token": "^5.1.1",
85
82
  "semver": "^7.7.4",
86
- "tcp-ping": "^0.1.1",
87
83
  "tty-table": "5.0",
88
84
  "yauzl": "^3.3.0",
89
85
  "yazl": "3.3.1"
@@ -105,7 +101,6 @@
105
101
  "@types/node-fetch": "^2.6.13",
106
102
  "@types/progress": "^2.0.7",
107
103
  "@types/semver": "^7.7.1",
108
- "@types/tcp-ping": "^0.1.6",
109
104
  "@types/yauzl": "^2.10.3",
110
105
  "@types/yazl": "^2.4.6",
111
106
  "typescript": "^6.0.2"
package/src/api.ts CHANGED
@@ -4,15 +4,17 @@ import fs from 'fs';
4
4
  import fetch from 'node-fetch';
5
5
  import path from 'path';
6
6
  import ProgressBar from 'progress';
7
- import tcpp from 'tcp-ping';
8
- import util from 'util';
9
7
  import { getBaseUrl } from 'utils/http-helper';
10
8
  import packageJson from '../package.json';
11
9
  import type { Package, Session } from './types';
12
10
  import { credentialFile, IS_CRESC, pricingPageUrl } from './utils/constants';
13
11
  import { t } from './utils/i18n';
14
-
15
- const tcpPing = util.promisify(tcpp.ping);
12
+ import {
13
+ measureTcpLatency,
14
+ type RuntimeRequestInit,
15
+ type RuntimeResponse,
16
+ runtimeFetch,
17
+ } from './utils/runtime';
16
18
 
17
19
  let session: Session | undefined;
18
20
  let savedSession: Session | undefined;
@@ -75,22 +77,30 @@ export const closeSession = () => {
75
77
  session = undefined;
76
78
  };
77
79
 
78
- function createRequestError(error: unknown, requestUrl: string) {
80
+ function createRequestError(
81
+ error: unknown,
82
+ requestUrl: string,
83
+ status?: number,
84
+ ) {
79
85
  const message =
80
86
  typeof error === 'string'
81
87
  ? error
82
88
  : error instanceof Error
83
89
  ? error.message
84
90
  : String(error);
85
- return new Error(`${message}\nURL: ${requestUrl}`);
91
+ const requestError = new Error(`${message}\nURL: ${requestUrl}`) as Error & {
92
+ status?: number;
93
+ };
94
+ requestError.status = status;
95
+ return requestError;
86
96
  }
87
97
 
88
- async function query(url: string, options: fetch.RequestInit) {
98
+ async function query(url: string, options: RuntimeRequestInit) {
89
99
  const baseUrl = await getBaseUrl;
90
100
  const fullUrl = `${baseUrl}${url}`;
91
- let resp: fetch.Response;
101
+ let resp: RuntimeResponse;
92
102
  try {
93
- resp = await fetch(fullUrl, options);
103
+ resp = await runtimeFetch(fullUrl, options);
94
104
  } catch (error) {
95
105
  throw createRequestError(error, fullUrl);
96
106
  }
@@ -109,9 +119,9 @@ async function query(url: string, options: fetch.RequestInit) {
109
119
  if (resp.status !== 200) {
110
120
  const message = json?.message || resp.statusText || `HTTP ${resp.status}`;
111
121
  if (resp.status === 401) {
112
- throw createRequestError(t('loginExpired'), fullUrl);
122
+ throw createRequestError(t('loginExpired'), fullUrl, resp.status);
113
123
  }
114
- throw createRequestError(message, fullUrl);
124
+ throw createRequestError(message, fullUrl, resp.status);
115
125
  }
116
126
  return json;
117
127
  }
@@ -166,13 +176,11 @@ export async function uploadFile(fn: string, key?: string) {
166
176
  if (global.USE_ACC_OSS) {
167
177
  realUrl = backupUrl;
168
178
  } else {
169
- const pingResult = await tcpPing({
170
- address: url.replace('https://', ''),
179
+ const latency = await measureTcpLatency(url, {
171
180
  attempts: 4,
172
181
  timeout: 1000,
173
182
  });
174
- // console.log({pingResult});
175
- if (Number.isNaN(pingResult.avg) || pingResult.avg > 150) {
183
+ if (!Number.isFinite(latency) || latency > 150) {
176
184
  realUrl = backupUrl;
177
185
  }
178
186
  }
package/src/app.ts CHANGED
@@ -153,7 +153,7 @@ export function getAppCommands() {
153
153
  },
154
154
  apps: async ({ options }: { options: { platform?: Platform | '' } }) => {
155
155
  const { platform = '' } = options;
156
- await listApp(platform);
156
+ return listApp(platform);
157
157
  },
158
158
  selectApp,
159
159
  };