react-native-update-cli 2.22.5 → 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 CHANGED
@@ -70,7 +70,7 @@ const publishResult = await provider.publish({
70
70
 
71
71
  Hermes projects: `bundle` always runs hermesc with `-output-source-map`, so the debug info section is stripped from the bytecode (15–40% smaller, same as React Native's own release builds). The Hermes sourcemap stays in the intermediate directory (`.pushy/intermedia/<platform>/<bundle>.map`, never packed into the ppk); with `--sourcemap` it is composed with the packager map as before. Keep it if you want to symbolicate `address at` crash stacks later.
72
72
 
73
- Hermes delta mode (`-base-bytecode`): by default (`--hermesBase auto`) `bundle` compiles against the previous HBC of the same app, which keeps Hermes string IDs stable and makes hot-update patches 5–30× smaller. The base comes from the server (`GET /app/:id/hermesBase`), verified by sha256 and kept in a local cache (`.pushy/cache/<sha256>`, 500 MB / 20 files, `PUSHY_CACHE_DIR` / `--cacheMaxMb` to tune, `pushy cache [clean]` to inspect or clear). `--hermesBase none` disables it; `--hermesBase <file.hbc|.ppk|.apk|.ipa>` uses a local artifact (for example the store build). `--verifyHermesBase` (default on) additionally compiles without the base and compares both disassemblies; on any mismatch or failure the CLI silently falls back to the plain compile, so the feature can never block a release. Only hermesc builds that include the upstream delta-mode fix are used (classic `react-native/sdks/hermesc`, or `hermes-compiler` ≥ 250829098).
73
+ Hermes delta mode (`-base-bytecode`): by default (`--hermesBase auto`) `bundle` compiles against the previous HBC of the same app, which keeps Hermes string IDs stable and makes hot-update patches 5–30× smaller. The base comes from the server (`GET /app/:id/hermesBase`), verified by sha256 and kept in a local cache (`.pushy/cache/<sha256>`, 500 MB / 20 files, `PUSHY_CACHE_DIR` / `--cacheMaxMb` to tune, `pushy cache [clean]` to inspect or clear). `--hermesBase none` disables it; `--hermesBase <file.hbc|.ppk|.apk|.ipa>` uses a local artifact (for example the store build). `--verifyHermesBase` (default on) additionally compiles without the base (concurrently with the base compile) and compares both disassemblies; on any mismatch or failure the CLI silently falls back to the plain compile, so the feature can never block a release. Only hermesc builds that include the upstream delta-mode fix are used (classic `react-native/sdks/hermesc`, or `hermes-compiler` ≥ 250829098).
74
74
 
75
75
  ### Version
76
76
 
package/README.zh-CN.md CHANGED
@@ -70,7 +70,7 @@ const publishResult = await provider.publish({
70
70
 
71
71
  Hermes 工程:`bundle` 调用 hermesc 时始终带 `-output-source-map`,因此字节码不含 debug info 段(小 15%~40%,与 React Native 自身 release 构建一致)。Hermes sourcemap 保留在中间目录(`.pushy/intermedia/<platform>/<bundle>.map`,不会打进 ppk);传 `--sourcemap` 时照旧与 packager map 合成。留着它可以事后符号化 `address at` 形式的崩溃堆栈。
72
72
 
73
- Hermes delta 模式(`-base-bytecode`):默认 `--hermesBase auto`,`bundle` 会以同一应用上一版的 HBC 为 base 编译,让 Hermes 字符串 ID 跨版本稳定,热更 patch 可缩小 5~30 倍。base 由服务端(`GET /app/:id/hermesBase`)给出、按 sha256 校验并存入本地缓存(`.pushy/cache/<sha256>`,默认 500 MB / 20 个,可用 `PUSHY_CACHE_DIR` / `--cacheMaxMb` 调整,`pushy cache [clean]` 查看或清空)。`--hermesBase none` 关闭;`--hermesBase <file.hbc|.ppk|.apk|.ipa>` 指定本地文件(比如商店包)作 base。`--verifyHermesBase`(默认开)会再做一次普通编译并比对两份反汇编;任何不一致或失败都静默回退到普通编译,不会阻塞发版。只有包含上游 delta 模式修复的 hermesc 才会启用(经典 `react-native/sdks/hermesc`,或 `hermes-compiler` ≥ 250829098)。
73
+ Hermes delta 模式(`-base-bytecode`):默认 `--hermesBase auto`,`bundle` 会以同一应用上一版的 HBC 为 base 编译,让 Hermes 字符串 ID 跨版本稳定,热更 patch 可缩小 5~30 倍。base 由服务端(`GET /app/:id/hermesBase`)给出、按 sha256 校验并存入本地缓存(`.pushy/cache/<sha256>`,默认 500 MB / 20 个,可用 `PUSHY_CACHE_DIR` / `--cacheMaxMb` 调整,`pushy cache [clean]` 查看或清空)。`--hermesBase none` 关闭;`--hermesBase <file.hbc|.ppk|.apk|.ipa>` 指定本地文件(比如商店包)作 base。`--verifyHermesBase`(默认开)会并行再做一次普通编译并比对两份反汇编;任何不一致或失败都静默回退到普通编译,不会阻塞发版。只有包含上游 delta 模式修复的 hermesc 才会启用(经典 `react-native/sdks/hermesc`,或 `hermes-compiler` ≥ 250829098)。
74
74
 
75
75
  ### Version
76
76
 
@@ -30,6 +30,15 @@ export interface HermesCompileResult {
30
30
  /** true when --verifyHermesBase ran and passed; false when it failed (base dropped) */
31
31
  verified?: boolean;
32
32
  }
33
+ /** Outcome of picking a base: what to compile with, plus the log lines. */
34
+ export interface HermesBaseSelectionResult {
35
+ base: HermesBaseSelection | null;
36
+ bytecodeVersion: number | null;
37
+ /** messages to print when the compile phase starts (kept out of Metro's output) */
38
+ logs: string[];
39
+ /** hermesc could not be resolved; the compile phase will report it */
40
+ commandUnavailable?: boolean;
41
+ }
33
42
  type ResolvedExpoCli = {
34
43
  cliPath: string;
35
44
  usingExpo: boolean;
@@ -82,6 +91,23 @@ export declare function resolveHermesCommand(projectRoot?: string): string;
82
91
  */
83
92
  export declare function summarizeHermescStderr(stderr: string): string;
84
93
  export declare function buildHermescArgs(bundlePath: string): string[];
94
+ export interface CompileHermesOptions {
95
+ bundleName: string;
96
+ outputFolder: string;
97
+ sourcemapOutput: string;
98
+ shouldCleanSourcemap: boolean;
99
+ baseRequest?: HermesBaseRequest;
100
+ /** base selection started before Metro (see startHermesBaseSelection) */
101
+ pendingBase?: Promise<HermesBaseSelectionResult>;
102
+ /** defaults to the project's hermesc */
103
+ hermesCommand?: string;
104
+ }
105
+ export declare function compileHermesByteCode({ bundleName, outputFolder, sourcemapOutput, shouldCleanSourcemap, baseRequest, pendingBase, hermesCommand, }: CompileHermesOptions): Promise<HermesCompileResult>;
106
+ /**
107
+ * Begin resolving the base right away (before Metro); the compile phase awaits
108
+ * the result. Never rejects: any failure is reported there instead.
109
+ */
110
+ export declare function startHermesBaseSelection(request: HermesBaseRequest): Promise<HermesBaseSelectionResult>;
85
111
  export declare function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string): Promise<void>;
86
112
  export declare function prepareSentryUploadArtifacts(bundleName: string, outputFolder: string, platform: string): Promise<SentryUploadArtifacts>;
87
113
  export declare function readSourcemapDebugId(sourcemapPath: string): Promise<string | undefined>;
@@ -42,6 +42,8 @@ exports.runReactNativeBundleCommand = runReactNativeBundleCommand;
42
42
  exports.resolveHermesCommand = resolveHermesCommand;
43
43
  exports.summarizeHermescStderr = summarizeHermescStderr;
44
44
  exports.buildHermescArgs = buildHermescArgs;
45
+ exports.compileHermesByteCode = compileHermesByteCode;
46
+ exports.startHermesBaseSelection = startHermesBaseSelection;
45
47
  exports.copyDebugidForSentry = copyDebugidForSentry;
46
48
  exports.prepareSentryUploadArtifacts = prepareSentryUploadArtifacts;
47
49
  exports.readSourcemapDebugId = readSourcemapDebugId;
@@ -225,6 +227,12 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
225
227
  if (config) {
226
228
  reactNativeBundleArgs.push('--config', config);
227
229
  }
230
+ // Decide about Hermes before Metro runs so the base lookup (server query,
231
+ // Range download, cache) overlaps the bundling instead of following it.
232
+ const hermesEnabled = await detectHermesEnabled(platform, forceHermes, gradleConfig);
233
+ const pendingBase = hermesEnabled && hermesBase
234
+ ? startHermesBaseSelection(hermesBase)
235
+ : undefined;
228
236
  const jsRuntime = (0, runtime_1.getJavaScriptRuntime)();
229
237
  const reactNativeBundleProcess = (0, runtime_1.spawnJavaScript)(reactNativeBundleArgs);
230
238
  console.log(`Running bundle command: ${jsRuntime} ${reactNativeBundleArgs.join(' ')}`);
@@ -243,33 +251,15 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
243
251
  return;
244
252
  }
245
253
  try {
246
- let hermesEnabled = false;
247
- if (forceHermes) {
248
- hermesEnabled = true;
249
- console.log((0, i18n_1.t)('forceHermes'));
250
- }
251
- else if (platform === 'android') {
252
- const gradleProperties = await new Promise((resolve) => {
253
- properties.parse('./android/gradle.properties', { path: true }, (error, props = {}) => {
254
- if (error) {
255
- console.error(error);
256
- resolve({});
257
- return;
258
- }
259
- resolve(props);
260
- });
261
- });
262
- hermesEnabled = gradleProperties.hermesEnabled;
263
- if (typeof hermesEnabled !== 'boolean') {
264
- hermesEnabled = gradleConfig.enableHermes;
265
- }
266
- }
267
- else if (platform === 'ios' &&
268
- fs.existsSync('ios/Pods/hermes-engine')) {
269
- hermesEnabled = true;
270
- }
271
254
  if (hermesEnabled) {
272
- hermesResult = await compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, !isSentry, hermesBase);
255
+ hermesResult = await compileHermesByteCode({
256
+ bundleName,
257
+ outputFolder,
258
+ sourcemapOutput,
259
+ shouldCleanSourcemap: !isSentry,
260
+ baseRequest: hermesBase,
261
+ pendingBase,
262
+ });
273
263
  }
274
264
  if (platform === 'harmony') {
275
265
  const harmonyRawAssetsPath = 'harmony/entry/src/main/resources/rawfile/assets';
@@ -290,6 +280,32 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
290
280
  });
291
281
  return hermesResult;
292
282
  }
283
+ async function detectHermesEnabled(platform, forceHermes, gradleConfig) {
284
+ if (forceHermes) {
285
+ console.log((0, i18n_1.t)('forceHermes'));
286
+ return true;
287
+ }
288
+ if (platform === 'android') {
289
+ const gradleProperties = await new Promise((resolve) => {
290
+ properties.parse('./android/gradle.properties', { path: true }, (error, props = {}) => {
291
+ if (error) {
292
+ console.error(error);
293
+ resolve({});
294
+ return;
295
+ }
296
+ resolve(props);
297
+ });
298
+ });
299
+ if (typeof gradleProperties.hermesEnabled === 'boolean') {
300
+ return gradleProperties.hermesEnabled;
301
+ }
302
+ return Boolean(gradleConfig.enableHermes);
303
+ }
304
+ if (platform === 'ios' && fs.existsSync('ios/Pods/hermes-engine')) {
305
+ return true;
306
+ }
307
+ return false;
308
+ }
293
309
  function getHermesOSBin() {
294
310
  if (os_1.default.platform() === 'win32')
295
311
  return 'win64-bin';
@@ -431,9 +447,27 @@ function buildHermescArgs(bundlePath) {
431
447
  '-output-source-map',
432
448
  ];
433
449
  }
434
- async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, shouldCleanSourcemap, baseRequest) {
450
+ /** spawn without blocking the event loop, so two hermesc runs can overlap */
451
+ function runProcess(command, args, captureStderr) {
452
+ return new Promise((resolve) => {
453
+ const child = (0, child_process_1.spawn)(command, args, {
454
+ stdio: ['ignore', 'ignore', captureStderr ? 'pipe' : 'ignore'],
455
+ });
456
+ const chunks = [];
457
+ child.stderr?.on('data', (chunk) => chunks.push(chunk));
458
+ let settled = false;
459
+ const finish = (outcome) => {
460
+ if (settled)
461
+ return;
462
+ settled = true;
463
+ resolve(outcome);
464
+ };
465
+ child.once('error', (error) => finish({ status: null, signal: null, stderr: '', error }));
466
+ child.once('close', (status, signal) => finish({ status, signal, stderr: Buffer.concat(chunks).toString() }));
467
+ });
468
+ }
469
+ async function compileHermesByteCode({ bundleName, outputFolder, sourcemapOutput, shouldCleanSourcemap, baseRequest, pendingBase, hermesCommand = resolveHermesCommand(), }) {
435
470
  console.log((0, i18n_1.t)('hermesEnabledCompiling'));
436
- const hermesCommand = resolveHermesCommand();
437
471
  const bundlePath = path_1.default.join(outputFolder, bundleName);
438
472
  const plainArgs = buildHermescArgs(bundlePath);
439
473
  if (sourcemapOutput) {
@@ -442,26 +476,46 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
442
476
  else {
443
477
  console.log((0, i18n_1.t)('hermesSourcemapKept', { file: `${bundlePath}.map` }));
444
478
  }
445
- const result = { bytecodeVersion: null, base: null };
446
- const base = await selectHermesBase(hermesCommand, baseRequest, result);
447
- // hermesc reads its input in full before writing, so compiling in place is
448
- // safe; keep the JS bundle aside while a base compile may still fail or be
449
- // rejected by the equivalence check.
450
- const jsBackup = base ? `${bundlePath}.js.bak` : '';
451
- if (base)
452
- fs.copyFileSync(bundlePath, jsBackup);
453
- let usedBase = false;
479
+ let selection = pendingBase ? await pendingBase : null;
480
+ if (!selection || selection.commandUnavailable) {
481
+ selection = await selectHermesBase(hermesCommand, baseRequest);
482
+ }
483
+ for (const line of selection.logs)
484
+ console.log(line);
485
+ const result = {
486
+ bytecodeVersion: selection.bytecodeVersion,
487
+ base: null,
488
+ };
489
+ const base = selection.base;
454
490
  if (base) {
491
+ // hermesc reads its input in full before writing, so compiling in place is
492
+ // safe; keep the JS bundle aside while a base compile may still fail or be
493
+ // rejected by the equivalence check. With verification on, the plain
494
+ // compile the check needs runs concurrently in a sibling directory (same
495
+ // file name, so its sourcemap looks identical) and simply becomes the
496
+ // result when the base is rejected — no third compile.
497
+ const jsBackup = `${bundlePath}.js.bak`;
498
+ fs.copyFileSync(bundlePath, jsBackup);
499
+ const plainDir = path_1.default.join(outputFolder, '.hermes-plain');
500
+ const plainPath = path_1.default.join(plainDir, bundleName);
501
+ const wantPlain = Boolean(baseRequest?.verify);
502
+ if (wantPlain) {
503
+ fs.ensureDirSync(plainDir);
504
+ fs.copyFileSync(bundlePath, plainPath);
505
+ }
455
506
  const args = (0, hermes_base_1.hermescArgsWithBase)(plainArgs, base.path);
456
507
  console.log((0, i18n_1.t)('runningHermesc', { command: hermesCommand, args: args.join(' ') }));
457
- const attempt = (0, child_process_1.spawnSync)(hermesCommand, args, {
458
- stdio: ['ignore', 'ignore', 'pipe'],
459
- });
460
- if (attempt.status === 0) {
461
- usedBase = true;
462
- }
463
- else {
464
- const fullStderr = attempt.stderr ? String(attempt.stderr) : '';
508
+ const [attempt, plain] = await Promise.all([
509
+ runProcess(hermesCommand, args, true),
510
+ wantPlain
511
+ ? runProcess(hermesCommand, buildHermescArgs(plainPath), false)
512
+ : Promise.resolve(null),
513
+ ]);
514
+ let usedBase = attempt.status === 0 && !attempt.error;
515
+ if (!usedBase) {
516
+ const fullStderr = attempt.error
517
+ ? String(attempt.error.message ?? attempt.error)
518
+ : attempt.stderr;
465
519
  const reason = summarizeHermescStderr(fullStderr);
466
520
  console.warn((0, i18n_1.t)('hermesBaseCompileFailed', {
467
521
  reason: reason || `exit ${attempt.status}`,
@@ -475,40 +529,51 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
475
529
  }
476
530
  catch { }
477
531
  }
478
- fs.copyFileSync(jsBackup, bundlePath);
479
532
  }
480
- }
481
- if (usedBase && baseRequest?.verify) {
482
- // plain compile next to it, compare disassembly, keep whichever is right
483
- const plainOut = `${bundlePath}.plain.hbc`;
484
- const plain = (0, child_process_1.spawnSync)(hermesCommand,
485
- // same flags as the real compile (only the base differs), otherwise
486
- // debug-info settings would make the two dumps legitimately differ
487
- ['-emit-binary', '-out', plainOut, jsBackup, '-O', '-output-source-map'], { stdio: 'ignore' });
488
- let ok = plain.status === 0;
489
- if (ok) {
490
- try {
491
- ok = await (0, hermes_base_1.verifyHermesBaseEquivalence)(hermesCommand, bundlePath, plainOut);
533
+ const plainOk = plain !== null && plain.status === 0 && !plain.error;
534
+ if (usedBase && wantPlain) {
535
+ // compare disassembly, keep whichever is right
536
+ let ok = plainOk;
537
+ if (ok) {
538
+ try {
539
+ ok = await (0, hermes_base_1.verifyHermesBaseEquivalence)(hermesCommand, bundlePath, plainPath);
540
+ }
541
+ catch {
542
+ ok = false;
543
+ }
492
544
  }
493
- catch {
494
- ok = false;
545
+ result.verified = ok;
546
+ if (ok) {
547
+ console.log((0, i18n_1.t)('hermesBaseVerified'));
548
+ }
549
+ else {
550
+ console.warn((0, i18n_1.t)('hermesBaseVerifyFailed'));
551
+ usedBase = false;
495
552
  }
496
553
  }
497
- fs.removeSync(plainOut);
498
- fs.removeSync(`${plainOut}.map`);
499
- result.verified = ok;
500
- if (ok) {
501
- console.log((0, i18n_1.t)('hermesBaseVerified'));
502
- }
503
- else {
504
- console.warn((0, i18n_1.t)('hermesBaseVerifyFailed'));
505
- fs.copyFileSync(jsBackup, bundlePath);
506
- usedBase = false;
554
+ if (!usedBase) {
555
+ if (plainOk) {
556
+ fs.moveSync(plainPath, bundlePath, { overwrite: true });
557
+ if (fs.existsSync(`${plainPath}.map`)) {
558
+ fs.moveSync(`${plainPath}.map`, `${bundlePath}.map`, {
559
+ overwrite: true,
560
+ });
561
+ }
562
+ }
563
+ else {
564
+ fs.copyFileSync(jsBackup, bundlePath);
565
+ console.log((0, i18n_1.t)('runningHermesc', {
566
+ command: hermesCommand,
567
+ args: plainArgs.join(' '),
568
+ }));
569
+ assertSuccessfulSyncProcess((0, child_process_1.spawnSync)(hermesCommand, plainArgs, { stdio: 'ignore' }), hermesCommand);
570
+ }
507
571
  }
508
- }
509
- if (jsBackup)
510
572
  fs.removeSync(jsBackup);
511
- if (!usedBase) {
573
+ fs.removeSync(plainDir);
574
+ result.base = usedBase ? base : null;
575
+ }
576
+ else {
512
577
  console.log((0, i18n_1.t)('runningHermesc', {
513
578
  command: hermesCommand,
514
579
  args: plainArgs.join(' '),
@@ -516,10 +581,6 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
516
581
  assertSuccessfulSyncProcess((0, child_process_1.spawnSync)(hermesCommand, plainArgs, {
517
582
  stdio: 'ignore',
518
583
  }), hermesCommand);
519
- result.base = null;
520
- }
521
- else {
522
- result.base = base;
523
584
  }
524
585
  if (sourcemapOutput) {
525
586
  let composerPath;
@@ -547,38 +608,76 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
547
608
  }
548
609
  return result;
549
610
  }
550
- async function selectHermesBase(hermesCommand, request, result) {
611
+ /**
612
+ * Begin resolving the base right away (before Metro); the compile phase awaits
613
+ * the result. Never rejects: any failure is reported there instead.
614
+ */
615
+ function startHermesBaseSelection(request) {
616
+ return (async () => {
617
+ let hermesCommand;
618
+ try {
619
+ hermesCommand = resolveHermesCommand();
620
+ }
621
+ catch {
622
+ return {
623
+ base: null,
624
+ bytecodeVersion: null,
625
+ logs: [],
626
+ commandUnavailable: true,
627
+ };
628
+ }
629
+ try {
630
+ return await selectHermesBase(hermesCommand, request);
631
+ }
632
+ catch (error) {
633
+ return {
634
+ base: null,
635
+ bytecodeVersion: null,
636
+ logs: [
637
+ (0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }),
638
+ ],
639
+ };
640
+ }
641
+ })();
642
+ }
643
+ async function selectHermesBase(hermesCommand, request) {
644
+ const logs = [];
645
+ const none = (bytecodeVersion = null) => ({
646
+ base: null,
647
+ bytecodeVersion,
648
+ logs,
649
+ });
551
650
  if (!request || request.option === 'none') {
552
651
  if (request) {
553
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: 'disabled by option' }));
652
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: 'disabled by option' }));
554
653
  }
555
- return null;
654
+ return none();
556
655
  }
557
656
  const gate = (0, hermes_base_1.classifyHermesCommand)(hermesCommand);
558
657
  if (!gate.allowed) {
559
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }));
560
- return null;
658
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }));
659
+ return none();
561
660
  }
562
661
  const bytecodeVersion = (0, hermes_base_1.probeHbcVersion)(hermesCommand);
563
- result.bytecodeVersion = bytecodeVersion;
564
662
  if (bytecodeVersion === null) {
565
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: 'could not probe HBC version' }));
566
- return null;
663
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: 'could not probe HBC version' }));
664
+ return none();
567
665
  }
