react-native-update-cli 2.21.2 → 2.22.1
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 +15 -7
- package/README.zh-CN.md +15 -7
- package/cli.json +18 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +22 -0
- package/lib/bin.js +2 -0
- package/lib/bundle-runner.d.ts +26 -1
- package/lib/bundle-runner.js +137 -14
- package/lib/bundle.d.ts +3 -0
- package/lib/bundle.js +38 -2
- package/lib/cache.d.ts +5 -0
- package/lib/cache.js +20 -0
- package/lib/locales/en.d.ts +9 -0
- package/lib/locales/en.js +9 -0
- package/lib/locales/zh.d.ts +9 -0
- package/lib/locales/zh.js +9 -0
- package/lib/package.js +7 -0
- package/lib/provider.js +2 -0
- package/lib/types.d.ts +4 -0
- package/lib/utils/hermes-base.d.ts +109 -0
- package/lib/utils/hermes-base.js +644 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +3 -0
- package/lib/versions.d.ts +3 -0
- package/lib/versions.js +28 -0
- package/package.json +1 -1
- package/src/api.ts +28 -0
- package/src/bin.ts +2 -0
- package/src/bundle-runner.ts +185 -21
- package/src/bundle.ts +56 -3
- package/src/cache.ts +20 -0
- package/src/locales/en.ts +14 -0
- package/src/locales/zh.ts +12 -0
- package/src/package.ts +7 -0
- package/src/provider.ts +2 -0
- package/src/types.ts +4 -0
- package/src/utils/hermes-base.ts +730 -0
- package/src/utils/index.ts +3 -0
- package/src/versions.ts +38 -0
package/lib/versions.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Package, Platform, Version } from './types';
|
|
2
|
+
import { type HermesBaseMeta } from './utils/hermes-base';
|
|
2
3
|
interface VersionCommandOptions {
|
|
3
4
|
[key: string]: unknown;
|
|
4
5
|
config?: string;
|
|
@@ -19,6 +20,8 @@ interface VersionCommandOptions {
|
|
|
19
20
|
dryRun?: boolean;
|
|
20
21
|
versionDeps?: Record<string, string>;
|
|
21
22
|
warnDepsChanges?: boolean;
|
|
23
|
+
/** internal: chain metadata from the bundle step (not a CLI flag) */
|
|
24
|
+
hermesBase?: HermesBaseMeta;
|
|
22
25
|
'no-interactive'?: boolean | string;
|
|
23
26
|
}
|
|
24
27
|
type Deps = Record<string, string>;
|
package/lib/versions.js
CHANGED
|
@@ -15,6 +15,8 @@ const package_1 = require("./package");
|
|
|
15
15
|
const utils_1 = require("./utils");
|
|
16
16
|
const dep_versions_1 = require("./utils/dep-versions");
|
|
17
17
|
const git_1 = require("./utils/git");
|
|
18
|
+
const hbcTransform_1 = require("./utils/hbcTransform");
|
|
19
|
+
const hermes_base_1 = require("./utils/hermes-base");
|
|
18
20
|
const i18n_1 = require("./utils/i18n");
|
|
19
21
|
const options_1 = require("./utils/options");
|
|
20
22
|
function normalizeDeps(input) {
|
|
@@ -314,6 +316,29 @@ const bindVersionToPackages = async ({ appId, versionId, pkgs, rollout, dryRun,
|
|
|
314
316
|
console.log((0, i18n_1.t)('operationComplete', { count: pkgs.length }));
|
|
315
317
|
};
|
|
316
318
|
exports.bindVersionToPackages = bindVersionToPackages;
|
|
319
|
+
/**
|
|
320
|
+
* Content identity of the ppk's bundle for the server (bundleHash, HBC version)
|
|
321
|
+
* plus the base used to compile it, and a copy of the bundle in the local
|
|
322
|
+
* cache so it can serve as a future base without a download.
|
|
323
|
+
*/
|
|
324
|
+
async function describePpkBundle(ppkPath, base) {
|
|
325
|
+
const meta = {};
|
|
326
|
+
try {
|
|
327
|
+
const bundle = await (0, hermes_base_1.extractBundleFromArchive)(ppkPath);
|
|
328
|
+
if (bundle) {
|
|
329
|
+
meta.bundleHash = (0, hermes_base_1.sha256Hex)(bundle);
|
|
330
|
+
const hbcVersion = (0, hbcTransform_1.getHbcVersion)(bundle);
|
|
331
|
+
meta.bytecodeVersion = hbcVersion ?? base?.bytecodeVersion ?? null;
|
|
332
|
+
await (0, hermes_base_1.cachePut)(bundle).catch(() => { });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
// best effort: metadata never blocks a publish
|
|
337
|
+
}
|
|
338
|
+
meta.baseVersionId = base?.baseVersionId ?? null;
|
|
339
|
+
meta.baseHash = base?.baseHash ?? null;
|
|
340
|
+
return meta;
|
|
341
|
+
}
|
|
317
342
|
exports.versionCommands = {
|
|
318
343
|
publish: async ({ args, options, }) => {
|
|
319
344
|
const fn = args[0];
|
|
@@ -328,6 +353,7 @@ exports.versionCommands = {
|
|
|
328
353
|
}
|
|
329
354
|
const nonInteractive = (0, options_1.getBooleanOption)(options, 'no-interactive', false) || (0, utils_1.isNonInteractive)();
|
|
330
355
|
const { hash } = await (0, api_1.uploadFile)(fn, undefined, appId);
|
|
356
|
+
const bundleMeta = await describePpkBundle(fn, options.hermesBase);
|
|
331
357
|
const versionName = name ||
|
|
332
358
|
(nonInteractive ? '' : await (0, utils_1.question)((0, i18n_1.t)('versionNameQuestion'))) ||
|
|
333
359
|
(0, i18n_1.t)('unnamed');
|
|
@@ -340,6 +366,8 @@ exports.versionCommands = {
|
|
|
340
366
|
(nonInteractive ? '' : await (0, utils_1.question)((0, i18n_1.t)('versionMetaInfoQuestion'))),
|
|
341
367
|
deps: dep_versions_1.depVersions,
|
|
342
368
|
commit: await (0, git_1.getCommitInfo)(),
|
|
369
|
+
// Hermes delta-mode chain metadata (old servers drop unknown fields)
|
|
370
|
+
...bundleMeta,
|
|
343
371
|
});
|
|
344
372
|
console.log((0, i18n_1.t)('packageUploadSuccess', { id }));
|
|
345
373
|
const { packageId, packageVersion, packageVersionRange, minPackageVersion, maxPackageVersion, rollout, dryRun, } = options;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -7,6 +7,7 @@ import ProgressBar from 'progress';
|
|
|
7
7
|
import packageJson from '../package.json';
|
|
8
8
|
import type { Package, Session } from './types';
|
|
9
9
|
import { credentialFile, IS_CRESC, pricingPageUrl } from './utils/constants';
|
|
10
|
+
import type { HermesBaseServerRecord } from './utils/hermes-base';
|
|
10
11
|
import { getBaseUrl } from './utils/http-helper';
|
|
11
12
|
import { t } from './utils/i18n';
|
|
12
13
|
import {
|
|
@@ -335,6 +336,33 @@ export async function uploadFile(
|
|
|
335
336
|
return { hash: key || formData.key };
|
|
336
337
|
}
|
|
337
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Ask the server for the Hermes base of (app, HBC version): the earliest
|
|
341
|
+
* existing version of that epoch, or the newest version when the epoch is not
|
|
342
|
+
* known yet. Old servers answer 404 → treated as "no base".
|
|
343
|
+
*/
|
|
344
|
+
export async function getHermesBase(
|
|
345
|
+
appId: string,
|
|
346
|
+
bytecodeVersion: number,
|
|
347
|
+
): Promise<HermesBaseServerRecord | null> {
|
|
348
|
+
try {
|
|
349
|
+
const data = await get(
|
|
350
|
+
`/app/${appId}/hermesBase?bytecodeVersion=${bytecodeVersion}`,
|
|
351
|
+
);
|
|
352
|
+
const record =
|
|
353
|
+
data && typeof data === 'object' && 'data' in data ? data.data : data;
|
|
354
|
+
if (!record || typeof record !== 'object' || !record.url || !record.hash) {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
return record as HermesBaseServerRecord;
|
|
358
|
+
} catch (error) {
|
|
359
|
+
if ((error as { status?: number })?.status === 404) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
338
366
|
export const getAllPackages = async (appId: string) => {
|
|
339
367
|
// the server caps limit at 100, so page through with offset
|
|
340
368
|
const limit = 100;
|
package/src/bin.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { loadSession } from './api';
|
|
4
4
|
import { getAppCommands } from './app';
|
|
5
5
|
import { bundleCommands } from './bundle';
|
|
6
|
+
import { cacheCommands } from './cache';
|
|
6
7
|
import { diffCommands } from './diff';
|
|
7
8
|
import { installCommands } from './install';
|
|
8
9
|
import { packageCommands } from './package';
|
|
@@ -46,6 +47,7 @@ function printUsage(exitCode = 1) {
|
|
|
46
47
|
const commandHandlers: Record<string, CliCommandHandler> = {
|
|
47
48
|
...userCommands,
|
|
48
49
|
...bundleCommands,
|
|
50
|
+
...cacheCommands,
|
|
49
51
|
...diffCommands,
|
|
50
52
|
...getAppCommands(),
|
|
51
53
|
...packageCommands,
|
package/src/bundle-runner.ts
CHANGED
|
@@ -3,6 +3,16 @@ import { satisfies } from 'compare-versions';
|
|
|
3
3
|
import * as fs from 'fs-extra';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import path from 'path';
|
|
6
|
+
import { getHermesBase } from './api';
|
|
7
|
+
import {
|
|
8
|
+
classifyHermesCommand,
|
|
9
|
+
type HermesBaseOption,
|
|
10
|
+
type HermesBaseSelection,
|
|
11
|
+
hermescArgsWithBase,
|
|
12
|
+
probeHbcVersion,
|
|
13
|
+
resolveHermesBase,
|
|
14
|
+
verifyHermesBaseEquivalence,
|
|
15
|
+
} from './utils/hermes-base';
|
|
6
16
|
import { t } from './utils/i18n';
|
|
7
17
|
import {
|
|
8
18
|
getJavaScriptRuntime,
|
|
@@ -28,10 +38,26 @@ export interface RunBundleCommandOptions {
|
|
|
28
38
|
sourcemapOutput: string;
|
|
29
39
|
config?: string;
|
|
30
40
|
forceHermes?: boolean;
|
|
41
|
+
/** Hermes -base-bytecode settings; omitted → compile without a base */
|
|
42
|
+
hermesBase?: HermesBaseRequest;
|
|
31
43
|
cli: BundleCliOptions;
|
|
32
44
|
isSentry: boolean;
|
|
33
45
|
}
|
|
34
46
|
|
|
47
|
+
export interface HermesBaseRequest {
|
|
48
|
+
option: HermesBaseOption;
|
|
49
|
+
appId?: string;
|
|
50
|
+
verify: boolean;
|
|
51
|
+
cacheMaxMb?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface HermesCompileResult {
|
|
55
|
+
bytecodeVersion: number | null;
|
|
56
|
+
base: HermesBaseSelection | null;
|
|
57
|
+
/** true when --verifyHermesBase ran and passed; false when it failed (base dropped) */
|
|
58
|
+
verified?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
35
61
|
interface GradleConfig {
|
|
36
62
|
crunchPngs?: boolean;
|
|
37
63
|
enableHermes?: boolean;
|
|
@@ -170,9 +196,10 @@ export async function runReactNativeBundleCommand({
|
|
|
170
196
|
sourcemapOutput,
|
|
171
197
|
config,
|
|
172
198
|
forceHermes,
|
|
199
|
+
hermesBase,
|
|
173
200
|
cli,
|
|
174
201
|
isSentry,
|
|
175
|
-
}: RunBundleCommandOptions): Promise<
|
|
202
|
+
}: RunBundleCommandOptions): Promise<HermesCompileResult | null> {
|
|
176
203
|
let gradleConfig: GradleConfig = {};
|
|
177
204
|
if (platform === 'android') {
|
|
178
205
|
gradleConfig = await checkGradleConfig();
|
|
@@ -298,6 +325,7 @@ export async function runReactNativeBundleCommand({
|
|
|
298
325
|
`Running bundle command: ${jsRuntime} ${reactNativeBundleArgs.join(' ')}`,
|
|
299
326
|
);
|
|
300
327
|
|
|
328
|
+
let hermesResult: HermesCompileResult | null = null;
|
|
301
329
|
await new Promise<void>((resolve, reject) => {
|
|
302
330
|
reactNativeBundleProcess.stdout.on('data', (data) => {
|
|
303
331
|
console.log(data.toString().trim());
|
|
@@ -354,11 +382,12 @@ export async function runReactNativeBundleCommand({
|
|
|
354
382
|
}
|
|
355
383
|
|
|
356
384
|
if (hermesEnabled) {
|
|
357
|
-
await compileHermesByteCode(
|
|
385
|
+
hermesResult = await compileHermesByteCode(
|
|
358
386
|
bundleName,
|
|
359
387
|
outputFolder,
|
|
360
388
|
sourcemapOutput,
|
|
361
389
|
!isSentry,
|
|
390
|
+
hermesBase,
|
|
362
391
|
);
|
|
363
392
|
}
|
|
364
393
|
|
|
@@ -384,6 +413,7 @@ export async function runReactNativeBundleCommand({
|
|
|
384
413
|
}
|
|
385
414
|
});
|
|
386
415
|
});
|
|
416
|
+
return hermesResult;
|
|
387
417
|
}
|
|
388
418
|
|
|
389
419
|
function getHermesOSBin() {
|
|
@@ -513,38 +543,129 @@ async function checkGradleConfig(): Promise<GradleConfig> {
|
|
|
513
543
|
};
|
|
514
544
|
}
|
|
515
545
|
|
|
546
|
+
/**
|
|
547
|
+
* hermesc argument policy. `-output-source-map` is always passed: hermesc then
|
|
548
|
+
* strips the debug info section from the bytecode (like React Native's own
|
|
549
|
+
* release builds, 15-40% smaller bytecode and smaller hot-update patches) and
|
|
550
|
+
* writes its own `<bundle>.map` next to the output. When the user asked for a
|
|
551
|
+
* sourcemap that file is composed with the packager map as before; otherwise it
|
|
552
|
+
* simply stays in the intermediate directory (never packed into the ppk) so
|
|
553
|
+
* `address at` stack frames can still be symbolicated later.
|
|
554
|
+
*/
|
|
555
|
+
export function buildHermescArgs(bundlePath: string): string[] {
|
|
556
|
+
return [
|
|
557
|
+
'-emit-binary',
|
|
558
|
+
'-out',
|
|
559
|
+
bundlePath,
|
|
560
|
+
bundlePath,
|
|
561
|
+
'-O',
|
|
562
|
+
'-output-source-map',
|
|
563
|
+
];
|
|
564
|
+
}
|
|
565
|
+
|
|
516
566
|
async function compileHermesByteCode(
|
|
517
567
|
bundleName: string,
|
|
518
568
|
outputFolder: string,
|
|
519
569
|
sourcemapOutput: string,
|
|
520
570
|
shouldCleanSourcemap: boolean,
|
|
521
|
-
|
|
571
|
+
baseRequest?: HermesBaseRequest,
|
|
572
|
+
): Promise<HermesCompileResult> {
|
|
522
573
|
console.log(t('hermesEnabledCompiling'));
|
|
523
574
|
const hermesCommand = resolveHermesCommand();
|
|
524
575
|
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
'-out',
|
|
528
|
-
path.join(outputFolder, bundleName),
|
|
529
|
-
path.join(outputFolder, bundleName),
|
|
530
|
-
'-O',
|
|
531
|
-
];
|
|
576
|
+
const bundlePath = path.join(outputFolder, bundleName);
|
|
577
|
+
const plainArgs = buildHermescArgs(bundlePath);
|
|
532
578
|
if (sourcemapOutput) {
|
|
533
579
|
fs.copyFileSync(
|
|
534
580
|
sourcemapOutput,
|
|
535
581
|
path.join(outputFolder, `${bundleName}.txt.map`),
|
|
536
582
|
);
|
|
537
|
-
|
|
583
|
+
} else {
|
|
584
|
+
console.log(t('hermesSourcemapKept', { file: `${bundlePath}.map` }));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const result: HermesCompileResult = { bytecodeVersion: null, base: null };
|
|
588
|
+
const base = await selectHermesBase(hermesCommand, baseRequest, result);
|
|
589
|
+
|
|
590
|
+
// hermesc reads its input in full before writing, so compiling in place is
|
|
591
|
+
// safe; keep the JS bundle aside while a base compile may still fail or be
|
|
592
|
+
// rejected by the equivalence check.
|
|
593
|
+
const jsBackup = base ? `${bundlePath}.js.bak` : '';
|
|
594
|
+
if (base) fs.copyFileSync(bundlePath, jsBackup);
|
|
595
|
+
let usedBase = false;
|
|
596
|
+
if (base) {
|
|
597
|
+
const args = hermescArgsWithBase(plainArgs, base.path);
|
|
598
|
+
console.log(
|
|
599
|
+
t('runningHermesc', { command: hermesCommand, args: args.join(' ') }),
|
|
600
|
+
);
|
|
601
|
+
const attempt = spawnSync(hermesCommand, args, {
|
|
602
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
603
|
+
});
|
|
604
|
+
if (attempt.status === 0) {
|
|
605
|
+
usedBase = true;
|
|
606
|
+
} else {
|
|
607
|
+
const stderr = attempt.stderr
|
|
608
|
+
? String(attempt.stderr).trim().split('\n').slice(-3).join(' ')
|
|
609
|
+
: '';
|
|
610
|
+
console.warn(
|
|
611
|
+
t('hermesBaseCompileFailed', {
|
|
612
|
+
reason: stderr || `exit ${attempt.status}`,
|
|
613
|
+
}),
|
|
614
|
+
);
|
|
615
|
+
fs.copyFileSync(jsBackup, bundlePath);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (usedBase && baseRequest?.verify) {
|
|
619
|
+
// plain compile next to it, compare disassembly, keep whichever is right
|
|
620
|
+
const plainOut = `${bundlePath}.plain.hbc`;
|
|
621
|
+
const plain = spawnSync(
|
|
622
|
+
hermesCommand,
|
|
623
|
+
// same flags as the real compile (only the base differs), otherwise
|
|
624
|
+
// debug-info settings would make the two dumps legitimately differ
|
|
625
|
+
['-emit-binary', '-out', plainOut, jsBackup, '-O', '-output-source-map'],
|
|
626
|
+
{ stdio: 'ignore' },
|
|
627
|
+
);
|
|
628
|
+
let ok = plain.status === 0;
|
|
629
|
+
if (ok) {
|
|
630
|
+
try {
|
|
631
|
+
ok = await verifyHermesBaseEquivalence(
|
|
632
|
+
hermesCommand,
|
|
633
|
+
bundlePath,
|
|
634
|
+
plainOut,
|
|
635
|
+
);
|
|
636
|
+
} catch {
|
|
637
|
+
ok = false;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
fs.removeSync(plainOut);
|
|
641
|
+
fs.removeSync(`${plainOut}.map`);
|
|
642
|
+
result.verified = ok;
|
|
643
|
+
if (ok) {
|
|
644
|
+
console.log(t('hermesBaseVerified'));
|
|
645
|
+
} else {
|
|
646
|
+
console.warn(t('hermesBaseVerifyFailed'));
|
|
647
|
+
fs.copyFileSync(jsBackup, bundlePath);
|
|
648
|
+
usedBase = false;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (jsBackup) fs.removeSync(jsBackup);
|
|
652
|
+
if (!usedBase) {
|
|
653
|
+
console.log(
|
|
654
|
+
t('runningHermesc', {
|
|
655
|
+
command: hermesCommand,
|
|
656
|
+
args: plainArgs.join(' '),
|
|
657
|
+
}),
|
|
658
|
+
);
|
|
659
|
+
assertSuccessfulSyncProcess(
|
|
660
|
+
spawnSync(hermesCommand, plainArgs, {
|
|
661
|
+
stdio: 'ignore',
|
|
662
|
+
}),
|
|
663
|
+
hermesCommand,
|
|
664
|
+
);
|
|
665
|
+
result.base = null;
|
|
666
|
+
} else {
|
|
667
|
+
result.base = base;
|
|
538
668
|
}
|
|
539
|
-
console.log(
|
|
540
|
-
t('runningHermesc', { command: hermesCommand, args: args.join(' ') }),
|
|
541
|
-
);
|
|
542
|
-
assertSuccessfulSyncProcess(
|
|
543
|
-
spawnSync(hermesCommand, args, {
|
|
544
|
-
stdio: 'ignore',
|
|
545
|
-
}),
|
|
546
|
-
hermesCommand,
|
|
547
|
-
);
|
|
548
669
|
if (sourcemapOutput) {
|
|
549
670
|
let composerPath: string;
|
|
550
671
|
try {
|
|
@@ -555,7 +676,7 @@ async function compileHermesByteCode(
|
|
|
555
676
|
);
|
|
556
677
|
} catch {
|
|
557
678
|
console.warn(t('composeSourceMapsNotFound'));
|
|
558
|
-
return;
|
|
679
|
+
return result;
|
|
559
680
|
}
|
|
560
681
|
console.log(t('composingSourceMap'));
|
|
561
682
|
assertSuccessfulSyncProcess(
|
|
@@ -577,6 +698,49 @@ async function compileHermesByteCode(
|
|
|
577
698
|
if (shouldCleanSourcemap) {
|
|
578
699
|
fs.removeSync(path.join(outputFolder, `${bundleName}.txt.map`));
|
|
579
700
|
}
|
|
701
|
+
return result;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
async function selectHermesBase(
|
|
705
|
+
hermesCommand: string,
|
|
706
|
+
request: HermesBaseRequest | undefined,
|
|
707
|
+
result: HermesCompileResult,
|
|
708
|
+
): Promise<HermesBaseSelection | null> {
|
|
709
|
+
if (!request || request.option === 'none') {
|
|
710
|
+
if (request) {
|
|
711
|
+
console.log(t('hermesBaseNone', { reason: 'disabled by option' }));
|
|
712
|
+
}
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
const gate = classifyHermesCommand(hermesCommand);
|
|
716
|
+
if (!gate.allowed) {
|
|
717
|
+
console.log(
|
|
718
|
+
t('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }),
|
|
719
|
+
);
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
722
|
+
const bytecodeVersion = probeHbcVersion(hermesCommand);
|
|
723
|
+
result.bytecodeVersion = bytecodeVersion;
|
|
724
|
+
if (bytecodeVersion === null) {
|
|
725
|
+
console.log(t('hermesBaseNone', { reason: 'could not probe HBC version' }));
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
return await resolveHermesBase({
|
|
730
|
+
option: request.option,
|
|
731
|
+
hermesCommand,
|
|
732
|
+
bytecodeVersion,
|
|
733
|
+
appId: request.appId,
|
|
734
|
+
cacheMaxMb: request.cacheMaxMb,
|
|
735
|
+
fetchBase: getHermesBase,
|
|
736
|
+
log: (message) => console.log(message),
|
|
737
|
+
});
|
|
738
|
+
} catch (error: any) {
|
|
739
|
+
console.log(
|
|
740
|
+
t('hermesBaseNone', { reason: error?.message ?? String(error) }),
|
|
741
|
+
);
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
580
744
|
}
|
|
581
745
|
|
|
582
746
|
export async function copyDebugidForSentry(
|
package/src/bundle.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { getPlatform } from './app';
|
|
2
|
+
import { getPlatform, getSelectedApp } from './app';
|
|
3
3
|
import { packBundle } from './bundle-pack';
|
|
4
4
|
import {
|
|
5
5
|
copyDebugidForSentry,
|
|
@@ -13,6 +13,11 @@ import { addGitIgnore } from './utils/add-gitignore';
|
|
|
13
13
|
import { checkLockFiles } from './utils/check-lockfile';
|
|
14
14
|
import { tempDir } from './utils/constants';
|
|
15
15
|
import { depVersions } from './utils/dep-versions';
|
|
16
|
+
import {
|
|
17
|
+
cleanStaleTmp,
|
|
18
|
+
type HermesBaseMeta,
|
|
19
|
+
hermesBaseMeta,
|
|
20
|
+
} from './utils/hermes-base';
|
|
16
21
|
import { t } from './utils/i18n';
|
|
17
22
|
import {
|
|
18
23
|
getBooleanOption,
|
|
@@ -32,6 +37,9 @@ type NormalizedBundleOptions = {
|
|
|
32
37
|
expo: boolean;
|
|
33
38
|
rncli: boolean;
|
|
34
39
|
hermes: boolean;
|
|
40
|
+
hermesBase: string;
|
|
41
|
+
verifyHermesBase: boolean;
|
|
42
|
+
cacheMaxMb?: number;
|
|
35
43
|
name?: string;
|
|
36
44
|
description?: string;
|
|
37
45
|
metaInfo?: string;
|
|
@@ -46,6 +54,11 @@ type NormalizedBundleOptions = {
|
|
|
46
54
|
sentryDist?: string;
|
|
47
55
|
};
|
|
48
56
|
|
|
57
|
+
function parseCacheMaxMb(value: unknown): number | undefined {
|
|
58
|
+
const parsed = typeof value === 'string' ? Number(value) : (value as number);
|
|
59
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
49
62
|
type PublishBundlePayload = {
|
|
50
63
|
name?: string;
|
|
51
64
|
description?: string;
|
|
@@ -57,6 +70,7 @@ type PublishBundlePayload = {
|
|
|
57
70
|
packageVersionRange?: string;
|
|
58
71
|
rollout?: string;
|
|
59
72
|
dryRun?: boolean;
|
|
73
|
+
hermesBase?: HermesBaseMeta;
|
|
60
74
|
};
|
|
61
75
|
|
|
62
76
|
function getAliasedOptionalStringOption(
|
|
@@ -98,6 +112,13 @@ export function normalizeBundleOptions(
|
|
|
98
112
|
expo: getBooleanOption(translatedOptions, 'expo', false),
|
|
99
113
|
rncli: getBooleanOption(translatedOptions, 'rncli', false),
|
|
100
114
|
hermes: getBooleanOption(translatedOptions, 'hermes', false),
|
|
115
|
+
hermesBase: getStringOption(translatedOptions, 'hermesBase', 'auto'),
|
|
116
|
+
verifyHermesBase: getBooleanOption(
|
|
117
|
+
translatedOptions,
|
|
118
|
+
'verifyHermesBase',
|
|
119
|
+
true,
|
|
120
|
+
),
|
|
121
|
+
cacheMaxMb: parseCacheMaxMb(translatedOptions.cacheMaxMb),
|
|
101
122
|
name: getOptionalStringOption(translatedOptions, 'name'),
|
|
102
123
|
description: getOptionalStringOption(translatedOptions, 'description'),
|
|
103
124
|
metaInfo: getOptionalStringOption(translatedOptions, 'metaInfo'),
|
|
@@ -206,7 +227,24 @@ export const bundleCommands = {
|
|
|
206
227
|
|
|
207
228
|
console.log(t('bundlingWithRN', { version: depVersions['react-native'] }));
|
|
208
229
|
|
|
209
|
-
await
|
|
230
|
+
await cleanStaleTmp().catch(() => {});
|
|
231
|
+
// the hermes base lookup needs the app; resolve it up front but never
|
|
232
|
+
// fail the bundle over it (publishing resolves it again and reports)
|
|
233
|
+
let appIdForBase: string | undefined =
|
|
234
|
+
typeof options.appId === 'string' && options.appId
|
|
235
|
+
? options.appId
|
|
236
|
+
: undefined;
|
|
237
|
+
if (!appIdForBase && normalized.hermesBase === 'auto') {
|
|
238
|
+
try {
|
|
239
|
+
appIdForBase = (
|
|
240
|
+
await getSelectedApp(platform, options.config as string | undefined)
|
|
241
|
+
).appId;
|
|
242
|
+
} catch {
|
|
243
|
+
appIdForBase = undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const hermesResult = await runReactNativeBundleCommand({
|
|
210
248
|
bundleName: normalized.bundleName,
|
|
211
249
|
dev: normalized.dev,
|
|
212
250
|
entryFile: normalized.entryFile,
|
|
@@ -215,6 +253,15 @@ export const bundleCommands = {
|
|
|
215
253
|
sourcemapOutput:
|
|
216
254
|
normalized.sourcemap || bundleParams.sourcemap ? sourcemapOutput : '',
|
|
217
255
|
forceHermes: normalized.hermes,
|
|
256
|
+
hermesBase:
|
|
257
|
+
normalized.dev === 'true'
|
|
258
|
+
? undefined
|
|
259
|
+
: {
|
|
260
|
+
option: normalized.hermesBase,
|
|
261
|
+
appId: appIdForBase,
|
|
262
|
+
verify: normalized.verifyHermesBase,
|
|
263
|
+
cacheMaxMb: normalized.cacheMaxMb,
|
|
264
|
+
},
|
|
218
265
|
cli: {
|
|
219
266
|
taro: normalized.taro,
|
|
220
267
|
expo: normalized.expo,
|
|
@@ -228,6 +275,9 @@ export const bundleCommands = {
|
|
|
228
275
|
realOutput,
|
|
229
276
|
normalized.bundleName,
|
|
230
277
|
);
|
|
278
|
+
const baseMeta = hermesResult
|
|
279
|
+
? hermesBaseMeta(hermesResult.base, hermesResult.bytecodeVersion)
|
|
280
|
+
: undefined;
|
|
231
281
|
|
|
232
282
|
if (normalized.name) {
|
|
233
283
|
await publishBundleVersion(realOutput, platform, {
|
|
@@ -241,6 +291,7 @@ export const bundleCommands = {
|
|
|
241
291
|
packageVersionRange: normalized.packageVersionRange,
|
|
242
292
|
rollout: normalized.rollout,
|
|
243
293
|
dryRun: normalized.dryRun,
|
|
294
|
+
hermesBase: baseMeta,
|
|
244
295
|
});
|
|
245
296
|
await uploadSentryArtifactsIfNeeded(
|
|
246
297
|
bundleParams.sentry,
|
|
@@ -259,7 +310,9 @@ export const bundleCommands = {
|
|
|
259
310
|
if (!getBooleanOption(options, 'no-interactive', false)) {
|
|
260
311
|
const v = await question(t('uploadBundlePrompt'));
|
|
261
312
|
if (v.toLowerCase() === 'y') {
|
|
262
|
-
await publishBundleVersion(realOutput, platform, {
|
|
313
|
+
await publishBundleVersion(realOutput, platform, {
|
|
314
|
+
hermesBase: baseMeta,
|
|
315
|
+
});
|
|
263
316
|
await uploadSentryArtifactsIfNeeded(
|
|
264
317
|
bundleParams.sentry,
|
|
265
318
|
normalized.bundleName,
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { cacheStats, cleanCache } from './utils/hermes-base';
|
|
2
|
+
import { t } from './utils/i18n';
|
|
3
|
+
|
|
4
|
+
export const cacheCommands = {
|
|
5
|
+
cache: async ({ args }: { args?: string[] }) => {
|
|
6
|
+
if (args?.[0] === 'clean') {
|
|
7
|
+
const removed = await cleanCache();
|
|
8
|
+
console.log(t('cacheCleaned', { count: removed }));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const stats = await cacheStats();
|
|
12
|
+
console.log(
|
|
13
|
+
t('cacheStats', {
|
|
14
|
+
dir: stats.dir,
|
|
15
|
+
files: stats.files,
|
|
16
|
+
mb: (stats.bytes / 1024 / 1024).toFixed(1),
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
};
|
package/src/locales/en.ts
CHANGED
|
@@ -136,6 +136,8 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
136
136
|
'Set {{rollout}}% rollout for OTA update {{version}} on native version(s) {{versions}}',
|
|
137
137
|
rolloutRangeError: 'rollout must be an integer between 1-100',
|
|
138
138
|
runningHermesc: 'Running hermesc: {{- command}} {{- args}}',
|
|
139
|
+
hermesSourcemapKept:
|
|
140
|
+
'Debug info is stripped from the bytecode (like RN release builds); the Hermes sourcemap is kept at {{- file}} for symbolicating crash stacks later.',
|
|
139
141
|
sentryReactNativeNotFound:
|
|
140
142
|
'Cannot find @sentry/react-native, please make sure it is properly installed',
|
|
141
143
|
sentryCliNotFound:
|
|
@@ -212,4 +214,16 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
212
214
|
unsupportedPlatformForHermes: 'Unsupported platform for Hermes: {{platform}}',
|
|
213
215
|
invalidManifest: 'Invalid manifest',
|
|
214
216
|
failedToResolveResource: 'Failed to resolve resource: {{error}}',
|
|
217
|
+
hermesBaseNone:
|
|
218
|
+
'Hermes base: none ({{- reason}}); compiling without -base-bytecode',
|
|
219
|
+
hermesBaseUsing: 'Hermes base: {{- source}} (HBC v{{version}})',
|
|
220
|
+
hermesBaseDownloading: 'Hermes base: downloading {{- url}}',
|
|
221
|
+
hermesBaseCompileFailed:
|
|
222
|
+
'Hermes base compile failed ({{- reason}}); retrying without -base-bytecode',
|
|
223
|
+
hermesBaseVerified:
|
|
224
|
+
'Hermes base: bytecode verified equivalent to a plain compile',
|
|
225
|
+
hermesBaseVerifyFailed:
|
|
226
|
+
'Hermes base: bytecode differs from a plain compile; dropping the base and recompiling',
|
|
227
|
+
cacheCleaned: 'Removed {{count}} cached bundle(s)',
|
|
228
|
+
cacheStats: 'Bundle cache: {{- dir}} — {{files}} file(s), {{mb}} MB',
|
|
215
229
|
};
|
package/src/locales/zh.ts
CHANGED
|
@@ -126,6 +126,8 @@ export default {
|
|
|
126
126
|
'已在原生版本 {{versions}} 上设置灰度发布 {{rollout}}% 热更包 {{version}}',
|
|
127
127
|
rolloutRangeError: 'rollout 必须是 1-100 的整数',
|
|
128
128
|
runningHermesc: '运行 hermesc:{{- command}} {{- args}}',
|
|
129
|
+
hermesSourcemapKept:
|
|
130
|
+
'字节码已剥离 debug info(与 RN release 构建一致);Hermes sourcemap 保留在 {{- file}},可用于事后符号化崩溃堆栈。',
|
|
129
131
|
sentryReactNativeNotFound: '无法找到 @sentry/react-native,请确保已正确安装',
|
|
130
132
|
sentryCliNotFound: '无法找到 Sentry CLI 工具,请确保已正确安装 @sentry/cli',
|
|
131
133
|
sentryReleaseCreated: '已为版本 {{version}} 创建 Sentry release',
|
|
@@ -196,4 +198,14 @@ export default {
|
|
|
196
198
|
unsupportedPlatformForHermes: 'Hermes 不支持当前系统平台:{{platform}}',
|
|
197
199
|
invalidManifest: '无效的 manifest',
|
|
198
200
|
failedToResolveResource: '资源解析失败:{{error}}',
|
|
201
|
+
hermesBaseNone: 'Hermes base:未使用({{- reason}}),按普通方式编译',
|
|
202
|
+
hermesBaseUsing: 'Hermes base:{{- source}}(HBC v{{version}})',
|
|
203
|
+
hermesBaseDownloading: 'Hermes base:下载 {{- url}}',
|
|
204
|
+
hermesBaseCompileFailed:
|
|
205
|
+
'Hermes base 编译失败({{- reason}}),改为不带 -base-bytecode 重编',
|
|
206
|
+
hermesBaseVerified: 'Hermes base:字节码与普通编译等价,校验通过',
|
|
207
|
+
hermesBaseVerifyFailed:
|
|
208
|
+
'Hermes base:字节码与普通编译不等价,放弃 base 重新编译',
|
|
209
|
+
cacheCleaned: '已清理 {{count}} 个缓存 bundle',
|
|
210
|
+
cacheStats: 'bundle 缓存:{{- dir}} — {{files}} 个文件,{{mb}} MB',
|
|
199
211
|
};
|
package/src/package.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import { AabParser } from './utils/app-info-parser/aab';
|
|
17
17
|
import { depVersions } from './utils/dep-versions';
|
|
18
18
|
import { getCommitInfo } from './utils/git';
|
|
19
|
+
import { cachePut } from './utils/hermes-base';
|
|
19
20
|
import { t } from './utils/i18n';
|
|
20
21
|
import { getStringListOption } from './utils/options';
|
|
21
22
|
|
|
@@ -115,6 +116,7 @@ async function uploadNativePackage(
|
|
|
115
116
|
): Promise<void> {
|
|
116
117
|
const info = await config.getInfo(filePath);
|
|
117
118
|
const { versionName: extractedVersionName, buildTime, bundleHash } = info;
|
|
119
|
+
const bundleFile = (info as { bundleFile?: Buffer }).bundleFile;
|
|
118
120
|
const { appId: appIdInPkg, appKey: appKeyInPkg } = info;
|
|
119
121
|
const selectedApp = options.appId
|
|
120
122
|
? {
|
|
@@ -151,6 +153,11 @@ async function uploadNativePackage(
|
|
|
151
153
|
try {
|
|
152
154
|
await createSlimNativePackage(filePath, slimPackagePath, config.platform);
|
|
153
155
|
const { hash } = await uploadFile(slimPackagePath, undefined, appId);
|
|
156
|
+
if (bundleFile) {
|
|
157
|
+
// keep the embedded bundle locally so a later `bundle` can use it as
|
|
158
|
+
// hermes base without downloading it back (see hermes-base.ts)
|
|
159
|
+
await cachePut(bundleFile).catch(() => {});
|
|
160
|
+
}
|
|
154
161
|
const normalizedBuildTime = config.normalizeBuildTime
|
|
155
162
|
? config.normalizeBuildTime(buildTime)
|
|
156
163
|
: buildTime;
|
package/src/provider.ts
CHANGED
|
@@ -91,6 +91,8 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
91
91
|
expo: options.expo || false,
|
|
92
92
|
rncli: options.rncli || false,
|
|
93
93
|
hermes: options.hermes || false,
|
|
94
|
+
hermesBase: options.hermesBase || 'auto',
|
|
95
|
+
verifyHermesBase: options.verifyHermesBase ?? true,
|
|
94
96
|
sentryRelease: options.sentryRelease,
|
|
95
97
|
sentryDist: options.sentryDist,
|
|
96
98
|
});
|
package/src/types.ts
CHANGED
|
@@ -57,6 +57,10 @@ export interface BundleOptions {
|
|
|
57
57
|
expo?: boolean;
|
|
58
58
|
rncli?: boolean;
|
|
59
59
|
hermes?: boolean;
|
|
60
|
+
/** 'auto' (default) | 'none' | path to a .hbc/.ppk/.apk/.ipa used as hermesc -base-bytecode */
|
|
61
|
+
hermesBase?: string;
|
|
62
|
+
/** run the disassembly equivalence check after a base compile (default true) */
|
|
63
|
+
verifyHermesBase?: boolean;
|
|
60
64
|
sentryRelease?: string;
|
|
61
65
|
sentryDist?: string;
|
|
62
66
|
}
|