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/zip-range.js
CHANGED
|
@@ -5,8 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HttpRangeReader = exports.RangeUnsupportedError = exports.ZIP_DEFLATED = exports.ZIP_STORED = void 0;
|
|
7
7
|
exports.locateZipEntry = locateZipEntry;
|
|
8
|
+
exports.readZipEntryWithLocation = readZipEntryWithLocation;
|
|
9
|
+
exports.bundleLocationFields = bundleLocationFields;
|
|
8
10
|
exports.parseContentRange = parseContentRange;
|
|
9
11
|
exports.fetchZipEntryData = fetchZipEntryData;
|
|
12
|
+
exports.parseEndOfCentralDirectory = parseEndOfCentralDirectory;
|
|
10
13
|
exports.openRemoteZip = openRemoteZip;
|
|
11
14
|
exports.readRemoteZipEntry = readRemoteZipEntry;
|
|
12
15
|
// Byte-range access to zip archives.
|
|
@@ -26,15 +29,42 @@ exports.ZIP_STORED = 0;
|
|
|
26
29
|
exports.ZIP_DEFLATED = 8;
|
|
27
30
|
const LOCAL_HEADER_SIGNATURE = 0x04034b50;
|
|
28
31
|
const LOCAL_HEADER_SIZE = 30;
|
|
29
|
-
/**
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Exactly what yauzl reads to find the EOCD (22 + 65535 comment + 20 zip64
|
|
34
|
+
* locator), so its first read is a cache hit; small archives fit entirely.
|
|
35
|
+
*/
|
|
36
|
+
const TAIL_BYTES = 22 + 0xffff + 20;
|
|
31
37
|
/** minimum span fetched for header reads, so header + directory share a request */
|
|
32
38
|
const CHUNK_BYTES = 64 * 1024;
|
|
39
|
+
/** extra bytes past a hinted entry, covering a longer local extra field */
|
|
40
|
+
const HINT_SLACK_BYTES = 4 * 1024;
|
|
33
41
|
/** Data location of the first entry matching `matches` in a local zip. */
|
|
34
42
|
async function locateZipEntry(zipPath, matches) {
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
43
|
+
const found = await openFirstEntry(zipPath, matches);
|
|
44
|
+
if (!found)
|
|
37
45
|
return null;
|
|
46
|
+
found.zipFile.close();
|
|
47
|
+
return locationOfEntry(zipPath, found.entry);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Content and data location of the first matching entry in one pass over the
|
|
51
|
+
* archive (publish needs both: the bundle to hash and cache, its location to
|
|
52
|
+
* report to the server).
|
|
53
|
+
*/
|
|
54
|
+
async function readZipEntryWithLocation(zipPath, matches) {
|
|
55
|
+
const found = await openFirstEntry(zipPath, matches);
|
|
56
|
+
if (!found)
|
|
57
|
+
return null;
|
|
58
|
+
let data;
|
|
59
|
+
try {
|
|
60
|
+
data = await (0, zip_entries_1.readEntry)(found.entry, found.zipFile);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
found.zipFile.close();
|
|
64
|
+
}
|
|
65
|
+
return { data, location: await locationOfEntry(zipPath, found.entry) };
|
|
66
|
+
}
|
|
67
|
+
async function locationOfEntry(zipPath, entry) {
|
|
38
68
|
const header = Buffer.alloc(LOCAL_HEADER_SIZE);
|
|
39
69
|
const fd = await fs_extra_1.default.open(zipPath, 'r');
|
|
40
70
|
try {
|
|
@@ -62,19 +92,32 @@ async function locateZipEntry(zipPath, matches) {
|
|
|
62
92
|
compressionMethod: entry.compressionMethod,
|
|
63
93
|
};
|
|
64
94
|
}
|
|
65
|
-
|
|
95
|
+
/** Open a local zip and stop at the first matching entry (caller closes). */
|
|
96
|
+
function openFirstEntry(zipPath, matches) {
|
|
66
97
|
return new Promise((resolve, reject) => {
|
|
67
|
-
(0, yauzl_1.open)(zipPath, { lazyEntries: true }, (err, zipFile) => {
|
|
98
|
+
(0, yauzl_1.open)(zipPath, { lazyEntries: true, autoClose: false }, (err, zipFile) => {
|
|
68
99
|
if (err)
|
|
69
100
|
return reject(err);
|
|
70
|
-
let
|
|
71
|
-
zipFile.on('error',
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
101
|
+
let settled = false;
|
|
102
|
+
zipFile.on('error', (error) => {
|
|
103
|
+
if (!settled) {
|
|
104
|
+
settled = true;
|
|
105
|
+
reject(error);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
zipFile.on('end', () => {
|
|
109
|
+
if (!settled) {
|
|
110
|
+
settled = true;
|
|
76
111
|
zipFile.close();
|
|
77
|
-
resolve(
|
|
112
|
+
resolve(null);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
zipFile.on('entry', (entry) => {
|
|
116
|
+
if (settled)
|
|
117
|
+
return;
|
|
118
|
+
if (matches(entry.fileName)) {
|
|
119
|
+
settled = true;
|
|
120
|
+
resolve({ zipFile, entry });
|
|
78
121
|
return;
|
|
79
122
|
}
|
|
80
123
|
zipFile.readEntry();
|
|
@@ -83,6 +126,24 @@ function findEntry(zipPath, matches) {
|
|
|
83
126
|
});
|
|
84
127
|
});
|
|
85
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* The `bundleOffset` / `bundleCompressedSize` / `bundleCompression` fields for
|
|
131
|
+
* version/create and package/create, or nothing when the entry cannot be
|
|
132
|
+
* fetched by a single Range request (unknown, empty or exotic compression).
|
|
133
|
+
*/
|
|
134
|
+
function bundleLocationFields(location) {
|
|
135
|
+
if (!location ||
|
|
136
|
+
location.compressedSize <= 0 ||
|
|
137
|
+
(location.compressionMethod !== exports.ZIP_STORED &&
|
|
138
|
+
location.compressionMethod !== exports.ZIP_DEFLATED)) {
|
|
139
|
+
return {};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
bundleOffset: location.dataOffset,
|
|
143
|
+
bundleCompressedSize: location.compressedSize,
|
|
144
|
+
bundleCompression: location.compressionMethod,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
86
147
|
// ---------------------------------------------------------------------------
|
|
87
148
|
// HTTP Range
|
|
88
149
|
// ---------------------------------------------------------------------------
|
|
@@ -158,13 +219,17 @@ async function fetchZipEntryData(url, location) {
|
|
|
158
219
|
}
|
|
159
220
|
/**
|
|
160
221
|
* yauzl reader over HTTP Range. Header reads (EOCD, central directory, local
|
|
161
|
-
* file headers) are widened to CHUNK_BYTES and cached
|
|
162
|
-
*
|
|
222
|
+
* file headers) are widened to CHUNK_BYTES and cached — adjacent or
|
|
223
|
+
* overlapping chunks are merged so a read never re-fetches bytes it already
|
|
224
|
+
* has — and entry data reuses whatever prefix the cache holds (typically the
|
|
225
|
+
* bytes following the local file header) before requesting the rest.
|
|
163
226
|
*/
|
|
164
227
|
class HttpRangeReader extends yauzl_1.RandomAccessReader {
|
|
165
228
|
url;
|
|
166
229
|
totalSize;
|
|
167
230
|
chunks = [];
|
|
231
|
+
/** span a header read inside it should widen to (see `hintEntry`) */
|
|
232
|
+
hint = null;
|
|
168
233
|
requests = 0;
|
|
169
234
|
fetchedBytes = 0;
|
|
170
235
|
constructor(url, totalSize, tail) {
|
|
@@ -172,25 +237,92 @@ class HttpRangeReader extends yauzl_1.RandomAccessReader {
|
|
|
172
237
|
this.url = url;
|
|
173
238
|
this.totalSize = totalSize;
|
|
174
239
|
if (tail)
|
|
175
|
-
this.
|
|
240
|
+
this.addChunk(tail.start, tail.data);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The next entry to be read: yauzl first reads its local file header, and
|
|
244
|
+
* widening that read to the entry's data makes the data stream a cache hit
|
|
245
|
+
* — one request for header + bundle instead of two. The central directory
|
|
246
|
+
* may understate the local header's extra field, hence the slack.
|
|
247
|
+
*/
|
|
248
|
+
hintEntry(entry) {
|
|
249
|
+
const start = entry.relativeOffsetOfLocalHeader;
|
|
250
|
+
const end = start +
|
|
251
|
+
LOCAL_HEADER_SIZE +
|
|
252
|
+
entry.fileNameLength +
|
|
253
|
+
entry.extraFieldLength +
|
|
254
|
+
entry.compressedSize +
|
|
255
|
+
HINT_SLACK_BYTES;
|
|
256
|
+
this.hint = { start, end: Math.min(end, this.totalSize) };
|
|
257
|
+
}
|
|
258
|
+
/** Cache `data` at `start`, merging with any chunk it touches. */
|
|
259
|
+
addChunk(start, data) {
|
|
260
|
+
if (data.length === 0)
|
|
261
|
+
return;
|
|
262
|
+
let lo = start;
|
|
263
|
+
let hi = start + data.length;
|
|
264
|
+
const pieces = [{ start, data }];
|
|
265
|
+
const rest = [];
|
|
266
|
+
for (const chunk of this.chunks) {
|
|
267
|
+
const chunkEnd = chunk.start + chunk.data.length;
|
|
268
|
+
if (chunk.start <= hi && chunkEnd >= lo) {
|
|
269
|
+
pieces.push(chunk);
|
|
270
|
+
lo = Math.min(lo, chunk.start);
|
|
271
|
+
hi = Math.max(hi, chunkEnd);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
rest.push(chunk);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (pieces.length === 1) {
|
|
278
|
+
rest.push(pieces[0]);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
const merged = Buffer.alloc(hi - lo);
|
|
282
|
+
// the new data is written last so it wins over stale overlaps
|
|
283
|
+
for (const piece of pieces.reverse()) {
|
|
284
|
+
piece.data.copy(merged, piece.start - lo);
|
|
285
|
+
}
|
|
286
|
+
rest.push({ start: lo, data: merged });
|
|
287
|
+
}
|
|
288
|
+
rest.sort((a, b) => a.start - b.start);
|
|
289
|
+
this.chunks = rest;
|
|
290
|
+
}
|
|
291
|
+
/** cached bytes starting exactly at `start`, up to `end` (may be shorter) */
|
|
292
|
+
cachedPrefix(start, end) {
|
|
293
|
+
for (const chunk of this.chunks) {
|
|
294
|
+
const chunkEnd = chunk.start + chunk.data.length;
|
|
295
|
+
if (start >= chunk.start && start < chunkEnd) {
|
|
296
|
+
return chunk.data.subarray(start - chunk.start, Math.min(end, chunkEnd) - chunk.start);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
176
300
|
}
|
|
177
301
|
cached(start, end) {
|
|
302
|
+
const prefix = this.cachedPrefix(start, end);
|
|
303
|
+
return prefix && prefix.length === end - start ? prefix : null;
|
|
304
|
+
}
|
|
305
|
+
/** start of the cached chunk holding byte `end - 1`, when there is one */
|
|
306
|
+
cachedSuffixStart(end) {
|
|
178
307
|
for (const chunk of this.chunks) {
|
|
179
|
-
if (
|
|
180
|
-
return chunk.
|
|
308
|
+
if (end - 1 >= chunk.start && end - 1 < chunk.start + chunk.data.length) {
|
|
309
|
+
return chunk.start;
|
|
181
310
|
}
|
|
182
311
|
}
|
|
183
312
|
return null;
|
|
184
313
|
}
|
|
185
314
|
_readStreamForRange(start, end) {
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
188
|
-
return stream_1.Readable.from([
|
|
315
|
+
const prefix = this.cachedPrefix(start, end);
|
|
316
|
+
if (prefix && prefix.length === end - start)
|
|
317
|
+
return stream_1.Readable.from([prefix]);
|
|
189
318
|
const out = new stream_1.PassThrough();
|
|
319
|
+
if (prefix)
|
|
320
|
+
out.write(prefix);
|
|
321
|
+
const from = start + (prefix?.length ?? 0);
|
|
190
322
|
this.requests++;
|
|
191
|
-
fetchRange(this.url,
|
|
323
|
+
fetchRange(this.url, from, end)
|
|
192
324
|
.then((response) => {
|
|
193
|
-
this.fetchedBytes += end -
|
|
325
|
+
this.fetchedBytes += end - from;
|
|
194
326
|
const body = stream_1.Readable.fromWeb(response.body);
|
|
195
327
|
body.on('error', (error) => out.destroy(error));
|
|
196
328
|
body.pipe(out);
|
|
@@ -205,17 +337,60 @@ class HttpRangeReader extends yauzl_1.RandomAccessReader {
|
|
|
205
337
|
setImmediate(() => callback(null, length));
|
|
206
338
|
return;
|
|
207
339
|
}
|
|
208
|
-
|
|
340
|
+
// fetch only what the cache lacks: skip a cached prefix, stop at a cached
|
|
341
|
+
// suffix (yauzl's EOCD read may just exceed the tail), and otherwise widen
|
|
342
|
+
// so the next header read is free
|
|
343
|
+
const requestEnd = position + length;
|
|
344
|
+
const from = position + (this.cachedPrefix(position, requestEnd)?.length ?? 0);
|
|
345
|
+
const suffixStart = this.cachedSuffixStart(requestEnd);
|
|
346
|
+
let end;
|
|
347
|
+
if (suffixStart !== null && suffixStart > from) {
|
|
348
|
+
end = suffixStart;
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
end = Math.min(this.totalSize, Math.max(requestEnd, from + CHUNK_BYTES));
|
|
352
|
+
if (this.hint &&
|
|
353
|
+
position >= this.hint.start &&
|
|
354
|
+
position < this.hint.end) {
|
|
355
|
+
end = Math.max(end, this.hint.end);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
209
358
|
this.requests++;
|
|
210
|
-
fetchRangeBuffer(this.url,
|
|
359
|
+
fetchRangeBuffer(this.url, from, end).then(({ data }) => {
|
|
211
360
|
this.fetchedBytes += data.length;
|
|
212
|
-
this.
|
|
213
|
-
|
|
361
|
+
this.addChunk(from, data);
|
|
362
|
+
const full = this.cached(position, position + length);
|
|
363
|
+
if (!full) {
|
|
364
|
+
callback(new Error('range read did not cover the requested bytes'));
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
full.copy(buffer, offset);
|
|
214
368
|
callback(null, length);
|
|
215
369
|
}, (error) => callback(error));
|
|
216
370
|
}
|
|
217
371
|
}
|
|
218
372
|
exports.HttpRangeReader = HttpRangeReader;
|
|
373
|
+
/** End-of-central-directory record: where the central directory lives. */
|
|
374
|
+
const EOCD_SIGNATURE = 0x06054b50;
|
|
375
|
+
const EOCD_SIZE = 22;
|
|
376
|
+
/** central directories larger than this are left to yauzl's paged reads */
|
|
377
|
+
const MAX_PREFETCH_BYTES = 8 * 1024 * 1024;
|
|
378
|
+
function parseEndOfCentralDirectory(tail) {
|
|
379
|
+
for (let i = tail.length - EOCD_SIZE; i >= 0; i--) {
|
|
380
|
+
if (tail.readUInt32LE(i) !== EOCD_SIGNATURE)
|
|
381
|
+
continue;
|
|
382
|
+
const commentLength = tail.readUInt16LE(i + 20);
|
|
383
|
+
if (i + EOCD_SIZE + commentLength !== tail.length)
|
|
384
|
+
continue;
|
|
385
|
+
const cdSize = tail.readUInt32LE(i + 12);
|
|
386
|
+
const cdOffset = tail.readUInt32LE(i + 16);
|
|
387
|
+
// zip64 markers: let yauzl resolve the real values itself
|
|
388
|
+
if (cdSize === 0xffffffff || cdOffset === 0xffffffff)
|
|
389
|
+
return null;
|
|
390
|
+
return { cdOffset, cdSize };
|
|
391
|
+
}
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
219
394
|
/**
|
|
220
395
|
* Open a remote zip by fetching its tail (EOCD + central directory for
|
|
221
396
|
* typical archives) and letting yauzl read the rest on demand.
|
|
@@ -245,13 +420,28 @@ async function openRemoteZip(url) {
|
|
|
245
420
|
});
|
|
246
421
|
reader.requests = 1;
|
|
247
422
|
reader.fetchedBytes = data.length;
|
|
423
|
+
// Large archives (apk / ipa with thousands of files) keep their central
|
|
424
|
+
// directory well before the tail; yauzl would otherwise page it in with one
|
|
425
|
+
// sequential request per CHUNK_BYTES. Fetch the missing part at once.
|
|
426
|
+
const eocd = parseEndOfCentralDirectory(data);
|
|
427
|
+
if (eocd &&
|
|
428
|
+
eocd.cdOffset < range.start &&
|
|
429
|
+
range.start - eocd.cdOffset <= MAX_PREFETCH_BYTES) {
|
|
430
|
+
const { data: directory } = await fetchRangeBuffer(url, eocd.cdOffset, range.start);
|
|
431
|
+
reader.requests++;
|
|
432
|
+
reader.fetchedBytes += directory.length;
|
|
433
|
+
reader.addChunk(eocd.cdOffset, directory);
|
|
434
|
+
}
|
|
248
435
|
const zipFile = await new Promise((resolve, reject) => {
|
|
249
436
|
(0, yauzl_1.fromRandomAccessReader)(reader, range.total, { lazyEntries: true, autoClose: false }, (err, file) => (err ? reject(err) : resolve(file)));
|
|
250
437
|
});
|
|
251
438
|
return { kind: 'zip', zipFile, reader };
|
|
252
439
|
}
|
|
253
|
-
/**
|
|
254
|
-
|
|
440
|
+
/**
|
|
441
|
+
* Read the first matching entry of an opened remote zip, then close it. With
|
|
442
|
+
* `reader` given, the entry's header and data are fetched in one request.
|
|
443
|
+
*/
|
|
444
|
+
function readRemoteZipEntry(zipFile, matches, reader) {
|
|
255
445
|
return new Promise((resolve, reject) => {
|
|
256
446
|
let settled = false;
|
|
257
447
|
const finish = (error, result = null) => {
|
|
@@ -268,6 +458,7 @@ function readRemoteZipEntry(zipFile, matches) {
|
|
|
268
458
|
zipFile.readEntry();
|
|
269
459
|
return;
|
|
270
460
|
}
|
|
461
|
+
reader?.hintEntry(entry);
|
|
271
462
|
(0, zip_entries_1.readEntry)(entry, zipFile).then((data) => finish(null, data), (error) => finish(error));
|
|
272
463
|
});
|
|
273
464
|
zipFile.readEntry();
|
package/lib/versions.js
CHANGED
|
@@ -329,24 +329,21 @@ async function describePpkBundle(ppkPath, base) {
|
|
|
329
329
|
// server version — strict, tolerant or too old to know the field — accepts.
|
|
330
330
|
const meta = {};
|
|
331
331
|
try {
|
|
332
|
-
|
|
332
|
+
// one pass over the ppk: the bundle itself plus where its compressed
|
|
333
|
+
// bytes live, so the next build can fetch just them with one HTTP Range
|
|
334
|
+
// request
|
|
335
|
+
const found = ppkPath.toLowerCase().endsWith('.ppk')
|
|
336
|
+
? await (0, zip_range_1.readZipEntryWithLocation)(ppkPath, (name) => hermes_base_1.BUNDLE_ENTRY_NAMES.includes(name)).catch(() => null)
|
|
337
|
+
: null;
|
|
338
|
+
const bundle = found?.data ?? (await (0, hermes_base_1.extractBundleFromArchive)(ppkPath));
|
|
333
339
|
if (bundle) {
|
|
334
|
-
|
|
340
|
+
const bundleHash = (0, hermes_base_1.sha256Hex)(bundle);
|
|
341
|
+
meta.bundleHash = bundleHash;
|
|
335
342
|
const hbcVersion = (0, hbcTransform_1.getHbcVersion)(bundle) ?? base?.bytecodeVersion;
|
|
336
343
|
if (hbcVersion != null)
|
|
337
344
|
meta.bytecodeVersion = hbcVersion;
|
|
338
|
-
await (0, hermes_base_1.cachePut)(bundle).catch(() => { });
|
|
339
|
-
|
|
340
|
-
// build can fetch just them with one HTTP Range request
|
|
341
|
-
const location = await (0, zip_range_1.locateZipEntry)(ppkPath, (name) => hermes_base_1.BUNDLE_ENTRY_NAMES.includes(name)).catch(() => null);
|
|
342
|
-
if (location &&
|
|
343
|
-
location.compressedSize > 0 &&
|
|
344
|
-
(location.compressionMethod === zip_range_1.ZIP_STORED ||
|
|
345
|
-
location.compressionMethod === zip_range_1.ZIP_DEFLATED)) {
|
|
346
|
-
meta.bundleOffset = location.dataOffset;
|
|
347
|
-
meta.bundleCompressedSize = location.compressedSize;
|
|
348
|
-
meta.bundleCompression = location.compressionMethod;
|
|
349
|
-
}
|
|
345
|
+
await (0, hermes_base_1.cachePut)(bundle, undefined, bundleHash).catch(() => { });
|
|
346
|
+
Object.assign(meta, (0, zip_range_1.bundleLocationFields)(found?.location));
|
|
350
347
|
}
|
|
351
348
|
}
|
|
352
349
|
catch {
|
package/package.json
CHANGED