568
666
  try {
569
- return await (0, hermes_base_1.resolveHermesBase)({
667
+ const base = await (0, hermes_base_1.resolveHermesBase)({
570
668
  option: request.option,
571
669
  hermesCommand,
572
670
  bytecodeVersion,
573
671
  appId: request.appId,
574
672
  cacheMaxMb: request.cacheMaxMb,
575
673
  fetchBase: api_1.getHermesBase,
576
- log: (message) => console.log(message),
674
+ log: (message) => logs.push(message),
577
675
  });
676
+ return { base, bytecodeVersion, logs };
578
677
  }
579
678
  catch (error) {
580
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }));
581
- return null;
679
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }));
680
+ return none(bytecodeVersion);
582
681
  }
583
682
  }
584
683
  async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
@@ -160,6 +160,8 @@ 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;
164
166
  hermesBaseCompileFailedLog: string;
165
167
  hermesBaseVerified: string;
package/lib/locales/en.js CHANGED
@@ -168,6 +168,8 @@ 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',
172
174
  hermesBaseCompileFailedLog: 'Hermes base: full compiler output written to {{- file}}',
173
175
  hermesBaseVerified: 'Hermes base: bytecode verified equivalent to a plain compile',
@@ -159,6 +159,8 @@ 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;
163
165
  hermesBaseCompileFailedLog: string;
