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/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,8 +189,82 @@ function classifyHermesCommand(hermesCommand) {
|
|
|
166
189
|
function sha256Hex(data) {
|
|
167
190
|
return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
168
191
|
}
|
|
169
|
-
/**
|
|
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
|
+
}
|
|
214
|
+
const PROBE_CACHE_FILE = 'hbc-versions.json';
|
|
215
|
+
const PROBE_CACHE_ENTRIES = 16;
|
|
216
|
+
/** identity of a hermesc binary for the probe cache: path + size + mtime */
|
|
217
|
+
function probeCacheKey(hermesCommand) {
|
|
218
|
+
try {
|
|
219
|
+
const stat = fs_extra_1.default.statSync(hermesCommand);
|
|
220
|
+
return `${path_1.default.resolve(hermesCommand)}|${stat.size}|${Math.floor(stat.mtimeMs)}`;
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function readProbeCache() {
|
|
227
|
+
try {
|
|
228
|
+
const parsed = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), 'utf8'));
|
|
229
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return {};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function writeProbeCache(entries) {
|
|
236
|
+
try {
|
|
237
|
+
const keys = Object.keys(entries);
|
|
238
|
+
// keep the most recently inserted entries only
|
|
239
|
+
const trimmed = Object.fromEntries(keys.slice(-PROBE_CACHE_ENTRIES).map((key) => [key, entries[key]]));
|
|
240
|
+
fs_extra_1.default.ensureDirSync(cacheDir());
|
|
241
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), JSON.stringify(trimmed));
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
// the cache is a convenience; probing again next time is fine
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Which HBC version this hermesc emits. The answer is remembered per binary
|
|
249
|
+
* (path, size, mtime) in the cache dir so only the first run of a given
|
|
250
|
+
* hermesc pays for the empty-file compile.
|
|
251
|
+
*/
|
|
170
252
|
function probeHbcVersion(hermesCommand) {
|
|
253
|
+
const key = probeCacheKey(hermesCommand);
|
|
254
|
+
if (key) {
|
|
255
|
+
const cached = readProbeCache()[key];
|
|
256
|
+
if (Number.isInteger(cached) && cached > 0)
|
|
257
|
+
return cached;
|
|
258
|
+
}
|
|
259
|
+
const version = compileProbe(hermesCommand);
|
|
260
|
+
if (key && version !== null) {
|
|
261
|
+
const { [key]: _stale, ...others } = readProbeCache();
|
|
262
|
+
writeProbeCache({ ...others, [key]: version });
|
|
263
|
+
}
|
|
264
|
+
return version;
|
|
265
|
+
}
|
|
266
|
+
/** Compile an empty file to learn which HBC version this hermesc emits. */
|
|
267
|
+
function compileProbe(hermesCommand) {
|
|
171
268
|
const dir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-hermes-probe-'));
|
|
172
269
|
try {
|
|
173
270
|
const input = path_1.default.join(dir, 'probe.js');
|
|
@@ -277,8 +374,7 @@ async function cacheLookup(bundleHash) {
|
|
|
277
374
|
const file = path_1.default.join(cacheDir(), bundleHash);
|
|
278
375
|
if (!(await fs_extra_1.default.pathExists(file)))
|
|
279
376
|
return null;
|
|
280
|
-
|
|
281
|
-
if (sha256Hex(data) !== bundleHash) {
|
|
377
|
+
if ((await sha256File(file).catch(() => '')) !== bundleHash) {
|
|
282
378
|
// corrupt entry: never trust cache content
|
|
283
379
|
await fs_extra_1.default.remove(file).catch(() => { });
|
|
284
380
|
return null;
|
|
@@ -288,8 +384,8 @@ async function cacheLookup(bundleHash) {
|
|
|
288
384
|
return file;
|
|
289
385
|
}
|
|
290
386
|
/** Store a bundle under its sha256 (LRU-evicting to the configured limits). */
|
|
291
|
-
async function cachePut(bundle, maxMb) {
|
|
292
|
-
const bundleHash = sha256Hex(bundle);
|
|
387
|
+
async function cachePut(bundle, maxMb, knownHash) {
|
|
388
|
+
const bundleHash = knownHash ?? sha256Hex(bundle);
|
|
293
389
|
const dir = cacheDir();
|
|
294
390
|
await fs_extra_1.default.ensureDir(dir);
|
|
295
391
|
const file = path_1.default.join(dir, bundleHash);
|
|
@@ -311,12 +407,21 @@ async function enforceCacheLimits(maxMb, keep) {
|
|
|
311
407
|
return;
|
|
312
408
|
const { maxBytes, maxFiles } = cacheLimits(maxMb);
|
|
313
409
|
const entries = [];
|
|
410
|
+
const staleTmpCutoff = Date.now() - STALE_CACHE_TMP_MS;
|
|
314
411
|
for (const name of await fs_extra_1.default.readdir(dir)) {
|
|
315
|
-
|
|
412
|
+
const isTmp = isCacheTmpName(name);
|
|
413
|
+
if (!isTmp && !/^[0-9a-f]{64}$/.test(name))
|
|
316
414
|
continue;
|
|
317
415
|
const stat = await fs_extra_1.default.stat(path_1.default.join(dir, name)).catch(() => null);
|
|
318
|
-
if (stat?.isFile())
|
|
319
|
-
|
|
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 });
|
|
320
425
|
}
|
|
321
426
|
entries.sort((a, b) => b.mtime - a.mtime); // newest first
|
|
322
427
|
let total = 0;
|
|
@@ -329,14 +434,25 @@ async function enforceCacheLimits(maxMb, keep) {
|
|
|
329
434
|
}
|
|
330
435
|
}
|
|
331
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. */
|
|
332
442
|
async function cleanCache() {
|
|
333
443
|
const dir = cacheDir();
|
|
334
444
|
if (!(await fs_extra_1.default.pathExists(dir)))
|
|
335
445
|
return 0;
|
|
336
|
-
|
|
337
|
-
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;
|
|
338
451
|
await fs_extra_1.default.remove(path_1.default.join(dir, name));
|
|
339
|
-
|
|
452
|
+
if (isBundle)
|
|
453
|
+
bundles += 1;
|
|
454
|
+
}
|
|
455
|
+
return bundles;
|
|
340
456
|
}
|
|
341
457
|
async function cacheStats() {
|
|
342
458
|
const dir = cacheDir();
|
|
@@ -372,13 +488,19 @@ async function cleanStaleTmp(maxAgeMs = 24 * 60 * 60 * 1000) {
|
|
|
372
488
|
// download
|
|
373
489
|
// ---------------------------------------------------------------------------
|
|
374
490
|
async function downloadToFile(url, destination) {
|
|
375
|
-
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
|
+
}
|
|
376
500
|
if (!response.ok || !response.body) {
|
|
377
501
|
throw new Error(`download failed: HTTP ${response.status} ${url}`);
|
|
378
502
|
}
|
|
379
|
-
await
|
|
380
|
-
const { Readable } = await Promise.resolve().then(() => __importStar(require('stream')));
|
|
381
|
-
await (0, promises_1.pipeline)(Readable.fromWeb(response.body), fs_extra_1.default.createWriteStream(destination));
|
|
503
|
+
await saveResponse(response, destination, controller);
|
|
382
504
|
}
|
|
383
505
|
function hasBundleLocation(record) {
|
|
384
506
|
return (record.bundleOffset != null &&
|
|
@@ -387,43 +509,69 @@ function hasBundleLocation(record) {
|
|
|
387
509
|
(record.bundleCompression === zip_range_1.ZIP_STORED ||
|
|
388
510
|
record.bundleCompression === zip_range_1.ZIP_DEFLATED));
|
|
389
511
|
}
|
|
390
|
-
|
|
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()) {
|
|
391
518
|
if (!response.body)
|
|
392
519
|
throw new Error('empty response body');
|
|
393
520
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(destination));
|
|
394
|
-
const
|
|
395
|
-
|
|
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
|
+
}
|
|
396
536
|
}
|
|
397
537
|
/**
|
|
398
538
|
* Obtain the base bundle with as little traffic as possible, in order:
|
|
399
539
|
* 1. one Range request for the bundle's compressed bytes when the server
|
|
400
|
-
* knows their location (ppk published by a CLI that
|
|
540
|
+
* knows their location (ppk / apk / ipa published by a CLI that
|
|
541
|
+
* reported it);
|
|
401
542
|
* 2. the archive's central directory over Range, then just the bundle
|
|
402
543
|
* entry (any zip: ppk, apk, ipa — harmony .app nests a second zip and
|
|
403
544
|
* is skipped);
|
|
404
545
|
* 3. the whole archive, as before.
|
|
405
546
|
* A server that ignores Range (HTTP 200) streams the full archive into
|
|
406
|
-
* `archive` without a second request.
|
|
407
|
-
* `record.bundleHash
|
|
408
|
-
*
|
|
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.
|
|
409
552
|
*/
|
|
410
553
|
async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
411
554
|
const matches = bundleEntryMatcher(artifactType);
|
|
412
555
|
const verified = (bundle) => {
|
|
413
556
|
if (!bundle)
|
|
414
|
-
throw new
|
|
415
|
-
|
|
416
|
-
|
|
557
|
+
throw new PermanentBaseError('bundle entry not found');
|
|
558
|
+
const bundleHash = sha256Hex(bundle);
|
|
559
|
+
if (record.bundleHash && bundleHash !== record.bundleHash) {
|
|
560
|
+
throw new BundleHashMismatchError(bundleHash, record.bundleHash);
|
|
417
561
|
}
|
|
418
|
-
return bundle;
|
|
562
|
+
return { bundle, bundleHash };
|
|
419
563
|
};
|
|
420
564
|
const fromFullResponse = async (response) => {
|
|
421
565
|
await saveResponse(response, archive);
|
|
422
|
-
|
|
423
|
-
|
|
566
|
+
return {
|
|
567
|
+
...verified(await extractBundleFromArchive(archive)),
|
|
568
|
+
transport: 'full',
|
|
569
|
+
};
|
|
424
570
|
};
|
|
425
571
|
const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
|
|
426
|
-
|
|
572
|
+
// harmony .app nests the bundle in a second zip, so a location inside the
|
|
573
|
+
// outer archive is never reported for it
|
|
574
|
+
if (artifactType !== 'app' && hasBundleLocation(record)) {
|
|
427
575
|
try {
|
|
428
576
|
const { data, fetchedBytes, totalBytes } = await (0, zip_range_1.fetchZipEntryData)(record.url, {
|
|
429
577
|
dataOffset: record.bundleOffset,
|
|
@@ -431,7 +579,7 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
431
579
|
compressionMethod: record.bundleCompression,
|
|
432
580
|
});
|
|
433
581
|
return {
|
|
434
|
-
|
|
582
|
+
...verified(data),
|
|
435
583
|
transport: 'range-entry',
|
|
436
584
|
fetchedBytes,
|
|
437
585
|
totalBytes,
|
|
@@ -452,9 +600,9 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
452
600
|
skip('server ignores Range');
|
|
453
601
|
return fromFullResponse(remote.response);
|
|
454
602
|
}
|
|
455
|
-
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches);
|
|
603
|
+
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches, remote.reader);
|
|
456
604
|
return {
|
|
457
|
-
|
|
605
|
+
...verified(bundle),
|
|
458
606
|
transport: 'range-zip',
|
|
459
607
|
fetchedBytes: remote.reader.fetchedBytes,
|
|
460
608
|
totalBytes: remote.reader.totalSize,
|
|
@@ -465,12 +613,17 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
465
613
|
skip('server ignores Range');
|
|
466
614
|
return fromFullResponse(error.response);
|
|
467
615
|
}
|
|
616
|
+
// the real entry was read and is not the recorded one: final
|
|
617
|
+
if (error instanceof PermanentBaseError)
|
|
618
|
+
throw error;
|
|
468
619
|
skip(`zip range: ${error?.message ?? error}`);
|
|
469
620
|
}
|
|
470
621
|
}
|
|
471
622
|
await downloadToFile(record.url, archive);
|
|
472
|
-
|
|
473
|
-
|
|
623
|
+
return {
|
|
624
|
+
...verified(await extractBundleFromArchive(archive)),
|
|
625
|
+
transport: 'full',
|
|
626
|
+
};
|
|
474
627
|
}
|
|
475
628
|
/**
|
|
476
629
|
* Pick and materialize the base bundle for this compile. Returns null (with
|
|
@@ -516,7 +669,7 @@ async function resolveHermesBase(params) {
|
|
|
516
669
|
}
|
|
517
670
|
let record = null;
|
|
518
671
|
try {
|
|
519
|
-
record = await params.fetchBase(params.appId, bytecodeVersion);
|
|
672
|
+
record = await retryOnce(() => params.fetchBase(params.appId, bytecodeVersion));
|
|
520
673
|
}
|
|
521
674
|
catch (error) {
|
|
522
675
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
@@ -543,6 +696,17 @@ async function resolveHermesBase(params) {
|
|
|
543
696
|
// 1. cache by bundleHash
|
|
544
697
|
if (record.bundleHash) {
|
|
545
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
|
+
}
|
|
546
710
|
if (hit) {
|
|
547
711
|
log((0, i18n_1.t)('hermesBaseUsing', {
|
|
548
712
|
source: `cache ${record.bundleHash.slice(0, 12)}${record.versionId == null ? '' : ` (version ${record.versionId})`}`,
|
|
@@ -558,7 +722,7 @@ async function resolveHermesBase(params) {
|
|
|
558
722
|
};
|
|
559
723
|
}
|
|
560
724
|
}
|
|
561
|
-
// 2. download, extract, verify, cache —
|
|
725
|
+
// 2. download, extract, verify, cache — transport errors get a second try
|
|
562
726
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
563
727
|
const dir = tmpDir();
|
|
564
728
|
await fs_extra_1.default.ensureDir(dir);
|
|
@@ -574,19 +738,13 @@ async function resolveHermesBase(params) {
|
|
|
574
738
|
try {
|
|
575
739
|
log((0, i18n_1.t)('hermesBaseDownloading', { url: record.url }));
|
|
576
740
|
const fetched = await fetchBaseBundle(record, artifactType, archive, log);
|
|
577
|
-
|
|
578
|
-
throw new Error('bundle entry not found in downloaded package');
|
|
579
|
-
const { bundle } = fetched;
|
|
741
|
+
const { bundle, bundleHash: actualHash } = fetched;
|
|
580
742
|
if (fetched.transport !== 'full') {
|
|
581
743
|
log((0, i18n_1.t)('hermesBaseRangeFetched', {
|
|
582
744
|
fetchedKb: Math.ceil((fetched.fetchedBytes ?? 0) / 1024),
|
|
583
745
|
totalKb: Math.ceil((fetched.totalBytes ?? 0) / 1024),
|
|
584
746
|
}));
|
|
585
747
|
}
|
|
586
|
-
const actualHash = sha256Hex(bundle);
|
|
587
|
-
if (record.bundleHash && actualHash !== record.bundleHash) {
|
|
588
|
-
throw new Error(`bundleHash mismatch (${actualHash.slice(0, 12)} != ${record.bundleHash.slice(0, 12)})`);
|
|
589
|
-
}
|
|
590
748
|
const version = (0, hbcTransform_1.getHbcVersion)(bundle);
|
|
591
749
|
if (version !== bytecodeVersion) {
|
|
592
750
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
@@ -594,7 +752,7 @@ async function resolveHermesBase(params) {
|
|
|
594
752
|
}));
|
|
595
753
|
return null;
|
|
596
754
|
}
|
|
597
|
-
const cached = await cachePut(bundle, params.cacheMaxMb);
|
|
755
|
+
const cached = await cachePut(bundle, params.cacheMaxMb, actualHash);
|
|
598
756
|
log((0, i18n_1.t)('hermesBaseUsing', {
|
|
599
757
|
source: record.versionId == null
|
|
600
758
|
? `native package ${record.hash.slice(0, 8)}`
|
|
@@ -611,7 +769,7 @@ async function resolveHermesBase(params) {
|
|
|
611
769
|
};
|
|
612
770
|
}
|
|
613
771
|
catch (error) {
|
|
614
|
-
if (attempt === 2) {
|
|
772
|
+
if (attempt === 2 || error instanceof PermanentBaseError) {
|
|
615
773
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
616
774
|
reason: `download/verify failed: ${error?.message ?? error}`,
|
|
617
775
|
}));
|
|
@@ -624,6 +782,16 @@ async function resolveHermesBase(params) {
|
|
|
624
782
|
}
|
|
625
783
|
return null;
|
|
626
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
|
+
}
|
|
627
795
|
function hermescArgsWithBase(baseArgs, basePath) {
|
|
628
796
|
return basePath ? [...baseArgs, `-base-bytecode=${basePath}`] : baseArgs;
|
|
629
797
|
}
|
|
@@ -645,44 +813,84 @@ const STRING_TABLE_LINE = /^\s*[is](\d+)\[[^\]]*\](?: #[0-9A-F]+)?: (.*)$/;
|
|
|
645
813
|
* distances follow instruction widths. Everything else must match exactly.
|
|
646
814
|
*/
|
|
647
815
|
function normalizeDisassemblyLine(line, strings) {
|
|
648
|
-
|
|
816
|
+
// Cheap dispatch on the opcode before touching any regex: dumps run to
|
|
817
|
+
// millions of lines and only a handful of instructions need rewriting.
|
|
818
|
+
let indent = 0;
|
|
819
|
+
while (indent < line.length && isSpace(line.charCodeAt(indent)))
|
|
820
|
+
indent++;
|
|
821
|
+
let opEnd = indent;
|
|
822
|
+
while (opEnd < line.length && isLetter(line.charCodeAt(opEnd)))
|
|
823
|
+
opEnd++;
|
|
824
|
+
const opcode = line.slice(indent, opEnd);
|
|
825
|
+
if (opcode === 'Offset' && line.startsWith('Offset in debug table', indent)) {
|
|
649
826
|
return null;
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
827
|
+
}
|
|
828
|
+
let m;
|
|
829
|
+
if (opcode.startsWith('New') && opcode.includes('WithBuffer')) {
|
|
830
|
+
m =
|
|
831
|
+
/^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(?:AndParent)?\s+(r\d+)(.*)$/.exec(line);
|
|
832
|
+
if (m) {
|
|
833
|
+
const nums = m[3].match(/\d+/g) ?? [];
|
|
834
|
+
return `${m[1]} ${m[2]} sizes=${nums.slice(0, 1).join(',')}`;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (opcode.charCodeAt(0) === 0x4a /* J */) {
|
|
838
|
+
m = /^(\s*J[A-Za-z]+?)(Long)?\s+(L\d+|\d+)(.*)$/.exec(line);
|
|
839
|
+
if (m)
|
|
840
|
+
return `${m[1]} <tgt>${m[4]}`;
|
|
841
|
+
}
|
|
842
|
+
if (opcode.startsWith('DefineOwnById')) {
|
|
843
|
+
m = /^(\s*DefineOwnById\w*\s+r\d+, r\d+, \d+, )(\d+)$/.exec(line);
|
|
844
|
+
if (m)
|
|
845
|
+
line = `${m[1]}"${strings.get(Number(m[2])) ?? `?${m[2]}`}"`;
|
|
846
|
+
}
|
|
661
847
|
// Operand-width variants of one instruction (GetByIdShort/GetById/GetByIdLong,
|
|
662
848
|
// LoadConstString/LoadConstStringLongIndex, ...) only differ by how wide a
|
|
663
849
|
// string/function id or offset is encoded — a foreign base hands the new
|
|
664
850
|
// code's hot strings large ids, so the delta build legitimately picks the
|
|
665
851
|
// wider form. Fold the suffix and the column padding that follows it.
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
852
|
+
if (opEnd > indent &&
|
|
853
|
+
(opEnd === line.length || isSpace(line.charCodeAt(opEnd)))) {
|
|
854
|
+
const folded = foldWidthSuffix(opcode);
|
|
855
|
+
line = `${line.slice(0, indent)}${folded}${line.slice(opEnd).replace(/\s+/g, ' ')}`;
|
|
856
|
+
// Switch jump tables sit after the instructions; their relative offset (and
|
|
857
|
+
// the table header hermesc prints for them) moves with instruction widths.
|
|
858
|
+
// The two switch instructions carry that offset in different operands:
|
|
859
|
+
// StringSwitchImm rX, <id>, <jtOffset>, <defaultLabel>, <count>
|
|
860
|
+
// UIntSwitchImm rX, <jtOffset>, <defaultLabel>, <min>, <max>
|
|
861
|
+
// Folding only the first shape let a shifted UIntSwitchImm offset read as a
|
|
862
|
+
// real difference and drop an otherwise good delta build.
|
|
863
|
+
if (folded === 'StringSwitchImm') {
|
|
864
|
+
m = /^(\s*StringSwitchImm r\d+, \d+, )\d+(, L\d+, \d+)$/.exec(line);
|
|
865
|
+
if (m)
|
|
866
|
+
line = `${m[1]}<jt>${m[2]}`;
|
|
867
|
+
}
|
|
868
|
+
else if (folded === 'UIntSwitchImm') {
|
|
869
|
+
m = /^(\s*UIntSwitchImm r\d+, )\d+(, L\d+, \d+, \d+)$/.exec(line);
|
|
870
|
+
if (m)
|
|
871
|
+
line = `${m[1]}<jt>${m[2]}`;
|
|
872
|
+
}
|
|
873
|
+
else if (folded === 'offset' && /^\s*offset \d+$/.test(line)) {
|
|
874
|
+
line = line.replace(/\d+$/, '<jt>');
|
|
875
|
+
}
|
|
876
|
+
}
|
|
684
877
|
return line;
|
|
685
878
|
}
|
|
879
|
+
function isSpace(code) {
|
|
880
|
+
return code === 0x20 || code === 0x09 || code === 0x0d;
|
|
881
|
+
}
|
|
882
|
+
function isLetter(code) {
|
|
883
|
+
return (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
|
|
884
|
+
}
|
|
885
|
+
/** strip one operand-width suffix (LongIndex, Long, Short) off an opcode */
|
|
886
|
+
function foldWidthSuffix(opcode) {
|
|
887
|
+
for (const suffix of ['LongIndex', 'Long', 'Short']) {
|
|
888
|
+
if (opcode.length > suffix.length && opcode.endsWith(suffix)) {
|
|
889
|
+
return opcode.slice(0, -suffix.length);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return opcode;
|
|
893
|
+
}
|
|
686
894
|
/** Split a readable stream into lines without readline (Bun's readline async iterator misbehaves when pulled manually). */
|
|
687
895
|
async function* streamLines(stream) {
|
|
688
896
|
let rest = '';
|
|
@@ -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 };
|