react-native-update-cli 2.22.6 → 2.22.7
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/lib/bundle-runner.d.ts +26 -0
- package/lib/bundle-runner.js +188 -89
- package/lib/package.js +9 -0
- package/lib/utils/hermes-base.d.ts +10 -3
- package/lib/utils/hermes-base.js +144 -45
- package/lib/utils/zip-range.d.ts +45 -6
- package/lib/utils/zip-range.js +220 -29
- package/lib/versions.js +11 -14
- package/package.json +1 -1
- package/src/bundle-runner.ts +252 -116
- package/src/package.ts +16 -1
- package/src/utils/hermes-base.ts +161 -42
- package/src/utils/zip-range.ts +252 -39
- package/src/versions.ts +17 -19
package/lib/utils/hermes-base.js
CHANGED
|
@@ -166,8 +166,60 @@ function classifyHermesCommand(hermesCommand) {
|
|
|
166
166
|
function sha256Hex(data) {
|
|
167
167
|
return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
const PROBE_CACHE_FILE = 'hbc-versions.json';
|
|
170
|
+
const PROBE_CACHE_ENTRIES = 16;
|
|
171
|
+
/** identity of a hermesc binary for the probe cache: path + size + mtime */
|
|
172
|
+
function probeCacheKey(hermesCommand) {
|
|
173
|
+
try {
|
|
174
|
+
const stat = fs_extra_1.default.statSync(hermesCommand);
|
|
175
|
+
return `${path_1.default.resolve(hermesCommand)}|${stat.size}|${Math.floor(stat.mtimeMs)}`;
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function readProbeCache() {
|
|
182
|
+
try {
|
|
183
|
+
const parsed = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), 'utf8'));
|
|
184
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function writeProbeCache(entries) {
|
|
191
|
+
try {
|
|
192
|
+
const keys = Object.keys(entries);
|
|
193
|
+
// keep the most recently inserted entries only
|
|
194
|
+
const trimmed = Object.fromEntries(keys.slice(-PROBE_CACHE_ENTRIES).map((key) => [key, entries[key]]));
|
|
195
|
+
fs_extra_1.default.ensureDirSync(cacheDir());
|
|
196
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), JSON.stringify(trimmed));
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// the cache is a convenience; probing again next time is fine
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Which HBC version this hermesc emits. The answer is remembered per binary
|
|
204
|
+
* (path, size, mtime) in the cache dir so only the first run of a given
|
|
205
|
+
* hermesc pays for the empty-file compile.
|
|
206
|
+
*/
|
|
170
207
|
function probeHbcVersion(hermesCommand) {
|
|
208
|
+
const key = probeCacheKey(hermesCommand);
|
|
209
|
+
if (key) {
|
|
210
|
+
const cached = readProbeCache()[key];
|
|
211
|
+
if (Number.isInteger(cached) && cached > 0)
|
|
212
|
+
return cached;
|
|
213
|
+
}
|
|
214
|
+
const version = compileProbe(hermesCommand);
|
|
215
|
+
if (key && version !== null) {
|
|
216
|
+
const { [key]: _stale, ...others } = readProbeCache();
|
|
217
|
+
writeProbeCache({ ...others, [key]: version });
|
|
218
|
+
}
|
|
219
|
+
return version;
|
|
220
|
+
}
|
|
221
|
+
/** Compile an empty file to learn which HBC version this hermesc emits. */
|
|
222
|
+
function compileProbe(hermesCommand) {
|
|
171
223
|
const dir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-hermes-probe-'));
|
|
172
224
|
try {
|
|
173
225
|
const input = path_1.default.join(dir, 'probe.js');
|
|
@@ -288,8 +340,8 @@ async function cacheLookup(bundleHash) {
|
|
|
288
340
|
return file;
|
|
289
341
|
}
|
|
290
342
|
/** Store a bundle under its sha256 (LRU-evicting to the configured limits). */
|
|
291
|
-
async function cachePut(bundle, maxMb) {
|
|
292
|
-
const bundleHash = sha256Hex(bundle);
|
|
343
|
+
async function cachePut(bundle, maxMb, knownHash) {
|
|
344
|
+
const bundleHash = knownHash ?? sha256Hex(bundle);
|
|
293
345
|
const dir = cacheDir();
|
|
294
346
|
await fs_extra_1.default.ensureDir(dir);
|
|
295
347
|
const file = path_1.default.join(dir, bundleHash);
|
|
@@ -397,7 +449,8 @@ async function saveResponse(response, destination) {
|
|
|
397
449
|
/**
|
|
398
450
|
* Obtain the base bundle with as little traffic as possible, in order:
|
|
399
451
|
* 1. one Range request for the bundle's compressed bytes when the server
|
|
400
|
-
* knows their location (ppk published by a CLI that
|
|
452
|
+
* knows their location (ppk / apk / ipa published by a CLI that
|
|
453
|
+
* reported it);
|
|
401
454
|
* 2. the archive's central directory over Range, then just the bundle
|
|
402
455
|
* entry (any zip: ppk, apk, ipa — harmony .app nests a second zip and
|
|
403
456
|
* is skipped);
|
|
@@ -412,18 +465,23 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
412
465
|
const verified = (bundle) => {
|
|
413
466
|
if (!bundle)
|
|
414
467
|
throw new Error('bundle entry not found');
|
|
415
|
-
|
|
468
|
+
const bundleHash = sha256Hex(bundle);
|
|
469
|
+
if (record.bundleHash && bundleHash !== record.bundleHash) {
|
|
416
470
|
throw new Error('bundleHash mismatch');
|
|
417
471
|
}
|
|
418
|
-
return bundle;
|
|
472
|
+
return { bundle, bundleHash };
|
|
419
473
|
};
|
|
420
474
|
const fromFullResponse = async (response) => {
|
|
421
475
|
await saveResponse(response, archive);
|
|
422
476
|
const bundle = await extractBundleFromArchive(archive);
|
|
423
|
-
return bundle
|
|
477
|
+
return bundle
|
|
478
|
+
? { bundle, bundleHash: sha256Hex(bundle), transport: 'full' }
|
|
479
|
+
: null;
|
|
424
480
|
};
|
|
425
481
|
const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
|
|
426
|
-
|
|
482
|
+
// harmony .app nests the bundle in a second zip, so a location inside the
|
|
483
|
+
// outer archive is never reported for it
|
|
484
|
+
if (artifactType !== 'app' && hasBundleLocation(record)) {
|
|
427
485
|
try {
|
|
428
486
|
const { data, fetchedBytes, totalBytes } = await (0, zip_range_1.fetchZipEntryData)(record.url, {
|
|
429
487
|
dataOffset: record.bundleOffset,
|
|
@@ -431,7 +489,7 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
431
489
|
compressionMethod: record.bundleCompression,
|
|
432
490
|
});
|
|
433
491
|
return {
|
|
434
|
-
|
|
492
|
+
...verified(data),
|
|
435
493
|
transport: 'range-entry',
|
|
436
494
|
fetchedBytes,
|
|
437
495
|
totalBytes,
|
|
@@ -452,9 +510,9 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
452
510
|
skip('server ignores Range');
|
|
453
511
|
return fromFullResponse(remote.response);
|
|
454
512
|
}
|
|
455
|
-
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches);
|
|
513
|
+
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches, remote.reader);
|
|
456
514
|
return {
|
|
457
|
-
|
|
515
|
+
...verified(bundle),
|
|
458
516
|
transport: 'range-zip',
|
|
459
517
|
fetchedBytes: remote.reader.fetchedBytes,
|
|
460
518
|
totalBytes: remote.reader.totalSize,
|
|
@@ -470,7 +528,9 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
470
528
|
}
|
|
471
529
|
await downloadToFile(record.url, archive);
|
|
472
530
|
const bundle = await extractBundleFromArchive(archive);
|
|
473
|
-
return bundle
|
|
531
|
+
return bundle
|
|
532
|
+
? { bundle, bundleHash: sha256Hex(bundle), transport: 'full' }
|
|
533
|
+
: null;
|
|
474
534
|
}
|
|
475
535
|
/**
|
|
476
536
|
* Pick and materialize the base bundle for this compile. Returns null (with
|
|
@@ -576,14 +636,13 @@ async function resolveHermesBase(params) {
|
|
|
576
636
|
const fetched = await fetchBaseBundle(record, artifactType, archive, log);
|
|
577
637
|
if (!fetched)
|
|
578
638
|
throw new Error('bundle entry not found in downloaded package');
|
|
579
|
-
const { bundle } = fetched;
|
|
639
|
+
const { bundle, bundleHash: actualHash } = fetched;
|
|
580
640
|
if (fetched.transport !== 'full') {
|
|
581
641
|
log((0, i18n_1.t)('hermesBaseRangeFetched', {
|
|
582
642
|
fetchedKb: Math.ceil((fetched.fetchedBytes ?? 0) / 1024),
|
|
583
643
|
totalKb: Math.ceil((fetched.totalBytes ?? 0) / 1024),
|
|
584
644
|
}));
|
|
585
645
|
}
|
|
586
|
-
const actualHash = sha256Hex(bundle);
|
|
587
646
|
if (record.bundleHash && actualHash !== record.bundleHash) {
|
|
588
647
|
throw new Error(`bundleHash mismatch (${actualHash.slice(0, 12)} != ${record.bundleHash.slice(0, 12)})`);
|
|
589
648
|
}
|
|
@@ -594,7 +653,7 @@ async function resolveHermesBase(params) {
|
|
|
594
653
|
}));
|
|
595
654
|
return null;
|
|
596
655
|
}
|
|
597
|
-
const cached = await cachePut(bundle, params.cacheMaxMb);
|
|
656
|
+
const cached = await cachePut(bundle, params.cacheMaxMb, actualHash);
|
|
598
657
|
log((0, i18n_1.t)('hermesBaseUsing', {
|
|
599
658
|
source: record.versionId == null
|
|
600
659
|
? `native package ${record.hash.slice(0, 8)}`
|
|
@@ -645,44 +704,84 @@ const STRING_TABLE_LINE = /^\s*[is](\d+)\[[^\]]*\](?: #[0-9A-F]+)?: (.*)$/;
|
|
|
645
704
|
* distances follow instruction widths. Everything else must match exactly.
|
|
646
705
|
*/
|
|
647
706
|
function normalizeDisassemblyLine(line, strings) {
|
|
648
|
-
|
|
707
|
+
// Cheap dispatch on the opcode before touching any regex: dumps run to
|
|
708
|
+
// millions of lines and only a handful of instructions need rewriting.
|
|
709
|
+
let indent = 0;
|
|
710
|
+
while (indent < line.length && isSpace(line.charCodeAt(indent)))
|
|
711
|
+
indent++;
|
|
712
|
+
let opEnd = indent;
|
|
713
|
+
while (opEnd < line.length && isLetter(line.charCodeAt(opEnd)))
|
|
714
|
+
opEnd++;
|
|
715
|
+
const opcode = line.slice(indent, opEnd);
|
|
716
|
+
if (opcode === 'Offset' && line.startsWith('Offset in debug table', indent)) {
|
|
649
717
|
return null;
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
718
|
+
}
|
|
719
|
+
let m;
|
|
720
|
+
if (opcode.startsWith('New') && opcode.includes('WithBuffer')) {
|
|
721
|
+
m =
|
|
722
|
+
/^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(?:AndParent)?\s+(r\d+)(.*)$/.exec(line);
|
|
723
|
+
if (m) {
|
|
724
|
+
const nums = m[3].match(/\d+/g) ?? [];
|
|
725
|
+
return `${m[1]} ${m[2]} sizes=${nums.slice(0, 1).join(',')}`;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (opcode.charCodeAt(0) === 0x4a /* J */) {
|
|
729
|
+
m = /^(\s*J[A-Za-z]+?)(Long)?\s+(L\d+|\d+)(.*)$/.exec(line);
|
|
730
|
+
if (m)
|
|
731
|
+
return `${m[1]} <tgt>${m[4]}`;
|
|
732
|
+
}
|
|
733
|
+
if (opcode.startsWith('DefineOwnById')) {
|
|
734
|
+
m = /^(\s*DefineOwnById\w*\s+r\d+, r\d+, \d+, )(\d+)$/.exec(line);
|
|
735
|
+
if (m)
|
|
736
|
+
line = `${m[1]}"${strings.get(Number(m[2])) ?? `?${m[2]}`}"`;
|
|
737
|
+
}
|
|
661
738
|
// Operand-width variants of one instruction (GetByIdShort/GetById/GetByIdLong,
|
|
662
739
|
// LoadConstString/LoadConstStringLongIndex, ...) only differ by how wide a
|
|
663
740
|
// string/function id or offset is encoded — a foreign base hands the new
|
|
664
741
|
// code's hot strings large ids, so the delta build legitimately picks the
|
|
665
742
|
// 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
|
-
|
|
743
|
+
if (opEnd > indent &&
|
|
744
|
+
(opEnd === line.length || isSpace(line.charCodeAt(opEnd)))) {
|
|
745
|
+
const folded = foldWidthSuffix(opcode);
|
|
746
|
+
line = `${line.slice(0, indent)}${folded}${line.slice(opEnd).replace(/\s+/g, ' ')}`;
|
|
747
|
+
// Switch jump tables sit after the instructions; their relative offset (and
|
|
748
|
+
// the table header hermesc prints for them) moves with instruction widths.
|
|
749
|
+
// The two switch instructions carry that offset in different operands:
|
|
750
|
+
// StringSwitchImm rX, <id>, <jtOffset>, <defaultLabel>, <count>
|
|
751
|
+
// UIntSwitchImm rX, <jtOffset>, <defaultLabel>, <min>, <max>
|
|
752
|
+
// Folding only the first shape let a shifted UIntSwitchImm offset read as a
|
|
753
|
+
// real difference and drop an otherwise good delta build.
|
|
754
|
+
if (folded === 'StringSwitchImm') {
|
|
755
|
+
m = /^(\s*StringSwitchImm r\d+, \d+, )\d+(, L\d+, \d+)$/.exec(line);
|
|
756
|
+
if (m)
|
|
757
|
+
line = `${m[1]}<jt>${m[2]}`;
|
|
758
|
+
}
|
|
759
|
+
else if (folded === 'UIntSwitchImm') {
|
|
760
|
+
m = /^(\s*UIntSwitchImm r\d+, )\d+(, L\d+, \d+, \d+)$/.exec(line);
|
|
761
|
+
if (m)
|
|
762
|
+
line = `${m[1]}<jt>${m[2]}`;
|
|
763
|
+
}
|
|
764
|
+
else if (folded === 'offset' && /^\s*offset \d+$/.test(line)) {
|
|
765
|
+
line = line.replace(/\d+$/, '<jt>');
|
|
766
|
+
}
|
|
767
|
+
}
|
|
684
768
|
return line;
|
|
685
769
|
}
|
|
770
|
+
function isSpace(code) {
|
|
771
|
+
return code === 0x20 || code === 0x09 || code === 0x0d;
|
|
772
|
+
}
|
|
773
|
+
function isLetter(code) {
|
|
774
|
+
return (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
|
|
775
|
+
}
|
|
776
|
+
/** strip one operand-width suffix (LongIndex, Long, Short) off an opcode */
|
|
777
|
+
function foldWidthSuffix(opcode) {
|
|
778
|
+
for (const suffix of ['LongIndex', 'Long', 'Short']) {
|
|
779
|
+
if (opcode.length > suffix.length && opcode.endsWith(suffix)) {
|
|
780
|
+
return opcode.slice(0, -suffix.length);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return opcode;
|
|
784
|
+
}
|
|
686
785
|
/** Split a readable stream into lines without readline (Bun's readline async iterator misbehaves when pulled manually). */
|
|
687
786
|
async function* streamLines(stream) {
|
|
688
787
|
let rest = '';
|
package/lib/utils/zip-range.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
-
import { RandomAccessReader, type ZipFile } from 'yauzl';
|
|
2
|
+
import { type Entry, RandomAccessReader, type ZipFile } from 'yauzl';
|
|
3
3
|
export declare const ZIP_STORED = 0;
|
|
4
4
|
export declare const ZIP_DEFLATED = 8;
|
|
5
5
|
export interface ZipEntryLocation {
|
|
@@ -13,6 +13,21 @@ export interface ZipEntryLocation {
|
|
|
13
13
|
}
|
|
14
14
|
/** Data location of the first entry matching `matches` in a local zip. */
|
|
15
15
|
export declare function locateZipEntry(zipPath: string, matches: (name: string) => boolean): Promise<ZipEntryLocation | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Content and data location of the first matching entry in one pass over the
|
|
18
|
+
* archive (publish needs both: the bundle to hash and cache, its location to
|
|
19
|
+
* report to the server).
|
|
20
|
+
*/
|
|
21
|
+
export declare function readZipEntryWithLocation(zipPath: string, matches: (name: string) => boolean): Promise<{
|
|
22
|
+
data: Buffer;
|
|
23
|
+
location: ZipEntryLocation;
|
|
24
|
+
} | null>;
|
|
25
|
+
/**
|
|
26
|
+
* The `bundleOffset` / `bundleCompressedSize` / `bundleCompression` fields for
|
|
27
|
+
* version/create and package/create, or nothing when the entry cannot be
|
|
28
|
+
* fetched by a single Range request (unknown, empty or exotic compression).
|
|
29
|
+
*/
|
|
30
|
+
export declare function bundleLocationFields(location: ZipEntryLocation | null | undefined): Record<string, number>;
|
|
16
31
|
/** The server answered a Range request with the whole body (HTTP 200). */
|
|
17
32
|
export declare class RangeUnsupportedError extends Error {
|
|
18
33
|
readonly response: Response;
|
|
@@ -35,23 +50,44 @@ export declare function fetchZipEntryData(url: string, location: Pick<ZipEntryLo
|
|
|
35
50
|
}>;
|
|
36
51
|
/**
|
|
37
52
|
* yauzl reader over HTTP Range. Header reads (EOCD, central directory, local
|
|
38
|
-
* file headers) are widened to CHUNK_BYTES and cached
|
|
39
|
-
*
|
|
53
|
+
* file headers) are widened to CHUNK_BYTES and cached — adjacent or
|
|
54
|
+
* overlapping chunks are merged so a read never re-fetches bytes it already
|
|
55
|
+
* has — and entry data reuses whatever prefix the cache holds (typically the
|
|
56
|
+
* bytes following the local file header) before requesting the rest.
|
|
40
57
|
*/
|
|
41
58
|
export declare class HttpRangeReader extends RandomAccessReader {
|
|
42
59
|
private readonly url;
|
|
43
60
|
readonly totalSize: number;
|
|
44
|
-
private
|
|
61
|
+
private chunks;
|
|
62
|
+
/** span a header read inside it should widen to (see `hintEntry`) */
|
|
63
|
+
private hint;
|
|
45
64
|
requests: number;
|
|
46
65
|
fetchedBytes: number;
|
|
47
66
|
constructor(url: string, totalSize: number, tail?: {
|
|
48
67
|
start: number;
|
|
49
68
|
data: Buffer;
|
|
50
69
|
});
|
|
70
|
+
/**
|
|
71
|
+
* The next entry to be read: yauzl first reads its local file header, and
|
|
72
|
+
* widening that read to the entry's data makes the data stream a cache hit
|
|
73
|
+
* — one request for header + bundle instead of two. The central directory
|
|
74
|
+
* may understate the local header's extra field, hence the slack.
|
|
75
|
+
*/
|
|
76
|
+
hintEntry(entry: Entry): void;
|
|
77
|
+
/** Cache `data` at `start`, merging with any chunk it touches. */
|
|
78
|
+
addChunk(start: number, data: Buffer): void;
|
|
79
|
+
/** cached bytes starting exactly at `start`, up to `end` (may be shorter) */
|
|
80
|
+
private cachedPrefix;
|
|
51
81
|
private cached;
|
|
82
|
+
/** start of the cached chunk holding byte `end - 1`, when there is one */
|
|
83
|
+
private cachedSuffixStart;
|
|
52
84
|
_readStreamForRange(start: number, end: number): Readable;
|
|
53
85
|
read(buffer: Buffer, offset: number, length: number, position: number, callback: (err: Error | null, bytesRead?: number) => void): void;
|
|
54
86
|
}
|
|
87
|
+
export declare function parseEndOfCentralDirectory(tail: Buffer): {
|
|
88
|
+
cdOffset: number;
|
|
89
|
+
cdSize: number;
|
|
90
|
+
} | null;
|
|
55
91
|
export type RemoteZip = {
|
|
56
92
|
kind: 'zip';
|
|
57
93
|
zipFile: ZipFile;
|
|
@@ -67,6 +103,9 @@ export type RemoteZip = {
|
|
|
67
103
|
* typical archives) and letting yauzl read the rest on demand.
|
|
68
104
|
*/
|
|
69
105
|
export declare function openRemoteZip(url: string): Promise<RemoteZip>;
|
|
70
|
-
/**
|
|
71
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Read the first matching entry of an opened remote zip, then close it. With
|
|
108
|
+
* `reader` given, the entry's header and data are fetched in one request.
|
|
109
|
+
*/
|
|
110
|
+
export declare function readRemoteZipEntry(zipFile: ZipFile, matches: (name: string) => boolean, reader?: HttpRangeReader): Promise<Buffer | null>;
|
|
72
111
|
export {};
|