react-native-update-cli 2.22.4 → 2.22.6
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/bundle-runner.d.ts +8 -0
- package/lib/bundle-runner.js +45 -4
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +3 -0
- package/lib/locales/zh.d.ts +3 -0
- package/lib/locales/zh.js +3 -0
- package/lib/utils/hermes-base.d.ts +34 -1
- package/lib/utils/hermes-base.js +123 -12
- package/lib/utils/zip-range.d.ts +72 -0
- package/lib/utils/zip-range.js +275 -0
- package/lib/versions.js +12 -0
- package/package.json +1 -1
- package/src/bundle-runner.ts +42 -4
- package/src/locales/en.ts +6 -0
- package/src/locales/zh.ts +5 -0
- package/src/utils/hermes-base.ts +176 -19
- package/src/utils/zip-range.ts +358 -0
- package/src/versions.ts +17 -0
package/lib/bundle-runner.d.ts
CHANGED
|
@@ -73,6 +73,14 @@ export declare function resolveHermesCommand(projectRoot?: string): string;
|
|
|
73
73
|
* simply stays in the intermediate directory (never packed into the ppk) so
|
|
74
74
|
* `address at` stack frames can still be symbolicated later.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* hermesc echoes every diagnostic as three lines (header, the offending source
|
|
78
|
+
* line, a caret line). Minified bundles put a whole module on one line, so a
|
|
79
|
+
* single warning can be 100k+ characters and blindly keeping the tail of stderr
|
|
80
|
+
* buries the actual error under warning noise. Keep the diagnostic headers,
|
|
81
|
+
* prefer errors over warnings, and cap the length of whatever survives.
|
|
82
|
+
*/
|
|
83
|
+
export declare function summarizeHermescStderr(stderr: string): string;
|
|
76
84
|
export declare function buildHermescArgs(bundlePath: string): string[];
|
|
77
85
|
export declare function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string): Promise<void>;
|
|
78
86
|
export declare function prepareSentryUploadArtifacts(bundleName: string, outputFolder: string, platform: string): Promise<SentryUploadArtifacts>;
|
package/lib/bundle-runner.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.hasProjectDependency = hasProjectDependency;
|
|
|
40
40
|
exports.resolveExpoCli = resolveExpoCli;
|
|
41
41
|
exports.runReactNativeBundleCommand = runReactNativeBundleCommand;
|
|
42
42
|
exports.resolveHermesCommand = resolveHermesCommand;
|
|
43
|
+
exports.summarizeHermescStderr = summarizeHermescStderr;
|
|
43
44
|
exports.buildHermescArgs = buildHermescArgs;
|
|
44
45
|
exports.copyDebugidForSentry = copyDebugidForSentry;
|
|
45
46
|
exports.prepareSentryUploadArtifacts = prepareSentryUploadArtifacts;
|
|
@@ -388,6 +389,38 @@ async function checkGradleConfig() {
|
|
|
388
389
|
* simply stays in the intermediate directory (never packed into the ppk) so
|
|
389
390
|
* `address at` stack frames can still be symbolicated later.
|
|
390
391
|
*/
|
|
392
|
+
/**
|
|
393
|
+
* hermesc echoes every diagnostic as three lines (header, the offending source
|
|
394
|
+
* line, a caret line). Minified bundles put a whole module on one line, so a
|
|
395
|
+
* single warning can be 100k+ characters and blindly keeping the tail of stderr
|
|
396
|
+
* buries the actual error under warning noise. Keep the diagnostic headers,
|
|
397
|
+
* prefer errors over warnings, and cap the length of whatever survives.
|
|
398
|
+
*/
|
|
399
|
+
function summarizeHermescStderr(stderr) {
|
|
400
|
+
const raw = String(stderr ?? '').split(/\r?\n/);
|
|
401
|
+
const kept = [];
|
|
402
|
+
for (let i = 0; i < raw.length; i++) {
|
|
403
|
+
const line = raw[i].trim();
|
|
404
|
+
if (!line)
|
|
405
|
+
continue;
|
|
406
|
+
if (/^\^~*$/.test(line))
|
|
407
|
+
continue; // caret line
|
|
408
|
+
// the line before a caret is the echoed source, never the message
|
|
409
|
+
const next = raw[i + 1]?.trim();
|
|
410
|
+
if (next && /^\^~*$/.test(next))
|
|
411
|
+
continue;
|
|
412
|
+
kept.push(line.length > 300 ? `${line.slice(0, 300)}…` : line);
|
|
413
|
+
}
|
|
414
|
+
if (kept.length === 0)
|
|
415
|
+
return '';
|
|
416
|
+
const isError = (line) => /(?::\s*|^)(?:fatal error|error)\b/i.test(line) ||
|
|
417
|
+
/^(?:Assertion|Stack dump|PLEASE submit a bug report)/i.test(line);
|
|
418
|
+
const errors = kept.filter(isError);
|
|
419
|
+
if (errors.length > 0)
|
|
420
|
+
return errors.slice(-3).join(' ');
|
|
421
|
+
const notWarnings = kept.filter((line) => !/:\s*(?:warning|note):/i.test(line));
|
|
422
|
+
return (notWarnings.length > 0 ? notWarnings : kept).slice(-3).join(' ');
|
|
423
|
+
}
|
|
391
424
|
function buildHermescArgs(bundlePath) {
|
|
392
425
|
return [
|
|
393
426
|
'-emit-binary',
|
|
@@ -428,12 +461,20 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
|
|
|
428
461
|
usedBase = true;
|
|
429
462
|
}
|
|
430
463
|
else {
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
: '';
|
|
464
|
+
const fullStderr = attempt.stderr ? String(attempt.stderr) : '';
|
|
465
|
+
const reason = summarizeHermescStderr(fullStderr);
|
|
434
466
|
console.warn((0, i18n_1.t)('hermesBaseCompileFailed', {
|
|
435
|
-
reason:
|
|
467
|
+
reason: reason || `exit ${attempt.status}`,
|
|
436
468
|
}));
|
|
469
|
+
if (fullStderr.trim()) {
|
|
470
|
+
// the summary drops warning noise; keep everything for bug reports
|
|
471
|
+
const logPath = path_1.default.join(outputFolder, 'hermes-base-error.log');
|
|
472
|
+
try {
|
|
473
|
+
fs.writeFileSync(logPath, fullStderr);
|
|
474
|
+
console.warn((0, i18n_1.t)('hermesBaseCompileFailedLog', { file: logPath }));
|
|
475
|
+
}
|
|
476
|
+
catch { }
|
|
477
|
+
}
|
|
437
478
|
fs.copyFileSync(jsBackup, bundlePath);
|
|
438
479
|
}
|
|
439
480
|
}
|
package/lib/locales/en.d.ts
CHANGED
|
@@ -160,7 +160,10 @@ declare const _default: {
|
|
|
160
160
|
hermesBaseNone: string;
|
|
161
161
|
hermesBaseUsing: string;
|
|
162
162
|
hermesBaseDownloading: string;
|
|
163
|
+
hermesBaseRangeFetched: string;
|
|
164
|
+
hermesBaseRangeFallback: string;
|
|
163
165
|
hermesBaseCompileFailed: string;
|
|
166
|
+
hermesBaseCompileFailedLog: string;
|
|
164
167
|
hermesBaseVerified: string;
|
|
165
168
|
hermesBaseVerifyFailed: string;
|
|
166
169
|
cacheCleaned: string;
|
package/lib/locales/en.js
CHANGED
|
@@ -168,7 +168,10 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
168
168
|
hermesBaseNone: 'Hermes base: none ({{- reason}}); compiling without -base-bytecode',
|
|
169
169
|
hermesBaseUsing: 'Hermes base: {{- source}} (HBC v{{version}})',
|
|
170
170
|
hermesBaseDownloading: 'Hermes base: downloading {{- url}}',
|
|
171
|
+
hermesBaseRangeFetched: 'Hermes base: fetched only the bundle via HTTP Range ({{fetchedKb}} KB of {{totalKb}} KB)',
|
|
172
|
+
hermesBaseRangeFallback: 'Hermes base: partial download unavailable ({{- reason}}); downloading the whole package',
|
|
171
173
|
hermesBaseCompileFailed: 'Hermes base compile failed ({{- reason}}); retrying without -base-bytecode',
|
|
174
|
+
hermesBaseCompileFailedLog: 'Hermes base: full compiler output written to {{- file}}',
|
|
172
175
|
hermesBaseVerified: 'Hermes base: bytecode verified equivalent to a plain compile',
|
|
173
176
|
hermesBaseVerifyFailed: 'Hermes base: bytecode differs from a plain compile; dropping the base and recompiling',
|
|
174
177
|
cacheCleaned: 'Removed {{count}} cached bundle(s)',
|
package/lib/locales/zh.d.ts
CHANGED
|
@@ -159,7 +159,10 @@ declare const _default: {
|
|
|
159
159
|
hermesBaseNone: string;
|
|
160
160
|
hermesBaseUsing: string;
|
|
161
161
|
hermesBaseDownloading: string;
|
|
162
|
+
hermesBaseRangeFetched: string;
|
|
163
|
+
hermesBaseRangeFallback: string;
|
|
162
164
|
hermesBaseCompileFailed: string;
|
|
165
|
+
hermesBaseCompileFailedLog: string;
|
|
163
166
|
hermesBaseVerified: string;
|
|
164
167
|
hermesBaseVerifyFailed: string;
|
|
165
168
|
cacheCleaned: string;
|
package/lib/locales/zh.js
CHANGED
|
@@ -167,7 +167,10 @@ exports.default = {
|
|
|
167
167
|
hermesBaseNone: 'Hermes base:未使用({{- reason}}),按普通方式编译',
|
|
168
168
|
hermesBaseUsing: 'Hermes base:{{- source}}(HBC v{{version}})',
|
|
169
169
|
hermesBaseDownloading: 'Hermes base:下载 {{- url}}',
|
|
170
|
+
hermesBaseRangeFetched: 'Hermes base:已通过 HTTP Range 仅下载 bundle({{fetchedKb}} KB / 整包 {{totalKb}} KB)',
|
|
171
|
+
hermesBaseRangeFallback: 'Hermes base:无法按需下载({{- reason}}),改为下载整包',
|
|
170
172
|
hermesBaseCompileFailed: 'Hermes base 编译失败({{- reason}}),改为不带 -base-bytecode 重编',
|
|
173
|
+
hermesBaseCompileFailedLog: 'Hermes base:完整编译错误已写入 {{- file}}',
|
|
171
174
|
hermesBaseVerified: 'Hermes base:字节码与普通编译等价,校验通过',
|
|
172
175
|
hermesBaseVerifyFailed: 'Hermes base:字节码与普通编译不等价,放弃 base 重新编译',
|
|
173
176
|
cacheCleaned: '已清理 {{count}} 个缓存 bundle',
|
|
@@ -34,6 +34,9 @@ export declare function sha256Hex(data: Buffer): string;
|
|
|
34
34
|
/** Compile an empty file to learn which HBC version this hermesc emits. */
|
|
35
35
|
export declare function probeHbcVersion(hermesCommand: string): number | null;
|
|
36
36
|
export declare const BUNDLE_ENTRY_NAMES: string[];
|
|
37
|
+
export type BaseArtifactType = 'ppk' | 'apk' | 'ipa' | 'app';
|
|
38
|
+
/** Which zip entry holds the JS/HBC bundle in each kind of artifact. */
|
|
39
|
+
export declare function bundleEntryMatcher(artifactType: BaseArtifactType): (name: string) => boolean;
|
|
37
40
|
/**
|
|
38
41
|
* Extract the JS/HBC bundle from a local artifact: a raw bundle file, a ppk,
|
|
39
42
|
* or a native package (apk / ipa / harmony app). Returns null when not found.
|
|
@@ -67,11 +70,40 @@ export declare function downloadToFile(url: string, destination: string): Promis
|
|
|
67
70
|
export interface HermesBaseServerRecord {
|
|
68
71
|
versionId?: number | null;
|
|
69
72
|
hash: string;
|
|
70
|
-
artifactType?:
|
|
73
|
+
artifactType?: BaseArtifactType;
|
|
71
74
|
bundleHash?: string | null;
|
|
72
75
|
bytecodeVersion?: number | null;
|
|
73
76
|
url: string;
|
|
77
|
+
/**
|
|
78
|
+
* Location of the bundle's compressed bytes inside the ppk, reported by the
|
|
79
|
+
* publishing CLI; lets the base be fetched with a single HTTP Range request.
|
|
80
|
+
*/
|
|
81
|
+
bundleOffset?: number | null;
|
|
82
|
+
bundleCompressedSize?: number | null;
|
|
83
|
+
/** zip compression method: 0 stored, 8 deflate */
|
|
84
|
+
bundleCompression?: number | null;
|
|
85
|
+
}
|
|
86
|
+
interface FetchedBaseBundle {
|
|
87
|
+
bundle: Buffer;
|
|
88
|
+
/** how the bytes were obtained, for the log line */
|
|
89
|
+
transport: 'range-entry' | 'range-zip' | 'full';
|
|
90
|
+
fetchedBytes?: number;
|
|
91
|
+
totalBytes?: number;
|
|
74
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Obtain the base bundle with as little traffic as possible, in order:
|
|
95
|
+
* 1. one Range request for the bundle's compressed bytes when the server
|
|
96
|
+
* knows their location (ppk published by a CLI that reported it);
|
|
97
|
+
* 2. the archive's central directory over Range, then just the bundle
|
|
98
|
+
* entry (any zip: ppk, apk, ipa — harmony .app nests a second zip and
|
|
99
|
+
* is skipped);
|
|
100
|
+
* 3. the whole archive, as before.
|
|
101
|
+
* A server that ignores Range (HTTP 200) streams the full archive into
|
|
102
|
+
* `archive` without a second request. Range results are verified against
|
|
103
|
+
* `record.bundleHash` here; a mismatch (e.g. re-packaged object) falls
|
|
104
|
+
* through to the next transport instead of failing the resolution.
|
|
105
|
+
*/
|
|
106
|
+
export declare function fetchBaseBundle(record: HermesBaseServerRecord, artifactType: BaseArtifactType, archive: string, log?: (message: string) => void): Promise<FetchedBaseBundle | null>;
|
|
75
107
|
export interface ResolveHermesBaseParams {
|
|
76
108
|
option: HermesBaseOption;
|
|
77
109
|
hermesCommand: string;
|
|
@@ -108,3 +140,4 @@ export declare function normalizeDisassemblyLine(line: string, strings: Map<numb
|
|
|
108
140
|
* the disk. Resolves true when equivalent.
|
|
109
141
|
*/
|
|
110
142
|
export declare function verifyHermesBaseEquivalence(hermesCommand: string, withBase: string, plain: string): Promise<boolean>;
|
|
143
|
+
export {};
|
package/lib/utils/hermes-base.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUND
|
|
|
40
40
|
exports.classifyHermesCommand = classifyHermesCommand;
|
|
41
41
|
exports.sha256Hex = sha256Hex;
|
|
42
42
|
exports.probeHbcVersion = probeHbcVersion;
|
|
43
|
+
exports.bundleEntryMatcher = bundleEntryMatcher;
|
|
43
44
|
exports.extractBundleFromArchive = extractBundleFromArchive;
|
|
44
45
|
exports.cacheDir = cacheDir;
|
|
45
46
|
exports.tmpDir = tmpDir;
|
|
@@ -51,6 +52,7 @@ exports.cleanCache = cleanCache;
|
|
|
51
52
|
exports.cacheStats = cacheStats;
|
|
52
53
|
exports.cleanStaleTmp = cleanStaleTmp;
|
|
53
54
|
exports.downloadToFile = downloadToFile;
|
|
55
|
+
exports.fetchBaseBundle = fetchBaseBundle;
|
|
54
56
|
exports.resolveHermesBase = resolveHermesBase;
|
|
55
57
|
exports.hermescArgsWithBase = hermescArgsWithBase;
|
|
56
58
|
exports.hermesBaseMeta = hermesBaseMeta;
|
|
@@ -76,6 +78,7 @@ const constants_1 = require("./constants");
|
|
|
76
78
|
const hbcTransform_1 = require("./hbcTransform");
|
|
77
79
|
const i18n_1 = require("./i18n");
|
|
78
80
|
const zip_entries_1 = require("./zip-entries");
|
|
81
|
+
const zip_range_1 = require("./zip-range");
|
|
79
82
|
// ---------------------------------------------------------------------------
|
|
80
83
|
// hermesc gating
|
|
81
84
|
// ---------------------------------------------------------------------------
|
|
@@ -198,6 +201,17 @@ exports.BUNDLE_ENTRY_NAMES = [
|
|
|
198
201
|
];
|
|
199
202
|
const APK_BUNDLE = /^assets\/index\.android\.bundle$/;
|
|
200
203
|
const IPA_BUNDLE = /^payload\/[^/]+\.app\/main\.jsbundle$/i;
|
|
204
|
+
/** Which zip entry holds the JS/HBC bundle in each kind of artifact. */
|
|
205
|
+
function bundleEntryMatcher(artifactType) {
|
|
206
|
+
switch (artifactType) {
|
|
207
|
+
case 'apk':
|
|
208
|
+
return (name) => APK_BUNDLE.test(name);
|
|
209
|
+
case 'ipa':
|
|
210
|
+
return (name) => IPA_BUNDLE.test(name.toLowerCase());
|
|
211
|
+
default:
|
|
212
|
+
return (name) => exports.BUNDLE_ENTRY_NAMES.includes(name);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
201
215
|
/**
|
|
202
216
|
* Extract the JS/HBC bundle from a local artifact: a raw bundle file, a ppk,
|
|
203
217
|
* or a native package (apk / ipa / harmony app). Returns null when not found.
|
|
@@ -211,14 +225,8 @@ async function extractBundleFromArchive(filePath) {
|
|
|
211
225
|
ext === '.js') {
|
|
212
226
|
return fs_extra_1.default.readFile(filePath);
|
|
213
227
|
}
|
|
214
|
-
if (ext === '.ppk') {
|
|
215
|
-
return readFirstZipEntry(filePath, (
|
|
216
|
-
}
|
|
217
|
-
if (ext === '.apk') {
|
|
218
|
-
return readFirstZipEntry(filePath, (name) => APK_BUNDLE.test(name));
|
|
219
|
-
}
|
|
220
|
-
if (ext === '.ipa') {
|
|
221
|
-
return readFirstZipEntry(filePath, (name) => IPA_BUNDLE.test(name.toLowerCase()));
|
|
228
|
+
if (ext === '.ppk' || ext === '.apk' || ext === '.ipa') {
|
|
229
|
+
return readFirstZipEntry(filePath, bundleEntryMatcher(ext.slice(1)));
|
|
222
230
|
}
|
|
223
231
|
if (ext === '.app') {
|
|
224
232
|
// harmony .app wraps .hap archives; reuse the existing parser
|
|
@@ -372,6 +380,98 @@ async function downloadToFile(url, destination) {
|
|
|
372
380
|
const { Readable } = await Promise.resolve().then(() => __importStar(require('stream')));
|
|
373
381
|
await (0, promises_1.pipeline)(Readable.fromWeb(response.body), fs_extra_1.default.createWriteStream(destination));
|
|
374
382
|
}
|
|
383
|
+
function hasBundleLocation(record) {
|
|
384
|
+
return (record.bundleOffset != null &&
|
|
385
|
+
record.bundleCompressedSize != null &&
|
|
386
|
+
record.bundleCompression != null &&
|
|
387
|
+
(record.bundleCompression === zip_range_1.ZIP_STORED ||
|
|
388
|
+
record.bundleCompression === zip_range_1.ZIP_DEFLATED));
|
|
389
|
+
}
|
|
390
|
+
async function saveResponse(response, destination) {
|
|
391
|
+
if (!response.body)
|
|
392
|
+
throw new Error('empty response body');
|
|
393
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(destination));
|
|
394
|
+
const { Readable } = await Promise.resolve().then(() => __importStar(require('stream')));
|
|
395
|
+
await (0, promises_1.pipeline)(Readable.fromWeb(response.body), fs_extra_1.default.createWriteStream(destination));
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Obtain the base bundle with as little traffic as possible, in order:
|
|
399
|
+
* 1. one Range request for the bundle's compressed bytes when the server
|
|
400
|
+
* knows their location (ppk published by a CLI that reported it);
|
|
401
|
+
* 2. the archive's central directory over Range, then just the bundle
|
|
402
|
+
* entry (any zip: ppk, apk, ipa — harmony .app nests a second zip and
|
|
403
|
+
* is skipped);
|
|
404
|
+
* 3. the whole archive, as before.
|
|
405
|
+
* A server that ignores Range (HTTP 200) streams the full archive into
|
|
406
|
+
* `archive` without a second request. Range results are verified against
|
|
407
|
+
* `record.bundleHash` here; a mismatch (e.g. re-packaged object) falls
|
|
408
|
+
* through to the next transport instead of failing the resolution.
|
|
409
|
+
*/
|
|
410
|
+
async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
|
|
411
|
+
const matches = bundleEntryMatcher(artifactType);
|
|
412
|
+
const verified = (bundle) => {
|
|
413
|
+
if (!bundle)
|
|
414
|
+
throw new Error('bundle entry not found');
|
|
415
|
+
if (record.bundleHash && sha256Hex(bundle) !== record.bundleHash) {
|
|
416
|
+
throw new Error('bundleHash mismatch');
|
|
417
|
+
}
|
|
418
|
+
return bundle;
|
|
419
|
+
};
|
|
420
|
+
const fromFullResponse = async (response) => {
|
|
421
|
+
await saveResponse(response, archive);
|
|
422
|
+
const bundle = await extractBundleFromArchive(archive);
|
|
423
|
+
return bundle ? { bundle, transport: 'full' } : null;
|
|
424
|
+
};
|
|
425
|
+
const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
|
|
426
|
+
if (artifactType === 'ppk' && hasBundleLocation(record)) {
|
|
427
|
+
try {
|
|
428
|
+
const { data, fetchedBytes, totalBytes } = await (0, zip_range_1.fetchZipEntryData)(record.url, {
|
|
429
|
+
dataOffset: record.bundleOffset,
|
|
430
|
+
compressedSize: record.bundleCompressedSize,
|
|
431
|
+
compressionMethod: record.bundleCompression,
|
|
432
|
+
});
|
|
433
|
+
return {
|
|
434
|
+
bundle: verified(data),
|
|
435
|
+
transport: 'range-entry',
|
|
436
|
+
fetchedBytes,
|
|
437
|
+
totalBytes,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
if (error instanceof zip_range_1.RangeUnsupportedError) {
|
|
442
|
+
skip('server ignores Range');
|
|
443
|
+
return fromFullResponse(error.response);
|
|
444
|
+
}
|
|
445
|
+
skip(`entry range: ${error?.message ?? error}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (artifactType !== 'app') {
|
|
449
|
+
try {
|
|
450
|
+
const remote = await (0, zip_range_1.openRemoteZip)(record.url);
|
|
451
|
+
if (remote.kind === 'full') {
|
|
452
|
+
skip('server ignores Range');
|
|
453
|
+
return fromFullResponse(remote.response);
|
|
454
|
+
}
|
|
455
|
+
const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches);
|
|
456
|
+
return {
|
|
457
|
+
bundle: verified(bundle),
|
|
458
|
+
transport: 'range-zip',
|
|
459
|
+
fetchedBytes: remote.reader.fetchedBytes,
|
|
460
|
+
totalBytes: remote.reader.totalSize,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
if (error instanceof zip_range_1.RangeUnsupportedError) {
|
|
465
|
+
skip('server ignores Range');
|
|
466
|
+
return fromFullResponse(error.response);
|
|
467
|
+
}
|
|
468
|
+
skip(`zip range: ${error?.message ?? error}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
await downloadToFile(record.url, archive);
|
|
472
|
+
const bundle = await extractBundleFromArchive(archive);
|
|
473
|
+
return bundle ? { bundle, transport: 'full' } : null;
|
|
474
|
+
}
|
|
375
475
|
/**
|
|
376
476
|
* Pick and materialize the base bundle for this compile. Returns null (with
|
|
377
477
|
* the reason logged) whenever a base cannot be used; callers then compile
|
|
@@ -462,16 +562,27 @@ async function resolveHermesBase(params) {
|
|
|
462
562
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
463
563
|
const dir = tmpDir();
|
|
464
564
|
await fs_extra_1.default.ensureDir(dir);
|
|
465
|
-
const artifactType = [
|
|
565
|
+
const artifactType = [
|
|
566
|
+
'ppk',
|
|
567
|
+
'apk',
|
|
568
|
+
'ipa',
|
|
569
|
+
'app',
|
|
570
|
+
].includes(record.artifactType ?? '')
|
|
466
571
|
? record.artifactType
|
|
467
572
|
: 'ppk';
|
|
468
573
|
const archive = path_1.default.join(dir, `base-${process.pid}-${Date.now()}-${attempt}.${artifactType}`);
|
|
469
574
|
try {
|
|
470
575
|
log((0, i18n_1.t)('hermesBaseDownloading', { url: record.url }));
|
|
471
|
-
await
|
|
472
|
-
|
|
473
|
-
if (!bundle)
|
|
576
|
+
const fetched = await fetchBaseBundle(record, artifactType, archive, log);
|
|
577
|
+
if (!fetched)
|
|
474
578
|
throw new Error('bundle entry not found in downloaded package');
|
|
579
|
+
const { bundle } = fetched;
|
|
580
|
+
if (fetched.transport !== 'full') {
|
|
581
|
+
log((0, i18n_1.t)('hermesBaseRangeFetched', {
|
|
582
|
+
fetchedKb: Math.ceil((fetched.fetchedBytes ?? 0) / 1024),
|
|
583
|
+
totalKb: Math.ceil((fetched.totalBytes ?? 0) / 1024),
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
475
586
|
const actualHash = sha256Hex(bundle);
|
|
476
587
|
if (record.bundleHash && actualHash !== record.bundleHash) {
|
|
477
588
|
throw new Error(`bundleHash mismatch (${actualHash.slice(0, 12)} != ${record.bundleHash.slice(0, 12)})`);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { RandomAccessReader, type ZipFile } from 'yauzl';
|
|
3
|
+
export declare const ZIP_STORED = 0;
|
|
4
|
+
export declare const ZIP_DEFLATED = 8;
|
|
5
|
+
export interface ZipEntryLocation {
|
|
6
|
+
fileName: string;
|
|
7
|
+
/** absolute offset of the compressed data, past the local file header */
|
|
8
|
+
dataOffset: number;
|
|
9
|
+
compressedSize: number;
|
|
10
|
+
uncompressedSize: number;
|
|
11
|
+
/** 0 = stored, 8 = deflate; anything else cannot be inflated here */
|
|
12
|
+
compressionMethod: number;
|
|
13
|
+
}
|
|
14
|
+
/** Data location of the first entry matching `matches` in a local zip. */
|
|
15
|
+
export declare function locateZipEntry(zipPath: string, matches: (name: string) => boolean): Promise<ZipEntryLocation | null>;
|
|
16
|
+
/** The server answered a Range request with the whole body (HTTP 200). */
|
|
17
|
+
export declare class RangeUnsupportedError extends Error {
|
|
18
|
+
readonly response: Response;
|
|
19
|
+
constructor(response: Response);
|
|
20
|
+
}
|
|
21
|
+
interface ContentRange {
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
total: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function parseContentRange(header: string | null): ContentRange | null;
|
|
27
|
+
/**
|
|
28
|
+
* Fetch one entry whose compressed bytes are already located (the ppk's own
|
|
29
|
+
* publish-time report) and decompress it. Returns the raw entry content.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fetchZipEntryData(url: string, location: Pick<ZipEntryLocation, 'dataOffset' | 'compressedSize' | 'compressionMethod'>): Promise<{
|
|
32
|
+
data: Buffer;
|
|
33
|
+
fetchedBytes: number;
|
|
34
|
+
totalBytes: number;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* yauzl reader over HTTP Range. Header reads (EOCD, central directory, local
|
|
38
|
+
* file headers) are widened to CHUNK_BYTES and cached so a small archive costs
|
|
39
|
+
* one request; entry data streams straight from its own request.
|
|
40
|
+
*/
|
|
41
|
+
export declare class HttpRangeReader extends RandomAccessReader {
|
|
42
|
+
private readonly url;
|
|
43
|
+
readonly totalSize: number;
|
|
44
|
+
private readonly chunks;
|
|
45
|
+
requests: number;
|
|
46
|
+
fetchedBytes: number;
|
|
47
|
+
constructor(url: string, totalSize: number, tail?: {
|
|
48
|
+
start: number;
|
|
49
|
+
data: Buffer;
|
|
50
|
+
});
|
|
51
|
+
private cached;
|
|
52
|
+
_readStreamForRange(start: number, end: number): Readable;
|
|
53
|
+
read(buffer: Buffer, offset: number, length: number, position: number, callback: (err: Error | null, bytesRead?: number) => void): void;
|
|
54
|
+
}
|
|
55
|
+
export type RemoteZip = {
|
|
56
|
+
kind: 'zip';
|
|
57
|
+
zipFile: ZipFile;
|
|
58
|
+
reader: HttpRangeReader;
|
|
59
|
+
}
|
|
60
|
+
/** the server ignored Range: the whole archive is streaming in `response` */
|
|
61
|
+
| {
|
|
62
|
+
kind: 'full';
|
|
63
|
+
response: Response;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Open a remote zip by fetching its tail (EOCD + central directory for
|
|
67
|
+
* typical archives) and letting yauzl read the rest on demand.
|
|
68
|
+
*/
|
|
69
|
+
export declare function openRemoteZip(url: string): Promise<RemoteZip>;
|
|
70
|
+
/** Read the first matching entry of an opened remote zip, then close it. */
|
|
71
|
+
export declare function readRemoteZipEntry(zipFile: ZipFile, matches: (name: string) => boolean): Promise<Buffer | null>;
|
|
72
|
+
export {};
|