164
166
  hermesBaseVerified: string;
package/lib/locales/zh.js CHANGED
@@ -167,6 +167,8 @@ 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 重编',
171
173
  hermesBaseCompileFailedLog: 'Hermes base:完整编译错误已写入 {{- file}}',
172
174
  hermesBaseVerified: 'Hermes base:字节码与普通编译等价,校验通过',
package/lib/package.js CHANGED
@@ -54,6 +54,7 @@ const git_1 = require("./utils/git");
54
54
  const hermes_base_1 = require("./utils/hermes-base");
55
55
  const i18n_1 = require("./utils/i18n");
56
56
  const options_1 = require("./utils/options");
57
+ const zip_range_1 = require("./utils/zip-range");
57
58
  function normalizeUploadBuildTime(value) {
58
59
  return String(value);
59
60
  }
@@ -122,6 +123,13 @@ async function uploadNativePackage(filePath, options, config) {
122
123
  try {
123
124
  await (0, native_package_1.createSlimNativePackage)(filePath, slimPackagePath, config.platform);
124
125
  const { hash } = await (0, api_1.uploadFile)(slimPackagePath, undefined, appId);
126
+ // where the bundle sits inside the uploaded (slim) archive, so a later
127
+ // `bundle` that falls back to this package as hermes base fetches only
128
+ // the bundle with one HTTP Range request. Harmony .app nests a second
129
+ // zip, so no location is reported for it.
130
+ const bundleLocation = config.extension === '.app'
131
+ ? {}
132
+ : (0, zip_range_1.bundleLocationFields)(await (0, zip_range_1.locateZipEntry)(slimPackagePath, (0, hermes_base_1.bundleEntryMatcher)(config.extension.slice(1))).catch(() => null));
125
133
  if (bundleFile) {
126
134
  // keep the embedded bundle locally so a later `bundle` can use it as
127
135
  // hermes base without downloading it back (see hermes-base.ts)
@@ -139,6 +147,7 @@ async function uploadNativePackage(filePath, options, config) {
139
147
  // against the client-reported bundleHash to decide pdiff applicability.
140
148
  // Old servers strip unknown fields, so this is forward-compatible.
141
149
  ...(bundleHash ? { bundleHash } : {}),
150
+ ...bundleLocation,
142
151
  deps: dep_versions_1.depVersions,
143
152
  commit: await (0, git_1.getCommitInfo)(),
144
153
  });
@@ -31,9 +31,16 @@ export declare function classifyHermesCommand(hermesCommand: string): {
31
31
  reason?: string;
32
32
  };
33
33
  export declare function sha256Hex(data: Buffer): string;
34
- /** Compile an empty file to learn which HBC version this hermesc emits. */
34
+ /**
35
+ * Which HBC version this hermesc emits. The answer is remembered per binary
36
+ * (path, size, mtime) in the cache dir so only the first run of a given
37
+ * hermesc pays for the empty-file compile.
38
+ */
35
39
  export declare function probeHbcVersion(hermesCommand: string): number | null;
36
40
  export declare const BUNDLE_ENTRY_NAMES: string[];
41
+ export type BaseArtifactType = 'ppk' | 'apk' | 'ipa' | 'app';
42
+ /** Which zip entry holds the JS/HBC bundle in each kind of artifact. */
43
+ export declare function bundleEntryMatcher(artifactType: BaseArtifactType): (name: string) => boolean;
37
44
  /**
38
45
  * Extract the JS/HBC bundle from a local artifact: a raw bundle file, a ppk,
39
46
  * or a native package (apk / ipa / harmony app). Returns null when not found.
@@ -50,7 +57,7 @@ export declare function cacheLimits(overrideMaxMb?: number): {
50
57
  /** Returns the cached bundle path when present and its sha256 still matches. */
51
58
  export declare function cacheLookup(bundleHash: string): Promise<string | null>;
52
59
  /** Store a bundle under its sha256 (LRU-evicting to the configured limits). */
53
- export declare function cachePut(bundle: Buffer, maxMb?: number): Promise<{
60
+ export declare function cachePut(bundle: Buffer, maxMb?: number, knownHash?: string): Promise<{
54
61
  path: string;
55
62
  bundleHash: string;
56
63
  }>;
@@ -67,11 +74,43 @@ export declare function downloadToFile(url: string, destination: string): Promis
67
74
  export interface HermesBaseServerRecord {
68
75
  versionId?: number | null;
69
76
  hash: string;
70
- artifactType?: 'ppk' | 'apk' | 'ipa' | 'app';
77
+ artifactType?: BaseArtifactType;
71
78
  bundleHash?: string | null;
72
79
  bytecodeVersion?: number | null;
73
80
  url: string;
81
+ /**
82
+ * Location of the bundle's compressed bytes inside the ppk, reported by the
83
+ * publishing CLI; lets the base be fetched with a single HTTP Range request.
84
+ */
85
+ bundleOffset?: number | null;
86
+ bundleCompressedSize?: number | null;
87
+ /** zip compression method: 0 stored, 8 deflate */
88
+ bundleCompression?: number | null;
74
89
  }
90
+ interface FetchedBaseBundle {
91
+ bundle: Buffer;
92
+ /** sha256 of `bundle`, computed once here */
93
+ bundleHash: string;
94
+ /** how the bytes were obtained, for the log line */
95
+ transport: 'range-entry' | 'range-zip' | 'full';
96
+ fetchedBytes?: number;
97
+ totalBytes?: number;
98
+ }
99
+ /**
100
+ * Obtain the base bundle with as little traffic as possible, in order:
101
+ * 1. one Range request for the bundle's compressed bytes when the server
102
+ * knows their location (ppk / apk / ipa published by a CLI that
103
+ * reported it);
104
+ * 2. the archive's central directory over Range, then just the bundle
105
+ * entry (any zip: ppk, apk, ipa — harmony .app nests a second zip and
106
+ * is skipped);
107
+ * 3. the whole archive, as before.
108
+ * A server that ignores Range (HTTP 200) streams the full archive into
109
+ * `archive` without a second request. Range results are verified against
110
+ * `record.bundleHash` here; a mismatch (e.g. re-packaged object) falls
111
+ * through to the next transport instead of failing the resolution.
112
+ */
113
+ export declare function fetchBaseBundle(record: HermesBaseServerRecord, artifactType: BaseArtifactType, archive: string, log?: (message: string) => void): Promise<FetchedBaseBundle | null>;
75
114
  export interface ResolveHermesBaseParams {
76
115
  option: HermesBaseOption;
77
116
  hermesCommand: string;
@@ -108,3 +147,4 @@ export declare function normalizeDisassemblyLine(line: string, strings: Map<numb
108
147
  * the disk. Resolves true when equivalent.
109
148
  */
110
149
  export declare function verifyHermesBaseEquivalence(hermesCommand: string, withBase: string, plain: string): Promise<boolean>;
150
+ export {};