react-native-update-cli 2.22.6 → 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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/cli.json +5 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +106 -38
- package/lib/app.js +3 -2
- package/lib/bin.js +16 -2
- package/lib/bundle-runner.d.ts +35 -2
- package/lib/bundle-runner.js +313 -128
- package/lib/bundle.d.ts +1 -0
- package/lib/bundle.js +2 -0
- package/lib/diff.d.ts +9 -0
- package/lib/diff.js +162 -120
- package/lib/locales/en.d.ts +1 -0
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.d.ts +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/package.d.ts +7 -3
- package/lib/package.js +31 -12
- package/lib/types.d.ts +2 -0
- package/lib/utils/dep-versions.d.ts +7 -0
- package/lib/utils/dep-versions.js +66 -31
- package/lib/utils/hbcTransform.d.ts +21 -0
- package/lib/utils/hbcTransform.js +146 -5
- package/lib/utils/hermes-base.d.ts +31 -7
- package/lib/utils/hermes-base.js +284 -76
- package/lib/utils/http-helper.d.ts +6 -1
- package/lib/utils/http-helper.js +23 -11
- package/lib/utils/index.d.ts +30 -1
- package/lib/utils/index.js +98 -24
- package/lib/utils/latest-version/index.d.ts +11 -8
- package/lib/utils/latest-version/index.js +63 -18
- package/lib/utils/zip-entries.js +20 -15
- package/lib/utils/zip-options.d.ts +2 -0
- package/lib/utils/zip-options.js +9 -4
- package/lib/utils/zip-range.d.ts +84 -13
- package/lib/utils/zip-range.js +363 -63
- package/lib/versions.js +30 -23
- package/package.json +11 -11
- package/src/api.ts +126 -46
- package/src/app.ts +3 -2
- package/src/bin.ts +17 -2
- package/src/bundle-runner.ts +419 -171
- package/src/bundle.ts +3 -0
- package/src/diff.ts +210 -153
- package/src/locales/en.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/package.ts +42 -14
- package/src/types.ts +2 -0
- package/src/utils/dep-versions.ts +76 -33
- package/src/utils/hbcTransform.ts +194 -5
- package/src/utils/hermes-base.ts +311 -81
- package/src/utils/http-helper.ts +24 -13
- package/src/utils/index.ts +136 -26
- package/src/utils/latest-version/index.ts +82 -29
- package/src/utils/zip-entries.ts +18 -16
- package/src/utils/zip-options.ts +8 -3
- package/src/utils/zip-range.ts +436 -67
- package/src/versions.ts +34 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update-cli",
|
|
3
|
-
"version": "2.22.
|
|
3
|
+
"version": "2.22.8",
|
|
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",
|
|
@@ -66,17 +66,17 @@
|
|
|
66
66
|
"chalk": "4",
|
|
67
67
|
"cli-arguments": "^0.2.1",
|
|
68
68
|
"compare-versions": "^6.1.1",
|
|
69
|
-
"filesize-parser": "^1.5.
|
|
69
|
+
"filesize-parser": "^1.5.2",
|
|
70
70
|
"form-data": "^4.0.6",
|
|
71
|
-
"fs-extra": "^11.
|
|
71
|
+
"fs-extra": "^11.4.0",
|
|
72
72
|
"global-dirs": "^4.0.0",
|
|
73
73
|
"gradle-to-js": "^2.0.1",
|
|
74
|
-
"i18next": "^26.
|
|
74
|
+
"i18next": "^26.4.0",
|
|
75
75
|
"node-fetch": "^2.6.1",
|
|
76
76
|
"plist": "^5.0.0",
|
|
77
77
|
"progress": "^2.0.3",
|
|
78
78
|
"properties": "^1.2.1",
|
|
79
|
-
"protobufjs": "^8.7.
|
|
79
|
+
"protobufjs": "^8.7.2",
|
|
80
80
|
"read": "^4.1.0",
|
|
81
81
|
"registry-auth-token": "^5.1.1",
|
|
82
82
|
"semver": "^7.8.5",
|
|
@@ -91,18 +91,18 @@
|
|
|
91
91
|
"node": ">= 18.17.0"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@babel/parser": "^8.0.
|
|
95
|
-
"@biomejs/biome": "^2.5.
|
|
96
|
-
"@types/bun": "^1.
|
|
94
|
+
"@babel/parser": "^8.0.4",
|
|
95
|
+
"@biomejs/biome": "^2.5.10",
|
|
96
|
+
"@types/bun": "^1.4.0",
|
|
97
97
|
"@types/filesize-parser": "^1.5.3",
|
|
98
98
|
"@types/fs-extra": "^11.0.4",
|
|
99
|
-
"@types/node": "^26.
|
|
99
|
+
"@types/node": "^26.3.0",
|
|
100
100
|
"@types/node-fetch": "^2.6.13",
|
|
101
101
|
"@types/progress": "^2.0.7",
|
|
102
|
-
"@types/semver": "^7.
|
|
102
|
+
"@types/semver": "^7.8.0",
|
|
103
103
|
"@types/yauzl": "^3.4.0",
|
|
104
104
|
"@types/yazl": "^3.3.1",
|
|
105
|
-
"node-hdiffpatch": "^2.
|
|
105
|
+
"node-hdiffpatch": "^2.4.0",
|
|
106
106
|
"typescript": "^7.0.2"
|
|
107
107
|
},
|
|
108
108
|
"trustedDependencies": [
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
}
|