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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/cli.json +5 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +106 -38
- package/lib/app.js +3 -2
- package/lib/bin.js +16 -2
- package/lib/bundle-runner.d.ts +35 -2
- package/lib/bundle-runner.js +313 -128
- package/lib/bundle.d.ts +1 -0
- package/lib/bundle.js +2 -0
- package/lib/diff.d.ts +9 -0
- package/lib/diff.js +162 -120
- package/lib/locales/en.d.ts +1 -0
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.d.ts +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/package.d.ts +7 -3
- package/lib/package.js +31 -12
- package/lib/types.d.ts +2 -0
- package/lib/utils/dep-versions.d.ts +7 -0
- package/lib/utils/dep-versions.js +66 -31
- package/lib/utils/hbcTransform.d.ts +21 -0
- package/lib/utils/hbcTransform.js +146 -5
- package/lib/utils/hermes-base.d.ts +31 -7
- package/lib/utils/hermes-base.js +284 -76
- package/lib/utils/http-helper.d.ts +6 -1
- package/lib/utils/http-helper.js +23 -11
- package/lib/utils/index.d.ts +30 -1
- package/lib/utils/index.js +98 -24
- package/lib/utils/latest-version/index.d.ts +11 -8
- package/lib/utils/latest-version/index.js +63 -18
- package/lib/utils/zip-entries.js +20 -15
- package/lib/utils/zip-options.d.ts +2 -0
- package/lib/utils/zip-options.js +9 -4
- package/lib/utils/zip-range.d.ts +84 -13
- package/lib/utils/zip-range.js +363 -63
- package/lib/versions.js +30 -23
- package/package.json +11 -11
- package/src/api.ts +126 -46
- package/src/app.ts +3 -2
- package/src/bin.ts +17 -2
- package/src/bundle-runner.ts +419 -171
- package/src/bundle.ts +3 -0
- package/src/diff.ts +210 -153
- package/src/locales/en.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/package.ts +42 -14
- package/src/types.ts +2 -0
- package/src/utils/dep-versions.ts +76 -33
- package/src/utils/hbcTransform.ts +194 -5
- package/src/utils/hermes-base.ts +311 -81
- package/src/utils/http-helper.ts +24 -13
- package/src/utils/index.ts +136 -26
- package/src/utils/latest-version/index.ts +82 -29
- package/src/utils/zip-entries.ts +18 -16
- package/src/utils/zip-options.ts +8 -3
- package/src/utils/zip-range.ts +436 -67
- package/src/versions.ts +34 -26
package/lib/bundle-runner.js
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
451
|
+
input,
|
|
430
452
|
'-O',
|
|
431
453
|
'-output-source-map',
|
|
432
454
|
];
|
|
433
455
|
}
|
|
434
|
-
|
|
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
|
|
556
|
+
const hermesMap = `${bundlePath}.map`;
|
|
557
|
+
const packagerMap = path_1.default.join(outputFolder, `${bundleName}.txt.map`);
|
|
439
558
|
if (sourcemapOutput) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
|
|
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
|
|
471
|
-
|
|
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
|
-
|
|
482
|
-
// plain
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
-
|
|
494
|
-
ok
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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 (
|
|
510
|
-
|
|
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
|
-
|
|
522
|
-
|
|
686
|
+
if (shouldCleanSourcemap) {
|
|
687
|
+
fs.removeSync(packagerMap);
|
|
523
688
|
}
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
|
|
528
|
-
composerPath = require.resolve('react-native/scripts/compose-source-maps.js', { paths: [process.cwd()] });
|
|
703
|
+
hermesCommand = resolveHermesCommand();
|
|
529
704
|
}
|
|
530
705
|
catch {
|
|
531
|
-
|
|
532
|
-
|
|
706
|
+
return {
|
|
707
|
+
base: null,
|
|
708
|
+
bytecodeVersion: null,
|
|
709
|
+
logs: [],
|
|
710
|
+
commandUnavailable: true,
|
|
711
|
+
};
|
|
533
712
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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
|
|
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
|
-
|
|
738
|
+
logs.push((0, i18n_1.t)('hermesBaseNone', { reason: 'disabled by option' }));
|
|
554
739
|
}
|
|
555
|
-
return
|
|
740
|
+
return none();
|
|
556
741
|
}
|
|
557
742
|
const gate = (0, hermes_base_1.classifyHermesCommand)(hermesCommand);
|
|
558
743
|
if (!gate.allowed) {
|
|
559
|
-
|
|
560
|
-
return
|
|
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
|
-
|
|
566
|
-
return
|
|
749
|
+
logs.push((0, i18n_1.t)('hermesBaseNone', { reason: 'could not probe HBC version' }));
|
|
750
|
+
return none();
|
|
567
751
|
}
|
|
568
752
|
try {
|
|
569
|
-
|
|
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) =>
|
|
760
|
+
log: (message) => logs.push(message),
|
|
577
761
|
});
|
|
762
|
+
return { base, bytecodeVersion, logs, hermesCommand };
|
|
578
763
|
}
|
|
579
764
|
catch (error) {
|
|
580
|
-
|
|
581
|
-
return
|
|
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
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>;
|