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.
- 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 +11 -4
- package/lib/bundle-runner.js +176 -90
- 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 +22 -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 +21 -4
- package/lib/utils/hermes-base.js +146 -37
- 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 +47 -15
- package/lib/utils/zip-range.js +192 -83
- package/lib/versions.js +19 -9
- 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 +225 -113
- 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 +26 -13
- 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 +156 -45
- 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 +244 -88
- package/src/versions.ts +17 -7
package/lib/utils/hermes-base.js
CHANGED
|
@@ -36,9 +36,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUNDLE_ENTRY_NAMES = exports.MIN_HERMES_COMPILER_COMMITLY_DATE = exports.MIN_HERMES_COMPILER_BUILD = void 0;
|
|
39
|
+
exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUNDLE_ENTRY_NAMES = exports.MIN_HERMES_COMPILER_COMMITLY_DATE = exports.MIN_HERMES_COMPILER_BUILD = exports.BundleHashMismatchError = exports.PermanentBaseError = void 0;
|
|
40
40
|
exports.classifyHermesCommand = classifyHermesCommand;
|
|
41
41
|
exports.sha256Hex = sha256Hex;
|
|
42
|
+
exports.sha256File = sha256File;
|
|
43
|
+
exports.readFileHbcVersion = readFileHbcVersion;
|
|
42
44
|
exports.probeHbcVersion = probeHbcVersion;
|
|
43
45
|
exports.bundleEntryMatcher = bundleEntryMatcher;
|
|
44
46
|
exports.extractBundleFromArchive = extractBundleFromArchive;
|
|
@@ -73,12 +75,33 @@ const crypto_1 = require("crypto");
|
|
|
73
75
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
74
76
|
const os_1 = __importDefault(require("os"));
|
|
75
77
|
const path_1 = __importDefault(require("path"));
|
|
78
|
+
const stream_1 = require("stream");
|
|
76
79
|
const promises_1 = require("stream/promises");
|
|
77
80
|
const constants_1 = require("./constants");
|
|
78
81
|
const hbcTransform_1 = require("./hbcTransform");
|
|
79
82
|
const i18n_1 = require("./i18n");
|
|
80
83
|
const zip_entries_1 = require("./zip-entries");
|
|
81
84
|
const zip_range_1 = require("./zip-range");
|
|
85
|
+
/**
|
|
86
|
+
* The base cannot be obtained whatever the transport or how often it is
|
|
87
|
+
* retried (wrong content on the server, no bundle in the package, ...).
|
|
88
|
+
*/
|
|
89
|
+
class PermanentBaseError extends Error {
|
|
90
|
+
}
|
|
91
|
+
exports.PermanentBaseError = PermanentBaseError;
|
|
92
|
+
/** The fetched bundle's sha256 differs from what the server recorded. */
|
|
93
|
+
class BundleHashMismatchError extends PermanentBaseError {
|
|
94
|
+
constructor(actual, expected) {
|
|
95
|
+
super(`bundleHash mismatch (${actual.slice(0, 12)} != ${expected.slice(0, 12)})`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.BundleHashMismatchError = BundleHashMismatchError;
|
|
99
|
+
/** time allowed for a response to start (headers) */
|
|
100
|
+
const FETCH_HEADERS_TIMEOUT_MS = 30_000;
|
|
101
|
+
/** a download that receives nothing for this long is abandoned */
|
|
102
|
+
const STREAM_IDLE_TIMEOUT_MS = 60_000;
|
|
103
|
+
/** cachePut leftovers (`<hash>.<pid>.tmp`) older than this are evicted */
|
|
104
|
+
const STALE_CACHE_TMP_MS = 60 * 60 * 1000;
|
|
82
105
|
// ---------------------------------------------------------------------------
|
|
83
106
|
// hermesc gating
|
|
84
107
|
// ---------------------------------------------------------------------------
|
|
@@ -166,6 +189,28 @@ function classifyHermesCommand(hermesCommand) {
|
|
|
166
189
|
function sha256Hex(data) {
|
|
167
190
|
return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
168
191
|
}
|
|
192
|
+
/** sha256 of a file, streamed (a cached base can be tens of MB) */
|
|
193
|
+
async function sha256File(file) {
|
|
194
|
+
const hash = (0, crypto_1.createHash)('sha256');
|
|
195
|
+
for await (const chunk of fs_extra_1.default.createReadStream(file))
|
|
196
|
+
hash.update(chunk);
|
|
197
|
+
return hash.digest('hex');
|
|
198
|
+
}
|
|
199
|
+
/** HBC version from the first bytes of a file, without reading the rest */
|
|
200
|
+
async function readFileHbcVersion(file) {
|
|
201
|
+
const header = Buffer.alloc(128);
|
|
202
|
+
const fd = await fs_extra_1.default.open(file, 'r');
|
|
203
|
+
try {
|
|
204
|
+
const { bytesRead } = await fs_extra_1.default.read(fd, header, 0, 128, 0);
|
|
205
|
+
return (0, hbcTransform_1.getHbcVersion)(header.subarray(0, bytesRead));
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
await fs_extra_1.default.close(fd);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
169
214
|
const PROBE_CACHE_FILE = 'hbc-versions.json';
|
|
170
215
|
const PROBE_CACHE_ENTRIES = 16;
|
|
171
216
|
/** identity of a hermesc binary for the probe cache: path + size + mtime */
|
|
@@ -329,8 +374,7 @@ async function cacheLookup(bundleHash) {
|
|
|
329
374
|
const file = path_1.default.join(cacheDir(), bundleHash);
|
|
330
375
|
if (!(await fs_extra_1.default.pathExists(file)))
|
|
331
376
|
return null;
|
|
332
|
-
|
|
333
|
-
if (sha256Hex(data) !== bundleHash) {
|
|
377
|
+
if ((await sha256File(file).catch(() => '')) !== bundleHash) {
|
|
334
378
|
// corrupt entry: never trust cache content
|
|
335
379
|
await fs_extra_1.default.remove(file).catch(() => { });
|
|
336
380
|
return null;
|
|
@@ -363,12 +407,21 @@ async function enforceCacheLimits(maxMb, keep) {
|
|
|
363
407
|
return;
|
|
364
408
|
const { maxBytes, maxFiles } = cacheLimits(maxMb);
|
|
365
409
|
const entries = [];
|
|
410
|
+
const staleTmpCutoff = Date.now() - STALE_CACHE_TMP_MS;
|
|
366
411
|
for (const name of await fs_extra_1.default.readdir(dir)) {
|
|
367
|
-
|
|
412
|
+
const isTmp = isCacheTmpName(name);
|
|
413
|
+
if (!isTmp && !/^[0-9a-f]{64}$/.test(name))
|
|
368
414
|
continue;
|
|
369
415
|
const stat = await fs_extra_1.default.stat(path_1.default.join(dir, name)).catch(() => null);
|
|
370
|
-
if (stat?.isFile())
|
|
371
|
-
|
|
416
|
+
if (!stat?.isFile())
|
|
417
|
+
continue;
|
|
418
|
+
if (isTmp) {
|
|
419
|
+
// an interrupted cachePut; nothing will ever rename it into place
|
|
420
|
+
if (stat.mtimeMs < staleTmpCutoff)
|
|
421
|
+
await fs_extra_1.default.remove(path_1.default.join(dir, name)).catch(() => { });
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
entries.push({ name, size: stat.size, mtime: stat.mtimeMs });
|
|
372
425
|
}
|
|
373
426
|
entries.sort((a, b) => b.mtime - a.mtime); // newest first
|
|
374
427
|
let total = 0;
|
|
@@ -381,14 +434,25 @@ async function enforceCacheLimits(maxMb, keep) {
|
|
|
381
434
|
}
|
|
382
435
|
}
|
|
383
436
|
}
|
|
437
|
+
/** `<sha256>.<pid>.tmp`, the staging name cachePut writes before renaming */
|
|
438
|
+
function isCacheTmpName(name) {
|
|
439
|
+
return /^[0-9a-f]{64}\.\d+\.tmp$/.test(name);
|
|
440
|
+
}
|
|
441
|
+
/** Remove every cached bundle (and staging leftovers); returns the bundle count. */
|
|
384
442
|
async function cleanCache() {
|
|
385
443
|
const dir = cacheDir();
|
|
386
444
|
if (!(await fs_extra_1.default.pathExists(dir)))
|
|
387
445
|
return 0;
|
|
388
|
-
|
|
389
|
-
for (const name of
|
|
446
|
+
let bundles = 0;
|
|
447
|
+
for (const name of await fs_extra_1.default.readdir(dir)) {
|
|
448
|
+
const isBundle = /^[0-9a-f]{64}$/.test(name);
|
|
449
|
+
if (!isBundle && !isCacheTmpName(name))
|
|
450
|
+
continue;
|
|
390
451
|
await fs_extra_1.default.remove(path_1.default.join(dir, name));
|
|
391
|
-
|
|
452
|
+
if (isBundle)
|
|
453
|
+
bundles += 1;
|
|
454
|
+
}
|
|
455
|
+
return bundles;
|
|
392
456
|
}
|
|
393
457
|
async function cacheStats() {
|
|
394
458
|
const dir = cacheDir();
|
|
@@ -424,13 +488,19 @@ async function cleanStaleTmp(maxAgeMs = 24 * 60 * 60 * 1000) {
|
|
|
424
488
|
// download
|
|
425
489
|
// ---------------------------------------------------------------------------
|
|
426
490
|
async function downloadToFile(url, destination) {
|
|
427
|
-
const
|
|
491
|
+
const controller = new AbortController();
|
|
492
|
+
const headersTimer = setTimeout(() => controller.abort(new Error('timeout waiting for response')), FETCH_HEADERS_TIMEOUT_MS);
|
|
493
|
+
let response;
|
|
494
|
+
try {
|
|
495
|
+
response = await fetch(url, { signal: controller.signal });
|
|
496
|
+
}
|
|
497
|
+
finally {
|
|
498
|
+
clearTimeout(headersTimer);
|
|
499
|
+
}
|
|
428
500
|
if (!response.ok || !response.body) {
|
|
429
501
|
throw new Error(`download failed: HTTP ${response.status} ${url}`);
|
|
430
502
|
}
|
|
431
|
-
await
|
|
432
|
-
const { Readable } = await Promise.resolve().then(() => __importStar(require('stream')));
|
|
433
|
-
await (0, promises_1.pipeline)(Readable.fromWeb(response.body), fs_extra_1.default.createWriteStream(destination));
|
|
503
|
+
await saveResponse(response, destination, controller);
|
|
434
504
|
}
|
|
435
505
|
function hasBundleLocation(record) {
|
|
436
506
|
return (record.bundleOffset != null &&
|
|
@@ -439,12 +509,30 @@ function hasBundleLocation(record) {
|
|
|
439
509
|
(record.bundleCompression === zip_range_1.ZIP_STORED ||
|
|
440
510
|
record.bundleCompression === zip_range_1.ZIP_DEFLATED));
|
|
441
511
|
}
|
|
442
|
-
|
|
512
|
+
/**
|
|
513
|
+
* Stream a response body to disk, giving up when no bytes arrive for
|
|
514
|
+
* STREAM_IDLE_TIMEOUT_MS. `controller` is the one the request was made with
|
|
515
|
+
* (aborting it also tears down the socket); a foreign response gets its own.
|
|
516
|
+
*/
|
|
517
|
+
async function saveResponse(response, destination, controller = new AbortController()) {
|
|
443
518
|
if (!response.body)
|
|
444
519
|
throw new Error('empty response body');
|
|
445
520
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(destination));
|
|
446
|
-
const
|
|
447
|
-
|
|
521
|
+
const abort = () => controller.abort(new Error(`download stalled for ${STREAM_IDLE_TIMEOUT_MS / 1000}s`));
|
|
522
|
+
let idle = setTimeout(abort, STREAM_IDLE_TIMEOUT_MS);
|
|
523
|
+
const watchdog = new stream_1.PassThrough({
|
|
524
|
+
transform(chunk, _encoding, callback) {
|
|
525
|
+
clearTimeout(idle);
|
|
526
|
+
idle = setTimeout(abort, STREAM_IDLE_TIMEOUT_MS);
|
|
527
|
+
callback(null, chunk);
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
try {
|
|
531
|
+
await (0, promises_1.pipeline)(stream_1.Readable.fromWeb(response.body), watchdog, fs_extra_1.default.createWriteStream(destination), { signal: controller.signal });
|
|
532
|
+
}
|
|
533
|
+
finally {
|
|
534
|
+
clearTimeout(idle);
|
|
535
|
+
}
|
|
448
536
|
}
|
|
449
537
|
/**
|
|
450
538
|
* Obtain the base bundle with as little traffic as possible, in order:
|
|
@@ -456,27 +544,29 @@ async function saveResponse(response, destination) {
|
|
|
456
544
|
* is skipped);
|
|
457
545
|
* 3. the whole archive, as before.
|
|
458
546
|
* A server that ignores Range (HTTP 200) streams the full archive into
|
|
459
|
-
* `archive` without a second request.
|
|
460
|
-
* `record.bundleHash
|
|
461
|
-
*
|
|
547
|
+
* `archive` without a second request. Every result is verified against
|
|
548
|
+
* `record.bundleHash`. A mismatch of the located bytes (1) may only mean the
|
|
549
|
+
* recorded location is stale, so the directory transport (2) still runs; a
|
|
550
|
+
* mismatch of the entry itself (2, 3) is final — the same bytes would come
|
|
551
|
+
* back however they are fetched — and raises BundleHashMismatchError.
|
|
462
552
|
*/
|
|
463
553
|
async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
464
554
|
const matches = bundleEntryMatcher(artifactType);
|
|
465
555
|
const verified = (bundle) => {
|
|
466
556
|
if (!bundle)
|
|
467
|
-
throw new
|
|
557
|
+
throw new PermanentBaseError('bundle entry not found');
|
|
468
558
|
const bundleHash = sha256Hex(bundle);
|
|
469
559
|
if (record.bundleHash && bundleHash !== record.bundleHash) {
|
|
470
|
-
throw new
|
|
560
|
+
throw new BundleHashMismatchError(bundleHash, record.bundleHash);
|
|
471
561
|
}
|
|
472
562
|
return { bundle, bundleHash };
|
|
473
563
|
};
|
|
474
564
|
const fromFullResponse = async (response) => {
|
|
475
565
|
await saveResponse(response, archive);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
566
|
+
return {
|
|
567
|
+
...verified(await extractBundleFromArchive(archive)),
|
|
568
|
+
transport: 'full',
|
|
569
|
+
};
|
|
480
570
|
};
|
|
481
571
|
const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
|
|
482
572
|
// harmony .app nests the bundle in a second zip, so a location inside the
|
|
@@ -523,14 +613,17 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
523
613
|
skip('server ignores Range');
|
|
524
614
|
return fromFullResponse(error.response);
|
|
525
615
|
}
|
|
616
|
+
// the real entry was read and is not the recorded one: final
|
|
617
|
+
if (error instanceof PermanentBaseError)
|
|
618
|
+
throw error;
|
|
526
619
|
skip(`zip range: ${error?.message ?? error}`);
|
|
527
620
|
}
|
|
528
621
|
}
|
|
529
622
|
await downloadToFile(record.url, archive);
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
623
|
+
return {
|
|
624
|
+
...verified(await extractBundleFromArchive(archive)),
|
|
625
|
+
transport: 'full',
|
|
626
|
+
};
|
|
534
627
|
}
|
|
535
628
|
/**
|
|
536
629
|
* Pick and materialize the base bundle for this compile. Returns null (with
|
|
@@ -576,7 +669,7 @@ async function resolveHermesBase(params) {
|
|
|
576
669
|
}
|
|
577
670
|
let record = null;
|
|
578
671
|
try {
|
|
579
|
-
record = await params.fetchBase(params.appId, bytecodeVersion);
|
|
672
|
+
record = await retryOnce(() => params.fetchBase(params.appId, bytecodeVersion));
|
|
580
673
|
}
|
|
581
674
|
catch (error) {
|
|
582
675
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
@@ -603,6 +696,17 @@ async function resolveHermesBase(params) {
|
|
|
603
696
|
// 1. cache by bundleHash
|
|
604
697
|
if (record.bundleHash) {
|
|
605
698
|
const hit = await cacheLookup(record.bundleHash);
|
|
699
|
+
if (hit && record.bytecodeVersion == null) {
|
|
700
|
+
// the server does not know the HBC version (legacy version, native
|
|
701
|
+
// package): the download path checks it, the cache path must too
|
|
702
|
+
const version = await readFileHbcVersion(hit);
|
|
703
|
+
if (version !== bytecodeVersion) {
|
|
704
|
+
log((0, i18n_1.t)('hermesBaseNone', {
|
|
705
|
+
reason: `cached base is HBC ${version ?? 'n/a'}, need ${bytecodeVersion}`,
|
|
706
|
+
}));
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
606
710
|
if (hit) {
|
|
607
711
|
log((0, i18n_1.t)('hermesBaseUsing', {
|
|
608
712
|
source: `cache ${record.bundleHash.slice(0, 12)}${record.versionId == null ? '' : ` (version ${record.versionId})`}`,
|
|
@@ -618,7 +722,7 @@ async function resolveHermesBase(params) {
|
|
|
618
722
|
};
|
|
619
723
|
}
|
|
620
724
|
}
|
|
621
|
-
// 2. download, extract, verify, cache —
|
|
725
|
+
// 2. download, extract, verify, cache — transport errors get a second try
|
|
622
726
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
623
727
|
const dir = tmpDir();
|
|
624
728
|
await fs_extra_1.default.ensureDir(dir);
|
|
@@ -634,8 +738,6 @@ async function resolveHermesBase(params) {
|
|
|
634
738
|
try {
|
|
635
739
|
log((0, i18n_1.t)('hermesBaseDownloading', { url: record.url }));
|
|
636
740
|
const fetched = await fetchBaseBundle(record, artifactType, archive, log);
|
|
637
|
-
if (!fetched)
|
|
638
|
-
throw new Error('bundle entry not found in downloaded package');
|
|
639
741
|
const { bundle, bundleHash: actualHash } = fetched;
|
|
640
742
|
if (fetched.transport !== 'full') {
|
|
641
743
|
log((0, i18n_1.t)('hermesBaseRangeFetched', {
|
|
@@ -643,9 +745,6 @@ async function resolveHermesBase(params) {
|
|
|
643
745
|
totalKb: Math.ceil((fetched.totalBytes ?? 0) / 1024),
|
|
644
746
|
}));
|
|
645
747
|
}
|
|
646
|
-
if (record.bundleHash && actualHash !== record.bundleHash) {
|
|
647
|
-
throw new Error(`bundleHash mismatch (${actualHash.slice(0, 12)} != ${record.bundleHash.slice(0, 12)})`);
|
|
648
|
-
}
|
|
649
748
|
const version = (0, hbcTransform_1.getHbcVersion)(bundle);
|
|
650
749
|
if (version !== bytecodeVersion) {
|
|
651
750
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
@@ -670,7 +769,7 @@ async function resolveHermesBase(params) {
|
|
|
670
769
|
};
|
|
671
770
|
}
|
|
672
771
|
catch (error) {
|
|
673
|
-
if (attempt === 2) {
|
|
772
|
+
if (attempt === 2 || error instanceof PermanentBaseError) {
|
|
674
773
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
675
774
|
reason: `download/verify failed: ${error?.message ?? error}`,
|
|
676
775
|
}));
|
|
@@ -683,6 +782,16 @@ async function resolveHermesBase(params) {
|
|
|
683
782
|
}
|
|
684
783
|
return null;
|
|
685
784
|
}
|
|
785
|
+
/** one retry after a short pause, for transient network failures */
|
|
786
|
+
async function retryOnce(action) {
|
|
787
|
+
try {
|
|
788
|
+
return await action();
|
|
789
|
+
}
|
|
790
|
+
catch {
|
|
791
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
792
|
+
return action();
|
|
793
|
+
}
|
|
794
|
+
}
|
|
686
795
|
function hermescArgsWithBase(baseArgs, basePath) {
|
|
687
796
|
return basePath ? [...baseArgs, `-base-bytecode=${basePath}`] : baseArgs;
|
|
688
797
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export declare function promiseAny<T>(promises: Promise<T>[]): Promise<T>;
|
|
2
2
|
export declare const ping: (url: string, signal?: AbortSignal) => Promise<string | null>;
|
|
3
3
|
export declare const testUrls: (urls?: string[], hedgeDelayMs?: number) => Promise<string | null>;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The API base url: the env override, or the first default endpoint that
|
|
6
|
+
* answers a HEAD ping. Resolved lazily on the first API call (offline commands
|
|
7
|
+
* such as `hdiff`/`help` never ping) and memoized for the process lifetime.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getBaseUrl: () => Promise<string>;
|
package/lib/utils/http-helper.js
CHANGED
|
@@ -111,18 +111,30 @@ const testUrls = async (urls, hedgeDelayMs = HEDGE_DELAY_MS) => {
|
|
|
111
111
|
});
|
|
112
112
|
};
|
|
113
113
|
exports.testUrls = testUrls;
|
|
114
|
-
|
|
114
|
+
let baseUrlPromise;
|
|
115
|
+
async function resolveBaseUrl() {
|
|
115
116
|
const testEndpoint = process.env.PUSHY_REGISTRY || process.env.RNU_API;
|
|
116
117
|
if (testEndpoint) {
|
|
117
118
|
return testEndpoint;
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
120
|
+
const ret = await (0, exports.testUrls)(constants_1.defaultEndpoints.map((url) => `${url}/status`));
|
|
121
|
+
let baseUrl = constants_1.defaultEndpoints[0];
|
|
122
|
+
if (ret) {
|
|
123
|
+
// remove /status
|
|
124
|
+
baseUrl = ret.replace('/status', '');
|
|
125
|
+
}
|
|
126
|
+
// console.log('baseUrl', baseUrl);
|
|
127
|
+
return baseUrl;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The API base url: the env override, or the first default endpoint that
|
|
131
|
+
* answers a HEAD ping. Resolved lazily on the first API call (offline commands
|
|
132
|
+
* such as `hdiff`/`help` never ping) and memoized for the process lifetime.
|
|
133
|
+
*/
|
|
134
|
+
const getBaseUrl = () => {
|
|
135
|
+
if (!baseUrlPromise) {
|
|
136
|
+
baseUrlPromise = resolveBaseUrl();
|
|
137
|
+
}
|
|
138
|
+
return baseUrlPromise;
|
|
139
|
+
};
|
|
140
|
+
exports.getBaseUrl = getBaseUrl;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { checkPlugins } from './check-plugin';
|
|
2
|
+
/**
|
|
3
|
+
* tty-table (~25 ms to load) only when a table is rendered. Bun's require of
|
|
4
|
+
* a CJS module can hand back a namespace object, so unwrap `default`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadTtyTable(): typeof import('tty-table');
|
|
2
7
|
export declare function isNonInteractive(): boolean;
|
|
3
8
|
export declare function question(query: string, password?: boolean): Promise<string>;
|
|
4
9
|
export declare function translateOptions<T extends Record<string, unknown>>(options: T, map?: Record<string, string>): T & Record<string, unknown>;
|
|
@@ -27,5 +32,29 @@ export declare function getAabInfo(fn: string): Promise<{
|
|
|
27
32
|
buildTime: number;
|
|
28
33
|
bundleHash?: string | undefined;
|
|
29
34
|
}>;
|
|
30
|
-
export
|
|
35
|
+
export interface VersionCheck {
|
|
36
|
+
/** settles once the registry check has finished (or failed); never rejects */
|
|
37
|
+
done: Promise<void>;
|
|
38
|
+
/** wait for the check, but never longer than `graceMs` */
|
|
39
|
+
settle: (graceMs: number) => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Print the "newer version available" hints if the check has completed by
|
|
42
|
+
* now; a no-op while it is still pending, when nothing is newer, and after
|
|
43
|
+
* the first call. Safe to call from a process 'exit' handler.
|
|
44
|
+
*/
|
|
45
|
+
printHints: () => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Print the installed CLI / react-native-update versions (and refuse or warn
|
|
49
|
+
* about unsupported client versions) immediately, without touching the
|
|
50
|
+
* network.
|
|
51
|
+
*
|
|
52
|
+
* With `wait: true` (the `-v`/`version` command) the registry is queried
|
|
53
|
+
* first and the latest versions are printed inline. Otherwise the registry
|
|
54
|
+
* check runs in the background and the returned `printHints` shows what is
|
|
55
|
+
* newer once the command is done — the command itself is never delayed by it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function printVersionCommand({ wait, }?: {
|
|
58
|
+
wait?: boolean;
|
|
59
|
+
}): Promise<VersionCheck>;
|
|
31
60
|
export { checkPlugins };
|
package/lib/utils/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.checkPlugins = exports.IpaBundleFileName = exports.ApkBundleFileName = void 0;
|
|
7
|
+
exports.loadTtyTable = loadTtyTable;
|
|
7
8
|
exports.isNonInteractive = isNonInteractive;
|
|
8
9
|
exports.question = question;
|
|
9
10
|
exports.translateOptions = translateOptions;
|
|
@@ -19,13 +20,25 @@ const path_1 = __importDefault(require("path"));
|
|
|
19
20
|
const read_1 = require("read");
|
|
20
21
|
const yauzl_1 = require("yauzl");
|
|
21
22
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
22
|
-
const latest_version_1 = __importDefault(require("../utils/latest-version"));
|
|
23
|
-
const app_info_parser_1 = __importDefault(require("./app-info-parser"));
|
|
24
23
|
const check_plugin_1 = require("./check-plugin");
|
|
25
24
|
Object.defineProperty(exports, "checkPlugins", { enumerable: true, get: function () { return check_plugin_1.checkPlugins; } });
|
|
26
25
|
const constants_1 = require("./constants");
|
|
27
26
|
const dep_versions_1 = require("./dep-versions");
|
|
28
27
|
const i18n_1 = require("./i18n");
|
|
28
|
+
// app-info-parser (and its zip/plist/protobuf stack) is only needed by the
|
|
29
|
+
// package commands; load it on first use instead of on every CLI start.
|
|
30
|
+
function createAppInfoParser(fn) {
|
|
31
|
+
const { default: AppInfoParser } = require('./app-info-parser');
|
|
32
|
+
return new AppInfoParser(fn);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* tty-table (~25 ms to load) only when a table is rendered. Bun's require of
|
|
36
|
+
* a CJS module can hand back a namespace object, so unwrap `default`.
|
|
37
|
+
*/
|
|
38
|
+
function loadTtyTable() {
|
|
39
|
+
const mod = require('tty-table');
|
|
40
|
+
return (mod.default ?? mod);
|
|
41
|
+
}
|
|
29
42
|
function isNonInteractive() {
|
|
30
43
|
const envValue = process.env.NO_INTERACTIVE?.toLowerCase();
|
|
31
44
|
return (global.NO_INTERACTIVE === true || envValue === 'true' || envValue === '1');
|
|
@@ -90,7 +103,7 @@ async function sha256(data) {
|
|
|
90
103
|
exports.ApkBundleFileName = /^assets\/index\.android\.bundle$/;
|
|
91
104
|
const ApkUpdateJsonName = /^res\/raw\/update\.json$/;
|
|
92
105
|
async function getApkInfo(fn) {
|
|
93
|
-
const appInfoParser =
|
|
106
|
+
const appInfoParser = createAppInfoParser(fn);
|
|
94
107
|
// read both entries in a single scan over the archive
|
|
95
108
|
const entries = await appInfoParser.parser.getEntries([
|
|
96
109
|
exports.ApkBundleFileName,
|
|
@@ -135,7 +148,7 @@ async function getApkInfo(fn) {
|
|
|
135
148
|
};
|
|
136
149
|
}
|
|
137
150
|
async function getAppInfo(fn) {
|
|
138
|
-
const appInfoParser =
|
|
151
|
+
const appInfoParser = createAppInfoParser(fn);
|
|
139
152
|
// single scan (and single nested .hap extraction) for all three entries
|
|
140
153
|
const [bundleFile, updateJsonFile, metaJsonFile] = await appInfoParser.parser.getEntriesFromHarmonyApp([
|
|
141
154
|
/^resources\/rawfile\/bundle\.harmony\.js$/,
|
|
@@ -180,7 +193,7 @@ const IpaBuildTimeName = /^payload\/[^/]+\.app\/pushy_build_time\.txt$/;
|
|
|
180
193
|
// Not in root bundle when use `use_frameworks`
|
|
181
194
|
const IpaBuildTimeFrameworkName = /^payload\/[^/]+\.app\/frameworks\/react_native_update\.framework\/pushy_build_time\.txt$/;
|
|
182
195
|
async function getIpaInfo(fn) {
|
|
183
|
-
const appInfoParser =
|
|
196
|
+
const appInfoParser = createAppInfoParser(fn);
|
|
184
197
|
// read all four entries in a single scan over the archive
|
|
185
198
|
const entries = await appInfoParser.parser.getEntries([
|
|
186
199
|
exports.IpaBundleFileName,
|
|
@@ -383,33 +396,72 @@ async function resolveResource(fn, resourceId, root) {
|
|
|
383
396
|
}
|
|
384
397
|
return null;
|
|
385
398
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
399
|
+
const VERSION_CHECK_PACKAGES = [
|
|
400
|
+
'react-native-update-cli',
|
|
401
|
+
'react-native-update',
|
|
402
|
+
];
|
|
403
|
+
/**
|
|
404
|
+
* Latest registry versions of the CLI and the client library, in that order
|
|
405
|
+
* (`undefined` where unknown). Never rejects.
|
|
406
|
+
*
|
|
407
|
+
* `background: true` answers from a 1-day cache when possible and otherwise
|
|
408
|
+
* refreshes it with an unref'd request, so the process is free to exit before
|
|
409
|
+
* the registry answers; `background: false` always asks the registry and
|
|
410
|
+
* waits (refreshing the cache on the way).
|
|
411
|
+
*/
|
|
412
|
+
async function getLatestVersions(background) {
|
|
413
|
+
// the registry client pulls in global-dirs/registry-auth-token/semver: only
|
|
414
|
+
// pay for them when actually checking
|
|
415
|
+
const { default: latestVersion } = require('./latest-version');
|
|
416
|
+
return latestVersion(VERSION_CHECK_PACKAGES, {
|
|
417
|
+
useCache: true,
|
|
418
|
+
...(background ? { unref: true } : { cacheMaxAge: 0 }),
|
|
389
419
|
requestOptions: {
|
|
390
420
|
timeout: 2000,
|
|
391
421
|
},
|
|
392
422
|
})
|
|
393
423
|
.then((pkgs) => pkgs.map((pkg) => pkg.latest))
|
|
394
|
-
.catch(() =>
|
|
424
|
+
.catch(() => VERSION_CHECK_PACKAGES.map(() => undefined));
|
|
395
425
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
426
|
+
function isNewer(latest, current) {
|
|
427
|
+
if (!latest || !current) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
return (0, compare_versions_1.compare)(latest, current, '>');
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function latestTag(version) {
|
|
438
|
+
return version
|
|
439
|
+
? ` ${(0, i18n_1.t)('latestVersionTag', { version: chalk_1.default.green(version) })}`
|
|
405
440
|
: '';
|
|
406
|
-
|
|
407
|
-
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Print the installed CLI / react-native-update versions (and refuse or warn
|
|
444
|
+
* about unsupported client versions) immediately, without touching the
|
|
445
|
+
* network.
|
|
446
|
+
*
|
|
447
|
+
* With `wait: true` (the `-v`/`version` command) the registry is queried
|
|
448
|
+
* first and the latest versions are printed inline. Otherwise the registry
|
|
449
|
+
* check runs in the background and the returned `printHints` shows what is
|
|
450
|
+
* newer once the command is done — the command itself is never delayed by it.
|
|
451
|
+
*/
|
|
452
|
+
async function printVersionCommand({ wait = true, } = {}) {
|
|
453
|
+
const rnuVersion = (0, dep_versions_1.getDepVersions)()['react-native-update'];
|
|
454
|
+
let latest;
|
|
455
|
+
const check = getLatestVersions(!wait).then((versions) => {
|
|
456
|
+
latest = versions;
|
|
457
|
+
});
|
|
458
|
+
if (wait) {
|
|
459
|
+
await check;
|
|
460
|
+
}
|
|
461
|
+
const [latestCliVersion, latestRnuVersion] = latest ?? [];
|
|
462
|
+
console.log(`react-native-update-cli: ${package_json_1.default.version}${latestTag(latestCliVersion)}`);
|
|
408
463
|
if (rnuVersion) {
|
|
409
|
-
|
|
410
|
-
? ` ${(0, i18n_1.t)('latestVersionTag', { version: chalk_1.default.green(latestRnuVersion) })}`
|
|
411
|
-
: '';
|
|
412
|
-
console.log(`react-native-update: ${rnuVersion}${latestRnuVersion}`);
|
|
464
|
+
console.log(`react-native-update: ${rnuVersion}${latestTag(latestRnuVersion)}`);
|
|
413
465
|
if (constants_1.IS_CRESC) {
|
|
414
466
|
if ((0, compare_versions_1.satisfies)(rnuVersion, '<10.27.0')) {
|
|
415
467
|
console.error('Unsupported version, please update to the latest version: npm i react-native-update@latest');
|
|
@@ -433,4 +485,26 @@ async function printVersionCommand() {
|
|
|
433
485
|
else {
|
|
434
486
|
console.log((0, i18n_1.t)('rnuVersionNotFound'));
|
|
435
487
|
}
|
|
488
|
+
let hinted = wait; // inline tags already shown
|
|
489
|
+
const printHints = () => {
|
|
490
|
+
if (hinted || !latest) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
hinted = true;
|
|
494
|
+
const [cliLatest, rnuLatest] = latest;
|
|
495
|
+
if (isNewer(cliLatest, package_json_1.default.version)) {
|
|
496
|
+
console.log(`react-native-update-cli: ${package_json_1.default.version}${latestTag(cliLatest)}`);
|
|
497
|
+
}
|
|
498
|
+
if (rnuVersion && isNewer(rnuLatest, rnuVersion)) {
|
|
499
|
+
console.log(`react-native-update: ${rnuVersion}${latestTag(rnuLatest)}`);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
const settle = (graceMs) => {
|
|
503
|
+
let timer;
|
|
504
|
+
const grace = new Promise((resolve) => {
|
|
505
|
+
timer = setTimeout(resolve, graceMs);
|
|
506
|
+
});
|
|
507
|
+
return Promise.race([check, grace]).then(() => clearTimeout(timer));
|
|
508
|
+
};
|
|
509
|
+
return { done: check, settle, printHints };
|
|
436
510
|
}
|
|
@@ -61,23 +61,26 @@ interface LatestVersionOptions {
|
|
|
61
61
|
* Awaiting the api to return might take time, depending on the network, and might impact your package loading performance.
|
|
62
62
|
* You can use the cache mechanism to improve load performance and reduce unnecessary network requests.
|
|
63
63
|
* If `useCache` is not supplied, the api will always check for updates and wait for every requests to return before returning itself.
|
|
64
|
-
* If `useCache` is used
|
|
65
|
-
* 1) a
|
|
66
|
-
* 2)
|
|
67
|
-
*
|
|
64
|
+
* If `useCache` is used (for each provided package):
|
|
65
|
+
* 1) a fresh cache (younger than `cacheMaxAge`, from the same registry) answers without any network request
|
|
66
|
+
* 2) otherwise the registry is queried and the cache refreshed; when that query fails, a stale cache (if any) is used instead.
|
|
67
|
+
* Combine with `unref` so a slow refresh never keeps the process alive.
|
|
68
68
|
* @default false
|
|
69
69
|
*/
|
|
70
70
|
readonly useCache?: boolean;
|
|
71
71
|
/**
|
|
72
72
|
* How long the cache for the provided packages should be used before being refreshed (in milliseconds).
|
|
73
73
|
* If `useCache` is not supplied, this option has no effect.
|
|
74
|
-
* If `0` is used,
|
|
75
|
-
* 1) The api will returned immediately (without any latest nor next version available for the provided packages)
|
|
76
|
-
* 2) New updates will be fetched in the background
|
|
77
|
-
* 3) The cache for each provided packages will be refreshed and made available for the next call to the api
|
|
74
|
+
* If `0` is used, the cache is always refreshed (a stale cache still serves as a fallback when the refresh fails).
|
|
78
75
|
* @default ONE_DAY
|
|
79
76
|
*/
|
|
80
77
|
readonly cacheMaxAge?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Do not let the registry request keep the process alive: its socket is `unref`'d, so the process may exit before the
|
|
80
|
+
* request completes (the returned promise then simply never settles). Use for opportunistic background checks.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
readonly unref?: boolean;
|
|
81
84
|
/**
|
|
82
85
|
* A JavaScript package registry url that implements the CommonJS Package Registry specification.
|
|
83
86
|
* @default "Looks at any registry urls in the .npmrc file or fallback to the default npm registry instead"
|