react-native-update-cli 2.28.1 → 2.28.3
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/lib/package.js +5 -0
- package/lib/utils/hermes-base.d.ts +21 -1
- package/lib/utils/hermes-base.js +72 -15
- package/lib/utils/zip-range.d.ts +20 -2
- package/lib/utils/zip-range.js +77 -5
- package/lib/versions.js +2 -4
- package/package.json +1 -1
package/lib/package.js
CHANGED
|
@@ -154,6 +154,11 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
154
154
|
// against the client-reported bundleHash to decide pdiff applicability.
|
|
155
155
|
// Old servers strip unknown fields, so this is forward-compatible.
|
|
156
156
|
...(bundleHash ? { bundleHash } : {}),
|
|
157
|
+
// HBC version of the embedded bundle (0 = plain JS), so the server
|
|
158
|
+
// offers this package as hermes base only to a matching compile
|
|
159
|
+
...(bundleFile
|
|
160
|
+
? { bytecodeVersion: (0, hermes_base_1.reportedBytecodeVersion)(bundleFile) }
|
|
161
|
+
: {}),
|
|
157
162
|
...bundleLocation,
|
|
158
163
|
deps: (0, dep_versions_1.getDepVersions)(),
|
|
159
164
|
commit: await (0, git_1.getCommitInfo)(),
|
|
@@ -10,6 +10,20 @@ export declare class PermanentBaseError extends Error {
|
|
|
10
10
|
export declare class BundleHashMismatchError extends PermanentBaseError {
|
|
11
11
|
constructor(actual: string, expected: string);
|
|
12
12
|
}
|
|
13
|
+
/** The base bundle is not Hermes bytecode of the version being compiled. */
|
|
14
|
+
export declare class HbcVersionMismatchError extends PermanentBaseError {
|
|
15
|
+
readonly version: number | null;
|
|
16
|
+
readonly expected: number;
|
|
17
|
+
constructor(version: number | null, expected: number);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* `bytecodeVersion` reported for a bundle that is not Hermes bytecode, so the
|
|
21
|
+
* server can tell "plain JS" from "not reported" (NULL) and never offers it
|
|
22
|
+
* as a base.
|
|
23
|
+
*/
|
|
24
|
+
export declare const PLAIN_JS_BYTECODE_VERSION = 0;
|
|
25
|
+
/** the `bytecodeVersion` to report for `bundle` at publish / upload time */
|
|
26
|
+
export declare function reportedBytecodeVersion(bundle: Buffer): number;
|
|
13
27
|
export interface HermesBaseSelection {
|
|
14
28
|
/** path of the bundle (HBC) handed to hermesc as -base-bytecode */
|
|
15
29
|
path: string;
|
|
@@ -152,8 +166,14 @@ interface FetchedBaseBundle {
|
|
|
152
166
|
* recorded location is stale, so the directory transport (2) still runs; a
|
|
153
167
|
* mismatch of the entry itself (2, 3) is final — the same bytes would come
|
|
154
168
|
* back however they are fetched — and raises BundleHashMismatchError.
|
|
169
|
+
*
|
|
170
|
+
* With `expectHbcVersion` (the server does not know the base's version), the
|
|
171
|
+
* bundle's first bytes are checked before its body is fetched; a base of
|
|
172
|
+
* another HBC version, or plain JS, raises HbcVersionMismatchError without
|
|
173
|
+
* downloading the rest. A head read at a recorded location (1) may be stale,
|
|
174
|
+
* so only the directory transport (2) decides.
|
|
155
175
|
*/
|
|
156
|
-
export declare function fetchBaseBundle(record: HermesBaseServerRecord, artifactType: BaseArtifactType, archive: string, log?: (message: string) => void): Promise<FetchedBaseBundle>;
|
|
176
|
+
export declare function fetchBaseBundle(record: HermesBaseServerRecord, artifactType: BaseArtifactType, archive: string, log?: (message: string) => void, expectHbcVersion?: number): Promise<FetchedBaseBundle>;
|
|
157
177
|
export interface ResolveHermesBaseParams {
|
|
158
178
|
option: HermesBaseOption;
|
|
159
179
|
hermesCommand: string;
|
package/lib/utils/hermes-base.js
CHANGED
|
@@ -46,7 +46,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
47
|
};
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
exports.LITERAL_SEPARATOR = 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.HERMES_BASE_DETAIL_MAX_CHARS = exports.BundleHashMismatchError = exports.PermanentBaseError = void 0;
|
|
49
|
+
exports.LITERAL_SEPARATOR = 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.HERMES_BASE_DETAIL_MAX_CHARS = exports.PLAIN_JS_BYTECODE_VERSION = exports.HbcVersionMismatchError = exports.BundleHashMismatchError = exports.PermanentBaseError = void 0;
|
|
50
|
+
exports.reportedBytecodeVersion = reportedBytecodeVersion;
|
|
50
51
|
exports.classifyHermesCommand = classifyHermesCommand;
|
|
51
52
|
exports.sha256Hex = sha256Hex;
|
|
52
53
|
exports.sha256File = sha256File;
|
|
@@ -105,6 +106,32 @@ class BundleHashMismatchError extends PermanentBaseError {
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
exports.BundleHashMismatchError = BundleHashMismatchError;
|
|
109
|
+
/** The base bundle is not Hermes bytecode of the version being compiled. */
|
|
110
|
+
class HbcVersionMismatchError extends PermanentBaseError {
|
|
111
|
+
version;
|
|
112
|
+
expected;
|
|
113
|
+
constructor(version, expected) {
|
|
114
|
+
super(`downloaded base is ${version == null ? 'plain JS' : `HBC ${version}`}, need ${expected}`);
|
|
115
|
+
this.version = version;
|
|
116
|
+
this.expected = expected;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.HbcVersionMismatchError = HbcVersionMismatchError;
|
|
120
|
+
/**
|
|
121
|
+
* `bytecodeVersion` reported for a bundle that is not Hermes bytecode, so the
|
|
122
|
+
* server can tell "plain JS" from "not reported" (NULL) and never offers it
|
|
123
|
+
* as a base.
|
|
124
|
+
*/
|
|
125
|
+
exports.PLAIN_JS_BYTECODE_VERSION = 0;
|
|
126
|
+
/** the `bytecodeVersion` to report for `bundle` at publish / upload time */
|
|
127
|
+
function reportedBytecodeVersion(bundle) {
|
|
128
|
+
return (0, hbcTransform_1.getHbcVersion)(bundle) ?? exports.PLAIN_JS_BYTECODE_VERSION;
|
|
129
|
+
}
|
|
130
|
+
const describeBytecodeVersion = (version) => version === exports.PLAIN_JS_BYTECODE_VERSION
|
|
131
|
+
? 'plain JS'
|
|
132
|
+
: `HBC ${version ?? 'n/a'}`;
|
|
133
|
+
/** bytes `getHbcVersion` needs to read the version */
|
|
134
|
+
const HBC_HEAD_BYTES = 128;
|
|
108
135
|
/** time allowed for a response to start (headers) */
|
|
109
136
|
const FETCH_HEADERS_TIMEOUT_MS = 30_000;
|
|
110
137
|
/** a download that receives nothing for this long is abandoned */
|
|
@@ -517,6 +544,9 @@ async function downloadToFile(url, destination) {
|
|
|
517
544
|
}
|
|
518
545
|
await saveResponse(response, destination, controller);
|
|
519
546
|
}
|
|
547
|
+
/** the head at a recorded bundle location is not the expected bytecode */
|
|
548
|
+
class StaleHeadError extends Error {
|
|
549
|
+
}
|
|
520
550
|
function hasBundleLocation(record) {
|
|
521
551
|
return (record.bundleOffset != null &&
|
|
522
552
|
record.bundleCompressedSize != null &&
|
|
@@ -564,8 +594,14 @@ async function saveResponse(response, destination, controller = new AbortControl
|
|
|
564
594
|
* recorded location is stale, so the directory transport (2) still runs; a
|
|
565
595
|
* mismatch of the entry itself (2, 3) is final — the same bytes would come
|
|
566
596
|
* back however they are fetched — and raises BundleHashMismatchError.
|
|
597
|
+
*
|
|
598
|
+
* With `expectHbcVersion` (the server does not know the base's version), the
|
|
599
|
+
* bundle's first bytes are checked before its body is fetched; a base of
|
|
600
|
+
* another HBC version, or plain JS, raises HbcVersionMismatchError without
|
|
601
|
+
* downloading the rest. A head read at a recorded location (1) may be stale,
|
|
602
|
+
* so only the directory transport (2) decides.
|
|
567
603
|
*/
|
|
568
|
-
async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
604
|
+
async function fetchBaseBundle(record, artifactType, archive, log = () => { }, expectHbcVersion) {
|
|
569
605
|
const matches = bundleEntryMatcher(artifactType);
|
|
570
606
|
const verified = (bundle) => {
|
|
571
607
|
if (!bundle)
|
|
@@ -587,12 +623,17 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
587
623
|
// harmony .app nests the bundle in a second zip, so a location inside the
|
|
588
624
|
// outer archive is never reported for it
|
|
589
625
|
if (artifactType !== 'app' && hasBundleLocation(record)) {
|
|
626
|
+
const location = {
|
|
627
|
+
dataOffset: record.bundleOffset,
|
|
628
|
+
compressedSize: record.bundleCompressedSize,
|
|
629
|
+
compressionMethod: record.bundleCompression,
|
|
630
|
+
};
|
|
590
631
|
try {
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
});
|
|
632
|
+
const headMatches = expectHbcVersion === undefined ||
|
|
633
|
+
(0, hbcTransform_1.getHbcVersion)(await (0, zip_range_1.fetchZipEntryHead)(record.url, location, HBC_HEAD_BYTES)) === expectHbcVersion;
|
|
634
|
+
if (!headMatches)
|
|
635
|
+
throw new StaleHeadError();
|
|
636
|
+
const { data, fetchedBytes, totalBytes } = await (0, zip_range_1.fetchZipEntryData)(record.url, location);
|
|
596
637
|
return {
|
|
597
638
|
...verified(data),
|
|
598
639
|
transport: 'range-entry',
|
|
@@ -605,7 +646,10 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
605
646
|
skip('server ignores Range');
|
|
606
647
|
return fromFullResponse(error.response);
|
|
607
648
|
}
|
|
608
|
-
|
|
649
|
+
// not a transport failure: the directory read below settles it
|
|
650
|
+
if (!(error instanceof StaleHeadError)) {
|
|
651
|
+
skip(`entry range: ${error?.message ?? error}`);
|
|
652
|
+
}
|
|
609
653
|
}
|
|
610
654
|
}
|
|
611
655
|
if (artifactType !== 'app') {
|
|
@@ -615,7 +659,17 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
|
615
659
|
skip('server ignores Range');
|
|
616
660
|
return fromFullResponse(remote.response);
|
|
617
661
|
}
|
|
618
|
-
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches, remote.reader
|
|
662
|
+
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches, remote.reader, expectHbcVersion === undefined
|
|
663
|
+
? undefined
|
|
664
|
+
: {
|
|
665
|
+
bytes: HBC_HEAD_BYTES,
|
|
666
|
+
check: (head) => {
|
|
667
|
+
const version = (0, hbcTransform_1.getHbcVersion)(head);
|
|
668
|
+
if (version !== expectHbcVersion) {
|
|
669
|
+
throw new HbcVersionMismatchError(version, expectHbcVersion);
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
});
|
|
619
673
|
return {
|
|
620
674
|
...verified(bundle),
|
|
621
675
|
transport: 'range-zip',
|
|
@@ -704,7 +758,7 @@ async function resolveHermesBase(params) {
|
|
|
704
758
|
if (record.bytecodeVersion != null &&
|
|
705
759
|
record.bytecodeVersion !== bytecodeVersion) {
|
|
706
760
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
707
|
-
reason: `server base is
|
|
761
|
+
reason: `server base is ${describeBytecodeVersion(record.bytecodeVersion)}, need ${bytecodeVersion}`,
|
|
708
762
|
}));
|
|
709
763
|
return null;
|
|
710
764
|
}
|
|
@@ -752,7 +806,9 @@ async function resolveHermesBase(params) {
|
|
|
752
806
|
const archive = path_1.default.join(dir, `base-${process.pid}-${Date.now()}-${attempt}.${artifactType}`);
|
|
753
807
|
try {
|
|
754
808
|
log((0, i18n_1.t)('hermesBaseDownloading', { url: record.url }));
|
|
755
|
-
const fetched = await fetchBaseBundle(record, artifactType, archive, log
|
|
809
|
+
const fetched = await fetchBaseBundle(record, artifactType, archive, log,
|
|
810
|
+
// a server that knows the version already matched it above
|
|
811
|
+
record.bytecodeVersion == null ? bytecodeVersion : undefined);
|
|
756
812
|
const { bundle, bundleHash: actualHash } = fetched;
|
|
757
813
|
if (fetched.transport !== 'full') {
|
|
758
814
|
log((0, i18n_1.t)('hermesBaseRangeFetched', {
|
|
@@ -762,10 +818,7 @@ async function resolveHermesBase(params) {
|
|
|
762
818
|
}
|
|
763
819
|
const version = (0, hbcTransform_1.getHbcVersion)(bundle);
|
|
764
820
|
if (version !== bytecodeVersion) {
|
|
765
|
-
|
|
766
|
-
reason: `downloaded base is HBC ${version ?? 'n/a'}, need ${bytecodeVersion}`,
|
|
767
|
-
}));
|
|
768
|
-
return null;
|
|
821
|
+
throw new HbcVersionMismatchError(version, bytecodeVersion);
|
|
769
822
|
}
|
|
770
823
|
const cached = await cachePut(bundle, params.cacheMaxMb, actualHash);
|
|
771
824
|
log((0, i18n_1.t)('hermesBaseUsing', {
|
|
@@ -784,6 +837,10 @@ async function resolveHermesBase(params) {
|
|
|
784
837
|
};
|
|
785
838
|
}
|
|
786
839
|
catch (error) {
|
|
840
|
+
if (error instanceof HbcVersionMismatchError) {
|
|
841
|
+
log((0, i18n_1.t)('hermesBaseNone', { reason: error.message }));
|
|
842
|
+
return null;
|
|
843
|
+
}
|
|
787
844
|
if (attempt === 2 || error instanceof PermanentBaseError) {
|
|
788
845
|
log((0, i18n_1.t)('hermesBaseNone', {
|
|
789
846
|
reason: `download/verify failed: ${error?.message ?? error}`,
|
package/lib/utils/zip-range.d.ts
CHANGED
|
@@ -63,6 +63,16 @@ export declare function fetchZipEntryData(url: string, location: Pick<ZipEntryLo
|
|
|
63
63
|
fetchedBytes: number;
|
|
64
64
|
totalBytes: number;
|
|
65
65
|
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Up to `bytes` leading bytes of an entry, decoded from a prefix of its
|
|
68
|
+
* compressed data (a truncated deflate stream is inflated as far as it goes).
|
|
69
|
+
*/
|
|
70
|
+
export declare function decodeEntryHead(raw: Buffer, compressionMethod: number, bytes: number): Buffer;
|
|
71
|
+
/**
|
|
72
|
+
* The first `bytes` of an entry whose compressed bytes are already located,
|
|
73
|
+
* from one small Range request (see `fetchZipEntryData`).
|
|
74
|
+
*/
|
|
75
|
+
export declare function fetchZipEntryHead(url: string, location: Pick<ZipEntryLocation, 'dataOffset' | 'compressedSize' | 'compressionMethod'>, bytes: number, options?: RangeOptions): Promise<Buffer>;
|
|
66
76
|
export interface HttpRangeReaderOptions extends RangeOptions {
|
|
67
77
|
/** validator of the archive (see `rangeValidator`), sent as If-Range */
|
|
68
78
|
ifRange?: string;
|
|
@@ -135,9 +145,17 @@ export type RemoteZip = {
|
|
|
135
145
|
* typical archives) and letting yauzl read the rest on demand.
|
|
136
146
|
*/
|
|
137
147
|
export declare function openRemoteZip(url: string, options?: RangeOptions): Promise<RemoteZip>;
|
|
148
|
+
/** Look at the head of the matched entry before its body is fetched. */
|
|
149
|
+
export interface EntryHeadCheck {
|
|
150
|
+
bytes: number;
|
|
151
|
+
/** throw to abandon the entry; the error is passed on as is */
|
|
152
|
+
check: (head: Buffer) => void;
|
|
153
|
+
}
|
|
138
154
|
/**
|
|
139
155
|
* Read the first matching entry of an opened remote zip, then close it. With
|
|
140
|
-
* `reader` given, the entry's header and data are fetched in one request
|
|
156
|
+
* `reader` given, the entry's header and data are fetched in one request —
|
|
157
|
+
* or, with `head` too, its first bytes are checked first (header and head
|
|
158
|
+
* share one small request, the rest of the body follows only if they pass).
|
|
141
159
|
*/
|
|
142
|
-
export declare function readRemoteZipEntry(zipFile: ZipFile, matches: (name: string) => boolean, reader?: HttpRangeReader): Promise<Buffer | null>;
|
|
160
|
+
export declare function readRemoteZipEntry(zipFile: ZipFile, matches: (name: string) => boolean, reader?: HttpRangeReader, head?: EntryHeadCheck): Promise<Buffer | null>;
|
|
143
161
|
export {};
|
package/lib/utils/zip-range.js
CHANGED
|
@@ -10,6 +10,8 @@ exports.bundleLocationFields = bundleLocationFields;
|
|
|
10
10
|
exports.parseContentRange = parseContentRange;
|
|
11
11
|
exports.rangeValidator = rangeValidator;
|
|
12
12
|
exports.fetchZipEntryData = fetchZipEntryData;
|
|
13
|
+
exports.decodeEntryHead = decodeEntryHead;
|
|
14
|
+
exports.fetchZipEntryHead = fetchZipEntryHead;
|
|
13
15
|
exports.parseEndOfCentralDirectory = parseEndOfCentralDirectory;
|
|
14
16
|
exports.openRemoteZip = openRemoteZip;
|
|
15
17
|
exports.readRemoteZipEntry = readRemoteZipEntry;
|
|
@@ -40,6 +42,11 @@ const TAIL_BYTES = 22 + 0xffff + 20;
|
|
|
40
42
|
const CHUNK_BYTES = 64 * 1024;
|
|
41
43
|
/** extra bytes past a hinted entry, covering a longer local extra field */
|
|
42
44
|
const HINT_SLACK_BYTES = 4 * 1024;
|
|
45
|
+
/**
|
|
46
|
+
* compressed bytes fetched to decode the head of a deflated entry: the
|
|
47
|
+
* dynamic Huffman header plus the first literals fit comfortably
|
|
48
|
+
*/
|
|
49
|
+
const HEAD_PROBE_BYTES = 4 * 1024;
|
|
43
50
|
/** Data location of the first entry matching `matches` in a local zip. */
|
|
44
51
|
async function locateZipEntry(zipPath, matches) {
|
|
45
52
|
const found = await openFirstEntry(zipPath, matches);
|
|
@@ -154,7 +161,8 @@ function timeoutFor(bytes, options) {
|
|
|
154
161
|
if (bytes <= CHUNK_BYTES) {
|
|
155
162
|
return options.headerTimeoutMs ?? DEFAULT_HEADER_TIMEOUT_MS;
|
|
156
163
|
}
|
|
157
|
-
|
|
164
|
+
// AbortSignal.timeout() rejects a fractional delay
|
|
165
|
+
return Math.ceil((options.dataTimeoutMs ?? DEFAULT_DATA_TIMEOUT_MS) +
|
|
158
166
|
((options.dataTimeoutPerMbMs ?? DEFAULT_DATA_TIMEOUT_PER_MB_MS) * bytes) /
|
|
159
167
|
(1024 * 1024));
|
|
160
168
|
}
|
|
@@ -270,6 +278,42 @@ async function fetchZipEntryData(url, location, options = {}) {
|
|
|
270
278
|
totalBytes: total,
|
|
271
279
|
};
|
|
272
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Up to `bytes` leading bytes of an entry, decoded from a prefix of its
|
|
283
|
+
* compressed data (a truncated deflate stream is inflated as far as it goes).
|
|
284
|
+
*/
|
|
285
|
+
function decodeEntryHead(raw, compressionMethod, bytes) {
|
|
286
|
+
if (compressionMethod === exports.ZIP_STORED)
|
|
287
|
+
return raw.subarray(0, bytes);
|
|
288
|
+
if (compressionMethod !== exports.ZIP_DEFLATED) {
|
|
289
|
+
throw new Error(`unsupported compression method ${compressionMethod}`);
|
|
290
|
+
}
|
|
291
|
+
return (0, zlib_1.inflateRawSync)(raw, {
|
|
292
|
+
finishFlush: zlib_1.constants.Z_SYNC_FLUSH,
|
|
293
|
+
}).subarray(0, bytes);
|
|
294
|
+
}
|
|
295
|
+
/** compressed bytes needed to decode the first `bytes` of an entry */
|
|
296
|
+
function headProbeSize(compressedSize, compressionMethod, bytes) {
|
|
297
|
+
return Math.min(compressedSize, compressionMethod === exports.ZIP_STORED ? bytes : HEAD_PROBE_BYTES);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The first `bytes` of an entry whose compressed bytes are already located,
|
|
301
|
+
* from one small Range request (see `fetchZipEntryData`).
|
|
302
|
+
*/
|
|
303
|
+
async function fetchZipEntryHead(url, location, bytes, options = {}) {
|
|
304
|
+
const { dataOffset, compressedSize, compressionMethod } = location;
|
|
305
|
+
if (!Number.isInteger(dataOffset) ||
|
|
306
|
+
!Number.isInteger(compressedSize) ||
|
|
307
|
+
dataOffset < 0 ||
|
|
308
|
+
compressedSize <= 0) {
|
|
309
|
+
throw new Error('invalid bundle location');
|
|
310
|
+
}
|
|
311
|
+
const size = headProbeSize(compressedSize, compressionMethod, bytes);
|
|
312
|
+
const { data } = await fetchRangeBuffer(url, dataOffset, dataOffset + size, {
|
|
313
|
+
timeoutMs: timeoutFor(size, options),
|
|
314
|
+
});
|
|
315
|
+
return decodeEntryHead(data, compressionMethod, bytes);
|
|
316
|
+
}
|
|
273
317
|
/**
|
|
274
318
|
* yauzl reader over HTTP Range. Header reads (EOCD, central directory, local
|
|
275
319
|
* file headers) are widened to CHUNK_BYTES and cached. Chunks are kept as
|
|
@@ -547,11 +591,34 @@ async function openRemoteZip(url, options = {}) {
|
|
|
547
591
|
});
|
|
548
592
|
return { kind: 'zip', zipFile, reader };
|
|
549
593
|
}
|
|
594
|
+
/** `reader.read` as a promise */
|
|
595
|
+
function readAt(reader, position, length) {
|
|
596
|
+
const buffer = Buffer.alloc(length);
|
|
597
|
+
return new Promise((resolve, reject) => reader.read(buffer, 0, length, position, (error) => error ? reject(error) : resolve(buffer)));
|
|
598
|
+
}
|
|
599
|
+
/** The first `bytes` of `entry`, read through `reader` without its body. */
|
|
600
|
+
async function remoteEntryHead(reader, entry, bytes) {
|
|
601
|
+
const start = entry.relativeOffsetOfLocalHeader;
|
|
602
|
+
const header = await readAt(reader, start, LOCAL_HEADER_SIZE);
|
|
603
|
+
if (header.readUInt32LE(0) !== LOCAL_HEADER_SIGNATURE) {
|
|
604
|
+
throw new Error('invalid local file header signature');
|
|
605
|
+
}
|
|
606
|
+
const dataOffset = start +
|
|
607
|
+
LOCAL_HEADER_SIZE +
|
|
608
|
+
header.readUInt16LE(26) +
|
|
609
|
+
header.readUInt16LE(28);
|
|
610
|
+
const size = headProbeSize(entry.compressedSize, entry.compressionMethod, bytes);
|
|
611
|
+
if (size <= 0)
|
|
612
|
+
return Buffer.alloc(0);
|
|
613
|
+
return decodeEntryHead(await readAt(reader, dataOffset, size), entry.compressionMethod, bytes);
|
|
614
|
+
}
|
|
550
615
|
/**
|
|
551
616
|
* Read the first matching entry of an opened remote zip, then close it. With
|
|
552
|
-
* `reader` given, the entry's header and data are fetched in one request
|
|
617
|
+
* `reader` given, the entry's header and data are fetched in one request —
|
|
618
|
+
* or, with `head` too, its first bytes are checked first (header and head
|
|
619
|
+
* share one small request, the rest of the body follows only if they pass).
|
|
553
620
|
*/
|
|
554
|
-
function readRemoteZipEntry(zipFile, matches, reader) {
|
|
621
|
+
function readRemoteZipEntry(zipFile, matches, reader, head) {
|
|
555
622
|
return new Promise((resolve, reject) => {
|
|
556
623
|
let settled = false;
|
|
557
624
|
const finish = (error, result = null) => {
|
|
@@ -568,8 +635,13 @@ function readRemoteZipEntry(zipFile, matches, reader) {
|
|
|
568
635
|
zipFile.readEntry();
|
|
569
636
|
return;
|
|
570
637
|
}
|
|
571
|
-
reader
|
|
572
|
-
|
|
638
|
+
const probe = reader && head
|
|
639
|
+
? remoteEntryHead(reader, entry, head.bytes).then(head.check)
|
|
640
|
+
: // without a probe the header read may take the body along
|
|
641
|
+
Promise.resolve(reader?.hintEntry(entry));
|
|
642
|
+
probe
|
|
643
|
+
.then(() => (0, zip_entries_1.readEntry)(entry, zipFile))
|
|
644
|
+
.then((data) => finish(null, data), (error) => finish(error));
|
|
573
645
|
});
|
|
574
646
|
zipFile.readEntry();
|
|
575
647
|
});
|
package/lib/versions.js
CHANGED
|
@@ -17,7 +17,6 @@ const package_1 = require("./package");
|
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
18
|
const dep_versions_1 = require("./utils/dep-versions");
|
|
19
19
|
const git_1 = require("./utils/git");
|
|
20
|
-
const hbcTransform_1 = require("./utils/hbcTransform");
|
|
21
20
|
const hermes_base_1 = require("./utils/hermes-base");
|
|
22
21
|
const i18n_1 = require("./utils/i18n");
|
|
23
22
|
const options_1 = require("./utils/options");
|
|
@@ -344,9 +343,8 @@ async function describePpkBundle(ppkPath, base) {
|
|
|
344
343
|
if (bundle) {
|
|
345
344
|
const bundleHash = (0, hermes_base_1.sha256Hex)(bundle);
|
|
346
345
|
meta.bundleHash = bundleHash;
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
meta.bytecodeVersion = hbcVersion;
|
|
346
|
+
// 0 for plain JS: the server then never offers it as a Hermes base
|
|
347
|
+
meta.bytecodeVersion = (0, hermes_base_1.reportedBytecodeVersion)(bundle);
|
|
350
348
|
await (0, hermes_base_1.cachePut)(bundle, undefined, bundleHash).catch(() => { });
|
|
351
349
|
Object.assign(meta, (0, zip_range_1.bundleLocationFields)(found?.location));
|
|
352
350
|
}
|
package/package.json
CHANGED