react-native-update-cli 2.22.6 → 2.22.8

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.
Files changed (59) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/cli.json +5 -0
  4. package/lib/api.d.ts +7 -0
  5. package/lib/api.js +106 -38
  6. package/lib/app.js +3 -2
  7. package/lib/bin.js +16 -2
  8. package/lib/bundle-runner.d.ts +35 -2
  9. package/lib/bundle-runner.js +313 -128
  10. package/lib/bundle.d.ts +1 -0
  11. package/lib/bundle.js +2 -0
  12. package/lib/diff.d.ts +9 -0
  13. package/lib/diff.js +162 -120
  14. package/lib/locales/en.d.ts +1 -0
  15. package/lib/locales/en.js +1 -0
  16. package/lib/locales/zh.d.ts +1 -0
  17. package/lib/locales/zh.js +1 -0
  18. package/lib/package.d.ts +7 -3
  19. package/lib/package.js +31 -12
  20. package/lib/types.d.ts +2 -0
  21. package/lib/utils/dep-versions.d.ts +7 -0
  22. package/lib/utils/dep-versions.js +66 -31
  23. package/lib/utils/hbcTransform.d.ts +21 -0
  24. package/lib/utils/hbcTransform.js +146 -5
  25. package/lib/utils/hermes-base.d.ts +31 -7
  26. package/lib/utils/hermes-base.js +284 -76
  27. package/lib/utils/http-helper.d.ts +6 -1
  28. package/lib/utils/http-helper.js +23 -11
  29. package/lib/utils/index.d.ts +30 -1
  30. package/lib/utils/index.js +98 -24
  31. package/lib/utils/latest-version/index.d.ts +11 -8
  32. package/lib/utils/latest-version/index.js +63 -18
  33. package/lib/utils/zip-entries.js +20 -15
  34. package/lib/utils/zip-options.d.ts +2 -0
  35. package/lib/utils/zip-options.js +9 -4
  36. package/lib/utils/zip-range.d.ts +84 -13
  37. package/lib/utils/zip-range.js +363 -63
  38. package/lib/versions.js +30 -23
  39. package/package.json +11 -11
  40. package/src/api.ts +126 -46
  41. package/src/app.ts +3 -2
  42. package/src/bin.ts +17 -2
  43. package/src/bundle-runner.ts +419 -171
  44. package/src/bundle.ts +3 -0
  45. package/src/diff.ts +210 -153
  46. package/src/locales/en.ts +2 -0
  47. package/src/locales/zh.ts +2 -0
  48. package/src/package.ts +42 -14
  49. package/src/types.ts +2 -0
  50. package/src/utils/dep-versions.ts +76 -33
  51. package/src/utils/hbcTransform.ts +194 -5
  52. package/src/utils/hermes-base.ts +311 -81
  53. package/src/utils/http-helper.ts +24 -13
  54. package/src/utils/index.ts +136 -26
  55. package/src/utils/latest-version/index.ts +82 -29
  56. package/src/utils/zip-entries.ts +18 -16
  57. package/src/utils/zip-options.ts +8 -3
  58. package/src/utils/zip-range.ts +436 -67
  59. package/src/versions.ts +34 -26
@@ -42,6 +42,9 @@ exports.runReactNativeBundleCommand = runReactNativeBundleCommand;
42
42
  exports.resolveHermesCommand = resolveHermesCommand;
43
43
  exports.summarizeHermescStderr = summarizeHermescStderr;
44
44
  exports.buildHermescArgs = buildHermescArgs;
45
+ exports.compileHermesByteCode = compileHermesByteCode;
46
+ exports.hermesBaseErrorLogPath = hermesBaseErrorLogPath;
47
+ exports.startHermesBaseSelection = startHermesBaseSelection;
45
48
  exports.copyDebugidForSentry = copyDebugidForSentry;
46
49
  exports.prepareSentryUploadArtifacts = prepareSentryUploadArtifacts;
47
50
  exports.readSourcemapDebugId = readSourcemapDebugId;
@@ -123,7 +126,7 @@ function resolveExpoCli(projectRoot = process.cwd()) {
123
126
  };
124
127
  }
125
128
  }
126
- async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, hermesBase, cli, isSentry, }) {
129
+ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, hermesBase, resetCache = true, cli, isSentry, }) {
127
130
  let gradleConfig = {};
128
131
  if (platform === 'android') {
129
132
  gradleConfig = await checkGradleConfig();
@@ -211,7 +214,9 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
211
214
  }
212
215
  reactNativeBundleArgs.push(cliPath, bundleCommand, '--assets-dest', outputFolder, '--bundle-output', path_1.default.join(outputFolder, bundleName));
213
216
  if (platform !== 'harmony') {
214
- reactNativeBundleArgs.push('--platform', platform, '--reset-cache');
217
+ reactNativeBundleArgs.push('--platform', platform);
218
+ if (resetCache)
219
+ reactNativeBundleArgs.push('--reset-cache');
215
220
  }
216
221
  if (cli.taro) {
217
222
  reactNativeBundleArgs.push('--type', 'rn');
@@ -225,9 +230,17 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
225
230
  if (config) {
226
231
  reactNativeBundleArgs.push('--config', config);
227
232
  }
233
+ // Decide about Hermes before Metro runs so the base lookup (server query,
234
+ // Range download, cache) overlaps the bundling instead of following it.
235
+ const hermesEnabled = await detectHermesEnabled(platform, forceHermes, gradleConfig);
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(' ')}`);
239
+ // Metro is running; the synchronous head of the selection (hermesc lookup,
240
+ // HBC version probe) now overlaps it instead of delaying its start.
241
+ const pendingBase = hermesEnabled && hermesBase
242
+ ? startHermesBaseSelection(hermesBase)
243
+ : undefined;
231
244
  let hermesResult = null;
232
245
  await new Promise((resolve, reject) => {
233
246
  reactNativeBundleProcess.stdout.on('data', (data) => {
@@ -243,33 +256,15 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
243
256
  return;
244
257
  }
245
258
  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
259
  if (hermesEnabled) {
272
- hermesResult = await compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, !isSentry, hermesBase);
260
+ hermesResult = await compileHermesByteCode({
261
+ bundleName,
262
+ outputFolder,
263
+ sourcemapOutput,
264
+ shouldCleanSourcemap: !isSentry,
265
+ baseRequest: hermesBase,
266
+ pendingBase,
267
+ });
273
268
  }
274
269
  if (platform === 'harmony') {
275
270
  const harmonyRawAssetsPath = 'harmony/entry/src/main/resources/rawfile/assets';
@@ -290,6 +285,32 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
290
285
  });
291
286
  return hermesResult;
292
287
  }
288
+ async function detectHermesEnabled(platform, forceHermes, gradleConfig) {
289
+ if (forceHermes) {
290
+ console.log((0, i18n_1.t)('forceHermes'));
291
+ return true;
292
+ }
293
+ if (platform === 'android') {
294
+ const gradleProperties = await new Promise((resolve) => {
295
+ properties.parse('./android/gradle.properties', { path: true }, (error, props = {}) => {
296
+ if (error) {
297
+ console.error(error);
298
+ resolve({});
299
+ return;
300
+ }
301
+ resolve(props);
302
+ });
303
+ });
304
+ if (typeof gradleProperties.hermesEnabled === 'boolean') {
305
+ return gradleProperties.hermesEnabled;
306
+ }
307
+ return Boolean(gradleConfig.enableHermes);
308
+ }
309
+ if (platform === 'ios' && fs.existsSync('ios/Pods/hermes-engine')) {
310
+ return true;
311
+ }
312
+ return false;
313
+ }
293
314
  function getHermesOSBin() {
294
315
  if (os_1.default.platform() === 'win32')
295
316
  return 'win64-bin';
@@ -421,164 +442,328 @@ function summarizeHermescStderr(stderr) {
421
442
  const notWarnings = kept.filter((line) => !/:\s*(?:warning|note):/i.test(line));
422
443
  return (notWarnings.length > 0 ? notWarnings : kept).slice(-3).join(' ');
423
444
  }
424
- function buildHermescArgs(bundlePath) {
445
+ /** hermesc arguments writing `bundlePath` from `input` (in place by default) */
446
+ function buildHermescArgs(bundlePath, input = bundlePath) {
425
447
  return [
426
448
  '-emit-binary',
427
449
  '-out',
428
450
  bundlePath,
429
- bundlePath,
451
+ input,
430
452
  '-O',
431
453
  '-output-source-map',
432
454
  ];
433
455
  }
434
- async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, shouldCleanSourcemap, baseRequest) {
456
+ /** captured stderr is bounded to this much head and this much tail */
457
+ const STDERR_KEEP_BYTES = 512 * 1024;
458
+ /** spawn without blocking the event loop, so two hermesc runs can overlap */
459
+ function runProcess(command, args, captureStderr) {
460
+ return new Promise((resolve) => {
461
+ const child = (0, child_process_1.spawn)(command, args, {
462
+ stdio: ['ignore', 'ignore', captureStderr ? 'pipe' : 'ignore'],
463
+ });
464
+ // hermesc echoes whole (minified) source lines per diagnostic: keep the
465
+ // head and the tail, never an unbounded transcript
466
+ const head = [];
467
+ const tail = [];
468
+ let headBytes = 0;
469
+ let tailBytes = 0;
470
+ let dropped = false;
471
+ child.stderr?.on('data', (chunk) => {
472
+ if (headBytes < STDERR_KEEP_BYTES) {
473
+ head.push(chunk);
474
+ headBytes += chunk.length;
475
+ return;
476
+ }
477
+ tail.push(chunk);
478
+ tailBytes += chunk.length;
479
+ while (tail.length > 1 && tailBytes > STDERR_KEEP_BYTES) {
480
+ tailBytes -= tail.shift().length;
481
+ dropped = true;
482
+ }
483
+ });
484
+ let settled = false;
485
+ const finish = (outcome) => {
486
+ if (settled)
487
+ return;
488
+ settled = true;
489
+ resolve(outcome);
490
+ };
491
+ child.once('error', (error) => finish({ status: null, signal: null, stderr: '', error }));
492
+ child.once('close', (status, signal) => finish({
493
+ status,
494
+ signal,
495
+ stderr: Buffer.concat(head).toString() +
496
+ (dropped ? '\n[... output truncated ...]\n' : '') +
497
+ Buffer.concat(tail).toString(),
498
+ }));
499
+ });
500
+ }
501
+ /** how long the compile phase waits for a base that is still being fetched */
502
+ const HERMES_BASE_WAIT_MS = 60_000;
503
+ /**
504
+ * The selection runs while Metro bundles; when Metro is done first, wait a
505
+ * bounded time for it — a stalled download must never hold up the compile.
506
+ */
507
+ async function awaitPendingBase(pending) {
508
+ const waitMs = Number(process.env.PUSHY_HERMES_BASE_WAIT_MS) || HERMES_BASE_WAIT_MS;
509
+ let timer;
510
+ const gaveUp = new Promise((resolve) => {
511
+ timer = setTimeout(() => resolve({
512
+ base: null,
513
+ bytecodeVersion: null,
514
+ logs: [
515
+ (0, i18n_1.t)('hermesBaseNone', {
516
+ reason: `base not ready after ${Math.round(waitMs / 1000)}s`,
517
+ }),
518
+ ],
519
+ }), waitMs);
520
+ });
521
+ try {
522
+ return await Promise.race([pending, gaveUp]);
523
+ }
524
+ finally {
525
+ clearTimeout(timer);
526
+ }
527
+ }
528
+ /** plain compile of `input` into `out`; throws when hermesc fails */
529
+ async function compilePlain(hermesCommand, out, input = out) {
530
+ const args = buildHermescArgs(out, input);
531
+ console.log((0, i18n_1.t)('runningHermesc', { command: hermesCommand, args: args.join(' ') }));
532
+ assertSuccessfulSyncProcess(await runProcess(hermesCommand, args, false), hermesCommand);
533
+ }
534
+ /**
535
+ * Merge the packager map with the hermes map into `sourcemapOutput` (which is
536
+ * normally the hermes map's own path). Resolves false when React Native's
537
+ * composer cannot be found; throws when it fails.
538
+ */
539
+ async function composeSourceMaps(packagerMap, hermesMap, sourcemapOutput) {
540
+ let composerPath;
541
+ try {
542
+ // resolve through the project so hoisted node_modules (monorepos) work
543
+ composerPath = require.resolve('react-native/scripts/compose-source-maps.js', { paths: [process.cwd()] });
544
+ }
545
+ catch {
546
+ console.warn((0, i18n_1.t)('composeSourceMapsNotFound'));
547
+ return false;
548
+ }
549
+ console.log((0, i18n_1.t)('composingSourceMap'));
550
+ assertSuccessfulSyncProcess(await runProcess((0, runtime_1.getJavaScriptRuntime)(), [composerPath, packagerMap, hermesMap, '-o', sourcemapOutput], false), composerPath);
551
+ return true;
552
+ }
553
+ async function compileHermesByteCode({ bundleName, outputFolder, sourcemapOutput, shouldCleanSourcemap, baseRequest, pendingBase, hermesCommand = resolveHermesCommand(), }) {
435
554
  console.log((0, i18n_1.t)('hermesEnabledCompiling'));
436
- const hermesCommand = resolveHermesCommand();
437
555
  const bundlePath = path_1.default.join(outputFolder, bundleName);
438
- const plainArgs = buildHermescArgs(bundlePath);
556
+ const hermesMap = `${bundlePath}.map`;
557
+ const packagerMap = path_1.default.join(outputFolder, `${bundleName}.txt.map`);
439
558
  if (sourcemapOutput) {
440
- fs.copyFileSync(sourcemapOutput, path_1.default.join(outputFolder, `${bundleName}.txt.map`));
441
- }
442
- else {
443
- console.log((0, i18n_1.t)('hermesSourcemapKept', { file: `${bundlePath}.map` }));
444
- }
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;
454
- if (base) {
455
- const args = (0, hermes_base_1.hermescArgsWithBase)(plainArgs, base.path);
456
- 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;
559
+ // hermesc is about to write its own map at `<bundle>.map`, which is where
560
+ // the packager map normally sits: move it aside (copy only when elsewhere)
561
+ if (path_1.default.resolve(sourcemapOutput) === path_1.default.resolve(hermesMap)) {
562
+ fs.renameSync(sourcemapOutput, packagerMap);
462
563
  }
463
564
  else {
464
- const fullStderr = attempt.stderr ? String(attempt.stderr) : '';
565
+ fs.copyFileSync(sourcemapOutput, packagerMap);
566
+ }
567
+ }
568
+ else {
569
+ console.log((0, i18n_1.t)('hermesSourcemapKept', { file: hermesMap }));
570
+ }
571
+ let selection = pendingBase ? await awaitPendingBase(pendingBase) : null;
572
+ const command = hermesCommand ?? selection?.hermesCommand ?? resolveHermesCommand();
573
+ if (!selection || selection.commandUnavailable) {
574
+ selection = await selectHermesBase(command, baseRequest);
575
+ }
576
+ for (const line of selection.logs)
577
+ console.log(line);
578
+ const result = {
579
+ bytecodeVersion: selection.bytecodeVersion,
580
+ base: null,
581
+ };
582
+ const base = selection.base;
583
+ // the packager + hermes maps merged into sourcemapOutput
584
+ let composed = false;
585
+ if (!base) {
586
+ await compilePlain(command, bundlePath);
587
+ }
588
+ else {
589
+ // The JS bundle moves into a work dir and both hermesc runs read it there
590
+ // (no copies); the base compile writes the real output, and with
591
+ // verification on the plain compile the check needs runs concurrently
592
+ // into `plain/` — it simply becomes the result when the base is rejected,
593
+ // so a rejected base never costs a third compile.
594
+ const workDir = path_1.default.join(outputFolder, '.hermes-base');
595
+ const jsSource = path_1.default.join(workDir, bundleName);
596
+ const plainPath = path_1.default.join(workDir, 'plain', bundleName);
597
+ const wantPlain = Boolean(baseRequest?.verify);
598
+ fs.ensureDirSync(path_1.default.dirname(plainPath));
599
+ fs.renameSync(bundlePath, jsSource);
600
+ const args = (0, hermes_base_1.hermescArgsWithBase)(buildHermescArgs(bundlePath, jsSource), base.path);
601
+ console.log((0, i18n_1.t)('runningHermesc', { command, args: args.join(' ') }));
602
+ const [attempt, plain] = await Promise.all([
603
+ // -w: warnings only bloat the captured stderr, errors still print
604
+ runProcess(command, [...args, '-w'], true),
605
+ wantPlain
606
+ ? runProcess(command, buildHermescArgs(plainPath, jsSource), false)
607
+ : Promise.resolve(null),
608
+ ]);
609
+ let usedBase = attempt.status === 0 && !attempt.error;
610
+ if (!usedBase) {
611
+ const fullStderr = attempt.error
612
+ ? String(attempt.error.message ?? attempt.error)
613
+ : attempt.stderr;
465
614
  const reason = summarizeHermescStderr(fullStderr);
466
615
  console.warn((0, i18n_1.t)('hermesBaseCompileFailed', {
467
616
  reason: reason || `exit ${attempt.status}`,
468
617
  }));
469
618
  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');
619
+ // the summary drops noise; keep everything for bug reports — next to
620
+ // the intermediate dir, never inside it (its content is packed)
621
+ const logPath = hermesBaseErrorLogPath(outputFolder);
472
622
  try {
473
623
  fs.writeFileSync(logPath, fullStderr);
474
624
  console.warn((0, i18n_1.t)('hermesBaseCompileFailedLog', { file: logPath }));
475
625
  }
476
626
  catch { }
477
627
  }
478
- fs.copyFileSync(jsBackup, bundlePath);
479
628
  }
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);
629
+ const plainOk = plain !== null && plain.status === 0 && !plain.error;
630
+ // compose the base output's map while the disassembly compare runs; it is
631
+ // redone from the plain map in the rare case the base is rejected
632
+ const speculativeCompose = usedBase && sourcemapOutput
633
+ ? composeSourceMaps(packagerMap, hermesMap, sourcemapOutput)
634
+ : null;
635
+ if (usedBase && wantPlain) {
636
+ if (!plainOk) {
637
+ // the check could not run; that is not a verification failure
638
+ console.warn((0, i18n_1.t)('hermesBasePlainCompileFailed', {
639
+ reason: (plain?.error && String(plain.error.message ?? plain.error)) ||
640
+ `exit ${plain?.status}`,
641
+ }));
492
642
  }
493
- catch {
494
- ok = false;
643
+ else {
644
+ let ok;
645
+ try {
646
+ ok = await (0, hermes_base_1.verifyHermesBaseEquivalence)(command, bundlePath, plainPath);
647
+ }
648
+ catch {
649
+ ok = false;
650
+ }
651
+ result.verified = ok;
652
+ if (ok) {
653
+ console.log((0, i18n_1.t)('hermesBaseVerified'));
654
+ }
655
+ else {
656
+ console.warn((0, i18n_1.t)('hermesBaseVerifyFailed'));
657
+ usedBase = false;
658
+ }
495
659
  }
496
660
  }
497
- fs.removeSync(plainOut);
498
- fs.removeSync(`${plainOut}.map`);
499
- result.verified = ok;
500
- if (ok) {
501
- console.log((0, i18n_1.t)('hermesBaseVerified'));
661
+ if (speculativeCompose) {
662
+ const done = await speculativeCompose.catch((error) => {
663
+ if (usedBase)
664
+ throw error;
665
+ return false;
666
+ });
667
+ composed = usedBase && done;
502
668
  }
503
- else {
504
- console.warn((0, i18n_1.t)('hermesBaseVerifyFailed'));
505
- fs.copyFileSync(jsBackup, bundlePath);
506
- usedBase = false;
669
+ if (!usedBase) {
670
+ if (plainOk) {
671
+ fs.moveSync(plainPath, bundlePath, { overwrite: true });
672
+ if (fs.existsSync(`${plainPath}.map`)) {
673
+ fs.moveSync(`${plainPath}.map`, hermesMap, { overwrite: true });
674
+ }
675
+ }
676
+ else {
677
+ await compilePlain(command, bundlePath, jsSource);
678
+ }
507
679
  }
680
+ fs.removeSync(workDir);
681
+ result.base = usedBase ? base : null;
508
682
  }
509
- if (jsBackup)
510
- fs.removeSync(jsBackup);
511
- if (!usedBase) {
512
- console.log((0, i18n_1.t)('runningHermesc', {
513
- command: hermesCommand,
514
- args: plainArgs.join(' '),
515
- }));
516
- assertSuccessfulSyncProcess((0, child_process_1.spawnSync)(hermesCommand, plainArgs, {
517
- stdio: 'ignore',
518
- }), hermesCommand);
519
- result.base = null;
683
+ if (sourcemapOutput && !composed) {
684
+ await composeSourceMaps(packagerMap, hermesMap, sourcemapOutput);
520
685
  }
521
- else {
522
- result.base = base;
686
+ if (shouldCleanSourcemap) {
687
+ fs.removeSync(packagerMap);
523
688
  }
524
- if (sourcemapOutput) {
525
- let composerPath;
689
+ return result;
690
+ }
691
+ /** where a failed base attempt's full hermesc output goes (never packed) */
692
+ function hermesBaseErrorLogPath(outputFolder) {
693
+ return path_1.default.join(path_1.default.dirname(path_1.default.resolve(outputFolder)), 'hermes-base-error.log');
694
+ }
695
+ /**
696
+ * Begin resolving the base right away (before Metro); the compile phase awaits
697
+ * the result. Never rejects: any failure is reported there instead.
698
+ */
699
+ function startHermesBaseSelection(request) {
700
+ return (async () => {
701
+ let hermesCommand;
526
702
  try {
527
- // resolve through the project so hoisted node_modules (monorepos) work
528
- composerPath = require.resolve('react-native/scripts/compose-source-maps.js', { paths: [process.cwd()] });
703
+ hermesCommand = resolveHermesCommand();
529
704
  }
530
705
  catch {
531
- console.warn((0, i18n_1.t)('composeSourceMapsNotFound'));
532
- return result;
706
+ return {
707
+ base: null,
708
+ bytecodeVersion: null,
709
+ logs: [],
710
+ commandUnavailable: true,
711
+ };
533
712
  }
534
- console.log((0, i18n_1.t)('composingSourceMap'));
535
- assertSuccessfulSyncProcess((0, runtime_1.spawnJavaScriptSync)([
536
- composerPath,
537
- path_1.default.join(outputFolder, `${bundleName}.txt.map`),
538
- path_1.default.join(outputFolder, `${bundleName}.map`),
539
- '-o',
540
- sourcemapOutput,
541
- ], {
542
- stdio: 'ignore',
543
- }), composerPath);
544
- }
545
- if (shouldCleanSourcemap) {
546
- fs.removeSync(path_1.default.join(outputFolder, `${bundleName}.txt.map`));
547
- }
548
- return result;
713
+ try {
714
+ return await selectHermesBase(hermesCommand, request);
715
+ }
716
+ catch (error) {
717
+ return {
718
+ base: null,
719
+ bytecodeVersion: null,
720
+ logs: [
721
+ (0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }),
722
+ ],
723
+ hermesCommand,
724
+ };
725
+ }
726
+ })();
549
727
  }
550
- async function selectHermesBase(hermesCommand, request, result) {
728
+ async function selectHermesBase(hermesCommand, request) {
729
+ const logs = [];
730
+ const none = (bytecodeVersion = null) => ({
731
+ base: null,
732
+ bytecodeVersion,
733
+ logs,
734
+ hermesCommand,
735
+ });
551
736
  if (!request || request.option === 'none') {
552
737
  if (request) {
553
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: 'disabled by option' }));
738
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: 'disabled by option' }));
554
739
  }
555
- return null;
740
+ return none();
556
741
  }
557
742
  const gate = (0, hermes_base_1.classifyHermesCommand)(hermesCommand);
558
743
  if (!gate.allowed) {
559
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }));
560
- return null;
744
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }));
745
+ return none();
561
746
  }
562
747
  const bytecodeVersion = (0, hermes_base_1.probeHbcVersion)(hermesCommand);
563
- result.bytecodeVersion = bytecodeVersion;
564
748
  if (bytecodeVersion === null) {
565
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: 'could not probe HBC version' }));
566
- return null;
749
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: 'could not probe HBC version' }));
750
+ return none();
567
751
  }
568
752
  try {
569
- return await (0, hermes_base_1.resolveHermesBase)({
753
+ const base = await (0, hermes_base_1.resolveHermesBase)({
570
754
  option: request.option,
571
755
  hermesCommand,
572
756
  bytecodeVersion,
573
757
  appId: request.appId,
574
758
  cacheMaxMb: request.cacheMaxMb,
575
759
  fetchBase: api_1.getHermesBase,
576
- log: (message) => console.log(message),
760
+ log: (message) => logs.push(message),
577
761
  });
762
+ return { base, bytecodeVersion, logs, hermesCommand };
578
763
  }
579
764
  catch (error) {
580
- console.log((0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }));
581
- return null;
765
+ logs.push((0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }));
766
+ return none(bytecodeVersion);
582
767
  }
583
768
  }
584
769
  async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
package/lib/bundle.d.ts CHANGED
@@ -11,6 +11,7 @@ type NormalizedBundleOptions = {
11
11
  hermes: boolean;
12
12
  hermesBase: string;
13
13
  verifyHermesBase: boolean;
14
+ resetCache: boolean;
14
15
  cacheMaxMb?: number;
15
16
  name?: string;
16
17
  description?: string;
package/lib/bundle.js CHANGED
@@ -44,6 +44,7 @@ function normalizeBundleOptions(translatedOptions, platform) {
44
44
  hermes: (0, options_1.getBooleanOption)(translatedOptions, 'hermes', false),
45
45
  hermesBase: (0, options_1.getStringOption)(translatedOptions, 'hermesBase', 'auto'),
46
46
  verifyHermesBase: (0, options_1.getBooleanOption)(translatedOptions, 'verifyHermesBase', true),
47
+ resetCache: (0, options_1.getBooleanOption)(translatedOptions, 'resetCache', true),
47
48
  cacheMaxMb: parseCacheMaxMb(translatedOptions.cacheMaxMb),
48
49
  name: (0, options_1.getOptionalStringOption)(translatedOptions, 'name'),
49
50
  description: (0, options_1.getOptionalStringOption)(translatedOptions, 'description'),
@@ -123,6 +124,7 @@ exports.bundleCommands = {
123
124
  verify: normalized.verifyHermesBase,
124
125
  cacheMaxMb: normalized.cacheMaxMb,
125
126
  },
127
+ resetCache: normalized.resetCache,
126
128
  cli: {
127
129
  taro: normalized.taro,
128
130
  expo: normalized.expo,
package/lib/diff.d.ts CHANGED
@@ -1,6 +1,15 @@
1
+ import type { Entry } from 'yauzl';
1
2
  import type { CommandContext } from './types';
2
3
  import { enumZipEntries, readEntry } from './utils/zip-entries';
4
+ type ZipEntryContent = Pick<Entry, 'crc32' | 'uncompressedSize'>;
3
5
  export { enumZipEntries, readEntry };
6
+ /**
7
+ * 判定两个 zip entry 内容相同的键:crc32 单独并不足以证明内容一致(32 位
8
+ * 校验和碰撞并不罕见,尤其是长度不同的文件),必须同时要求解压后长度相等。
9
+ * 仅用于生成端匹配,manifest 里的 copies / copiesCrc 格式不变。
10
+ */
11
+ export declare function zipEntryContentKey(entry: ZipEntryContent): string;
12
+ export declare function zipEntriesHaveSameContent(left: ZipEntryContent, right: ZipEntryContent): boolean;
4
13
  export declare const diffCommands: {
5
14
  hdiff: ({ args, options }: CommandContext) => Promise<void>;
6
15
  hdiffFromApk: ({ args, options }: CommandContext) => Promise<void>;