react-native-update-cli 2.21.2 → 2.22.0
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 +629 -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 +718 -0
- package/src/utils/index.ts +3 -0
- package/src/versions.ts +38 -0
package/README.md
CHANGED
|
@@ -14,22 +14,26 @@ A React Native Update command line tool for bundling, uploading native packages,
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm install react-native-update-cli
|
|
17
|
+
npm install -g react-native-update-cli
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
The command-line tool is installed globally. Invoke `pushy` or `cresc` directly; do not use a project-local CLI or prefix commands with `npx`.
|
|
21
|
+
|
|
20
22
|
## Basic Usage
|
|
21
23
|
|
|
22
24
|
```bash
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
pushy help
|
|
26
|
+
pushy list
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
pushy bundle --platform ios
|
|
29
|
+
pushy publish --platform ios --name 1.0.0
|
|
30
|
+
pushy uploadIpa ./app.ipa
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
## Programmatic Usage
|
|
32
34
|
|
|
35
|
+
The Provider API is a library integration, separate from the globally installed CLI. Add the package to build-tool dependencies only when importing this API; command-line usage continues to use the global `pushy` / `cresc` binaries.
|
|
36
|
+
|
|
33
37
|
```typescript
|
|
34
38
|
import { CLIProviderImpl } from 'react-native-update-cli';
|
|
35
39
|
|
|
@@ -64,6 +68,10 @@ const publishResult = await provider.publish({
|
|
|
64
68
|
- `hdiffFromApp`: Generate hdiff from APP files
|
|
65
69
|
- `hdiffFromIpa`: Generate hdiff from IPA files
|
|
66
70
|
|
|
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
|
+
|
|
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).
|
|
74
|
+
|
|
67
75
|
### Version
|
|
68
76
|
|
|
69
77
|
- `publish`: Publish a new version
|
|
@@ -147,7 +155,7 @@ sentry-cli sourcemaps upload --debug-id-reference
|
|
|
147
155
|
For older self-hosted Sentry versions or older `@sentry/cli` versions without Debug ID support, pass explicit legacy release/dist values:
|
|
148
156
|
|
|
149
157
|
```bash
|
|
150
|
-
|
|
158
|
+
pushy bundle --platform android --name "4.1" --sentry-release "com.example@1.0.0+10+pushy:4.1" --sentry-dist "pushy:4.1"
|
|
151
159
|
```
|
|
152
160
|
|
|
153
161
|
In legacy mode, the app runtime must report exactly the same Sentry `release` and `dist` values.
|
package/README.zh-CN.md
CHANGED
|
@@ -14,22 +14,26 @@ React Native Update 命令行工具,用于打包、上传原生包、发布 OT
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm install react-native-update-cli
|
|
17
|
+
npm install -g react-native-update-cli
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
命令行工具始终全局安装,直接调用 `pushy` 或 `cresc`;不要使用项目本地 CLI,也不要给命令添加 `npx` 前缀。
|
|
21
|
+
|
|
20
22
|
## 基础用法
|
|
21
23
|
|
|
22
24
|
```bash
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
pushy help
|
|
26
|
+
pushy list
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
pushy bundle --platform ios
|
|
29
|
+
pushy publish --platform ios --name 1.0.0
|
|
30
|
+
pushy uploadIpa ./app.ipa
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
## 编程调用
|
|
32
34
|
|
|
35
|
+
Provider API 属于库集成,与全局 CLI 分开。只有在代码中导入该 API 时才把包加入构建工具依赖;命令行仍然使用全局的 `pushy` / `cresc`。
|
|
36
|
+
|
|
33
37
|
```typescript
|
|
34
38
|
import { CLIProviderImpl } from 'react-native-update-cli';
|
|
35
39
|
|
|
@@ -64,6 +68,10 @@ const publishResult = await provider.publish({
|
|
|
64
68
|
- `hdiffFromApp`: 基于 APP 文件生成 hdiff
|
|
65
69
|
- `hdiffFromIpa`: 基于 IPA 文件生成 hdiff
|
|
66
70
|
|
|
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
|
+
|
|
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
|
+
|
|
67
75
|
### Version
|
|
68
76
|
|
|
69
77
|
- `publish`: 发布新版本
|
|
@@ -147,7 +155,7 @@ sentry-cli sourcemaps upload --debug-id-reference
|
|
|
147
155
|
旧版 self-hosted Sentry 或旧版 `@sentry/cli` 不支持 Debug ID 时,可以显式指定 legacy release/dist:
|
|
148
156
|
|
|
149
157
|
```bash
|
|
150
|
-
|
|
158
|
+
pushy bundle --platform android --name "4.1" --sentry-release "com.example@1.0.0+10+pushy:4.1" --sentry-dist "pushy:4.1"
|
|
151
159
|
```
|
|
152
160
|
|
|
153
161
|
这种 legacy 模式要求 App 运行时上报到 Sentry 的 `release` 和 `dist` 与上传参数完全一致。
|
package/cli.json
CHANGED
|
@@ -262,6 +262,20 @@
|
|
|
262
262
|
"hermes": {
|
|
263
263
|
"default": false
|
|
264
264
|
},
|
|
265
|
+
"hermesBase": {
|
|
266
|
+
"default": "auto",
|
|
267
|
+
"hasValue": true,
|
|
268
|
+
"description": "Hermes -base-bytecode: auto (previous version of this app, default) | none | path to .hbc/.ppk/.apk/.ipa"
|
|
269
|
+
},
|
|
270
|
+
"verifyHermesBase": {
|
|
271
|
+
"default": "true",
|
|
272
|
+
"hasValue": true,
|
|
273
|
+
"description": "After a base compile, check the bytecode is equivalent to a plain compile (disassembly compare); falls back on mismatch. Pass false to skip"
|
|
274
|
+
},
|
|
275
|
+
"cacheMaxMb": {
|
|
276
|
+
"hasValue": true,
|
|
277
|
+
"description": "Local bundle cache limit in MB (default 500)"
|
|
278
|
+
},
|
|
265
279
|
"name": {
|
|
266
280
|
"hasValue": true,
|
|
267
281
|
"description": "Version name for publishing"
|
|
@@ -359,6 +373,10 @@
|
|
|
359
373
|
"install": {
|
|
360
374
|
"description": "Install optional dependencies to the CLI",
|
|
361
375
|
"options": {}
|
|
376
|
+
},
|
|
377
|
+
"cache": {
|
|
378
|
+
"description": "Inspect or clean the local bundle cache: cache [clean]",
|
|
379
|
+
"options": {}
|
|
362
380
|
}
|
|
363
381
|
},
|
|
364
382
|
"globalOptions": {
|
package/lib/api.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Package, Session } from './types';
|
|
2
|
+
import type { HermesBaseServerRecord } from './utils/hermes-base';
|
|
2
3
|
export declare const getSession: () => Session | undefined;
|
|
3
4
|
export declare const getApiToken: () => string | undefined;
|
|
4
5
|
export declare const setApiToken: (token: string) => void;
|
|
@@ -15,4 +16,10 @@ export declare const doDelete: (api: string, body?: Record<string, any>) => Prom
|
|
|
15
16
|
export declare function uploadFile(fn: string, key?: string, appId?: string | number): Promise<{
|
|
16
17
|
hash: any;
|
|
17
18
|
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Ask the server for the Hermes base of (app, HBC version): the earliest
|
|
21
|
+
* existing version of that epoch, or the newest version when the epoch is not
|
|
22
|
+
* known yet. Old servers answer 404 → treated as "no base".
|
|
23
|
+
*/
|
|
24
|
+
export declare function getHermesBase(appId: string, bytecodeVersion: number): Promise<HermesBaseServerRecord | null>;
|
|
18
25
|
export declare const getAllPackages: (appId: string) => Promise<Package[] | null | undefined>;
|
package/lib/api.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getAllPackages = exports.doDelete = exports.put = exports.post = exports.get = exports.closeSession = exports.saveSession = exports.loadSession = exports.replaceSession = exports.setApiToken = exports.getApiToken = exports.getSession = void 0;
|
|
7
7
|
exports.uploadFile = uploadFile;
|
|
8
|
+
exports.getHermesBase = getHermesBase;
|
|
8
9
|
const filesize_parser_1 = __importDefault(require("filesize-parser"));
|
|
9
10
|
const form_data_1 = __importDefault(require("form-data"));
|
|
10
11
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -290,6 +291,27 @@ async function uploadFile(fn, key, appId) {
|
|
|
290
291
|
// const body = await response.json();
|
|
291
292
|
return { hash: key || formData.key };
|
|
292
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Ask the server for the Hermes base of (app, HBC version): the earliest
|
|
296
|
+
* existing version of that epoch, or the newest version when the epoch is not
|
|
297
|
+
* known yet. Old servers answer 404 → treated as "no base".
|
|
298
|
+
*/
|
|
299
|
+
async function getHermesBase(appId, bytecodeVersion) {
|
|
300
|
+
try {
|
|
301
|
+
const data = await (0, exports.get)(`/app/${appId}/hermesBase?bytecodeVersion=${bytecodeVersion}`);
|
|
302
|
+
const record = data && typeof data === 'object' && 'data' in data ? data.data : data;
|
|
303
|
+
if (!record || typeof record !== 'object' || !record.url || !record.hash) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
return record;
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
if (error?.status === 404) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
293
315
|
const getAllPackages = async (appId) => {
|
|
294
316
|
// the server caps limit at 100, so page through with offset
|
|
295
317
|
const limit = 100;
|
package/lib/bin.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const api_1 = require("./api");
|
|
5
5
|
const app_1 = require("./app");
|
|
6
6
|
const bundle_1 = require("./bundle");
|
|
7
|
+
const cache_1 = require("./cache");
|
|
7
8
|
const diff_1 = require("./diff");
|
|
8
9
|
const install_1 = require("./install");
|
|
9
10
|
const package_1 = require("./package");
|
|
@@ -32,6 +33,7 @@ function printUsage(exitCode = 1) {
|
|
|
32
33
|
const commandHandlers = {
|
|
33
34
|
...user_1.userCommands,
|
|
34
35
|
...bundle_1.bundleCommands,
|
|
36
|
+
...cache_1.cacheCommands,
|
|
35
37
|
...diff_1.diffCommands,
|
|
36
38
|
...(0, app_1.getAppCommands)(),
|
|
37
39
|
...package_1.packageCommands,
|
package/lib/bundle-runner.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type HermesBaseOption, type HermesBaseSelection } from './utils/hermes-base';
|
|
1
2
|
export interface BundleCliOptions {
|
|
2
3
|
taro?: boolean;
|
|
3
4
|
expo?: boolean;
|
|
@@ -12,9 +13,23 @@ export interface RunBundleCommandOptions {
|
|
|
12
13
|
sourcemapOutput: string;
|
|
13
14
|
config?: string;
|
|
14
15
|
forceHermes?: boolean;
|
|
16
|
+
/** Hermes -base-bytecode settings; omitted → compile without a base */
|
|
17
|
+
hermesBase?: HermesBaseRequest;
|
|
15
18
|
cli: BundleCliOptions;
|
|
16
19
|
isSentry: boolean;
|
|
17
20
|
}
|
|
21
|
+
export interface HermesBaseRequest {
|
|
22
|
+
option: HermesBaseOption;
|
|
23
|
+
appId?: string;
|
|
24
|
+
verify: boolean;
|
|
25
|
+
cacheMaxMb?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface HermesCompileResult {
|
|
28
|
+
bytecodeVersion: number | null;
|
|
29
|
+
base: HermesBaseSelection | null;
|
|
30
|
+
/** true when --verifyHermesBase ran and passed; false when it failed (base dropped) */
|
|
31
|
+
verified?: boolean;
|
|
32
|
+
}
|
|
18
33
|
type ResolvedExpoCli = {
|
|
19
34
|
cliPath: string;
|
|
20
35
|
usingExpo: boolean;
|
|
@@ -47,8 +62,18 @@ type SentryUploadMode = {
|
|
|
47
62
|
};
|
|
48
63
|
export declare function hasProjectDependency(dependencyName: string, projectRoot?: string): boolean;
|
|
49
64
|
export declare function resolveExpoCli(projectRoot?: string): ResolvedExpoCli;
|
|
50
|
-
export declare function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, cli, isSentry, }: RunBundleCommandOptions): Promise<
|
|
65
|
+
export declare function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, hermesBase, cli, isSentry, }: RunBundleCommandOptions): Promise<HermesCompileResult | null>;
|
|
51
66
|
export declare function resolveHermesCommand(projectRoot?: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* hermesc argument policy. `-output-source-map` is always passed: hermesc then
|
|
69
|
+
* strips the debug info section from the bytecode (like React Native's own
|
|
70
|
+
* release builds, 15-40% smaller bytecode and smaller hot-update patches) and
|
|
71
|
+
* writes its own `<bundle>.map` next to the output. When the user asked for a
|
|
72
|
+
* sourcemap that file is composed with the packager map as before; otherwise it
|
|
73
|
+
* simply stays in the intermediate directory (never packed into the ppk) so
|
|
74
|
+
* `address at` stack frames can still be symbolicated later.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildHermescArgs(bundlePath: string): string[];
|
|
52
77
|
export declare function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string): Promise<void>;
|
|
53
78
|
export declare function prepareSentryUploadArtifacts(bundleName: string, outputFolder: string, platform: string): Promise<SentryUploadArtifacts>;
|
|
54
79
|
export declare function readSourcemapDebugId(sourcemapPath: string): Promise<string | undefined>;
|
package/lib/bundle-runner.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.hasProjectDependency = hasProjectDependency;
|
|
|
40
40
|
exports.resolveExpoCli = resolveExpoCli;
|
|
41
41
|
exports.runReactNativeBundleCommand = runReactNativeBundleCommand;
|
|
42
42
|
exports.resolveHermesCommand = resolveHermesCommand;
|
|
43
|
+
exports.buildHermescArgs = buildHermescArgs;
|
|
43
44
|
exports.copyDebugidForSentry = copyDebugidForSentry;
|
|
44
45
|
exports.prepareSentryUploadArtifacts = prepareSentryUploadArtifacts;
|
|
45
46
|
exports.readSourcemapDebugId = readSourcemapDebugId;
|
|
@@ -51,6 +52,8 @@ const compare_versions_1 = require("compare-versions");
|
|
|
51
52
|
const fs = __importStar(require("fs-extra"));
|
|
52
53
|
const os_1 = __importDefault(require("os"));
|
|
53
54
|
const path_1 = __importDefault(require("path"));
|
|
55
|
+
const api_1 = require("./api");
|
|
56
|
+
const hermes_base_1 = require("./utils/hermes-base");
|
|
54
57
|
const i18n_1 = require("./utils/i18n");
|
|
55
58
|
const runtime_1 = require("./utils/runtime");
|
|
56
59
|
const g2js = require('gradle-to-js/lib/parser');
|
|
@@ -119,7 +122,7 @@ function resolveExpoCli(projectRoot = process.cwd()) {
|
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
|
-
async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, cli, isSentry, }) {
|
|
125
|
+
async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, hermesBase, cli, isSentry, }) {
|
|
123
126
|
let gradleConfig = {};
|
|
124
127
|
if (platform === 'android') {
|
|
125
128
|
gradleConfig = await checkGradleConfig();
|
|
@@ -224,6 +227,7 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
|
|
|
224
227
|
const jsRuntime = (0, runtime_1.getJavaScriptRuntime)();
|
|
225
228
|
const reactNativeBundleProcess = (0, runtime_1.spawnJavaScript)(reactNativeBundleArgs);
|
|
226
229
|
console.log(`Running bundle command: ${jsRuntime} ${reactNativeBundleArgs.join(' ')}`);
|
|
230
|
+
let hermesResult = null;
|
|
227
231
|
await new Promise((resolve, reject) => {
|
|
228
232
|
reactNativeBundleProcess.stdout.on('data', (data) => {
|
|
229
233
|
console.log(data.toString().trim());
|
|
@@ -264,7 +268,7 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
|
|
|
264
268
|
hermesEnabled = true;
|
|
265
269
|
}
|
|
266
270
|
if (hermesEnabled) {
|
|
267
|
-
await compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, !isSentry);
|
|
271
|
+
hermesResult = await compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, !isSentry, hermesBase);
|
|
268
272
|
}
|
|
269
273
|
if (platform === 'harmony') {
|
|
270
274
|
const harmonyRawAssetsPath = 'harmony/entry/src/main/resources/rawfile/assets';
|
|
@@ -283,6 +287,7 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
|
|
|
283
287
|
}
|
|
284
288
|
});
|
|
285
289
|
});
|
|
290
|
+
return hermesResult;
|
|
286
291
|
}
|
|
287
292
|
function getHermesOSBin() {
|
|
288
293
|
if (os_1.default.platform() === 'win32')
|
|
@@ -374,24 +379,107 @@ async function checkGradleConfig() {
|
|
|
374
379
|
crunchPngs,
|
|
375
380
|
};
|
|
376
381
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
382
|
+
/**
|
|
383
|
+
* hermesc argument policy. `-output-source-map` is always passed: hermesc then
|
|
384
|
+
* strips the debug info section from the bytecode (like React Native's own
|
|
385
|
+
* release builds, 15-40% smaller bytecode and smaller hot-update patches) and
|
|
386
|
+
* writes its own `<bundle>.map` next to the output. When the user asked for a
|
|
387
|
+
* sourcemap that file is composed with the packager map as before; otherwise it
|
|
388
|
+
* simply stays in the intermediate directory (never packed into the ppk) so
|
|
389
|
+
* `address at` stack frames can still be symbolicated later.
|
|
390
|
+
*/
|
|
391
|
+
function buildHermescArgs(bundlePath) {
|
|
392
|
+
return [
|
|
381
393
|
'-emit-binary',
|
|
382
394
|
'-out',
|
|
383
|
-
|
|
384
|
-
|
|
395
|
+
bundlePath,
|
|
396
|
+
bundlePath,
|
|
385
397
|
'-O',
|
|
398
|
+
'-output-source-map',
|
|
386
399
|
];
|
|
400
|
+
}
|
|
401
|
+
async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput, shouldCleanSourcemap, baseRequest) {
|
|
402
|
+
console.log((0, i18n_1.t)('hermesEnabledCompiling'));
|
|
403
|
+
const hermesCommand = resolveHermesCommand();
|
|
404
|
+
const bundlePath = path_1.default.join(outputFolder, bundleName);
|
|
405
|
+
const plainArgs = buildHermescArgs(bundlePath);
|
|
387
406
|
if (sourcemapOutput) {
|
|
388
407
|
fs.copyFileSync(sourcemapOutput, path_1.default.join(outputFolder, `${bundleName}.txt.map`));
|
|
389
|
-
args.push('-output-source-map');
|
|
390
408
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
409
|
+
else {
|
|
410
|
+
console.log((0, i18n_1.t)('hermesSourcemapKept', { file: `${bundlePath}.map` }));
|
|
411
|
+
}
|
|
412
|
+
const result = { bytecodeVersion: null, base: null };
|
|
413
|
+
const base = await selectHermesBase(hermesCommand, baseRequest, result);
|
|
414
|
+
// hermesc reads its input in full before writing, so compiling in place is
|
|
415
|
+
// safe; keep the JS bundle aside while a base compile may still fail or be
|
|
416
|
+
// rejected by the equivalence check.
|
|
417
|
+
const jsBackup = base ? `${bundlePath}.js.bak` : '';
|
|
418
|
+
if (base)
|
|
419
|
+
fs.copyFileSync(bundlePath, jsBackup);
|
|
420
|
+
let usedBase = false;
|
|
421
|
+
if (base) {
|
|
422
|
+
const args = (0, hermes_base_1.hermescArgsWithBase)(plainArgs, base.path);
|
|
423
|
+
console.log((0, i18n_1.t)('runningHermesc', { command: hermesCommand, args: args.join(' ') }));
|
|
424
|
+
const attempt = (0, child_process_1.spawnSync)(hermesCommand, args, {
|
|
425
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
426
|
+
});
|
|
427
|
+
if (attempt.status === 0) {
|
|
428
|
+
usedBase = true;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
const stderr = attempt.stderr
|
|
432
|
+
? String(attempt.stderr).trim().split('\n').slice(-3).join(' ')
|
|
433
|
+
: '';
|
|
434
|
+
console.warn((0, i18n_1.t)('hermesBaseCompileFailed', {
|
|
435
|
+
reason: stderr || `exit ${attempt.status}`,
|
|
436
|
+
}));
|
|
437
|
+
fs.copyFileSync(jsBackup, bundlePath);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (usedBase && baseRequest?.verify) {
|
|
441
|
+
// plain compile next to it, compare disassembly, keep whichever is right
|
|
442
|
+
const plainOut = `${bundlePath}.plain.hbc`;
|
|
443
|
+
const plain = (0, child_process_1.spawnSync)(hermesCommand,
|
|
444
|
+
// same flags as the real compile (only the base differs), otherwise
|
|
445
|
+
// debug-info settings would make the two dumps legitimately differ
|
|
446
|
+
['-emit-binary', '-out', plainOut, jsBackup, '-O', '-output-source-map'], { stdio: 'ignore' });
|
|
447
|
+
let ok = plain.status === 0;
|
|
448
|
+
if (ok) {
|
|
449
|
+
try {
|
|
450
|
+
ok = await (0, hermes_base_1.verifyHermesBaseEquivalence)(hermesCommand, bundlePath, plainOut);
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
ok = false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
fs.removeSync(plainOut);
|
|
457
|
+
fs.removeSync(`${plainOut}.map`);
|
|
458
|
+
result.verified = ok;
|
|
459
|
+
if (ok) {
|
|
460
|
+
console.log((0, i18n_1.t)('hermesBaseVerified'));
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
console.warn((0, i18n_1.t)('hermesBaseVerifyFailed'));
|
|
464
|
+
fs.copyFileSync(jsBackup, bundlePath);
|
|
465
|
+
usedBase = false;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (jsBackup)
|
|
469
|
+
fs.removeSync(jsBackup);
|
|
470
|
+
if (!usedBase) {
|
|
471
|
+
console.log((0, i18n_1.t)('runningHermesc', {
|
|
472
|
+
command: hermesCommand,
|
|
473
|
+
args: plainArgs.join(' '),
|
|
474
|
+
}));
|
|
475
|
+
assertSuccessfulSyncProcess((0, child_process_1.spawnSync)(hermesCommand, plainArgs, {
|
|
476
|
+
stdio: 'ignore',
|
|
477
|
+
}), hermesCommand);
|
|
478
|
+
result.base = null;
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
result.base = base;
|
|
482
|
+
}
|
|
395
483
|
if (sourcemapOutput) {
|
|
396
484
|
let composerPath;
|
|
397
485
|
try {
|
|
@@ -400,7 +488,7 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
|
|
|
400
488
|
}
|
|
401
489
|
catch {
|
|
402
490
|
console.warn((0, i18n_1.t)('composeSourceMapsNotFound'));
|
|
403
|
-
return;
|
|
491
|
+
return result;
|
|
404
492
|
}
|
|
405
493
|
console.log((0, i18n_1.t)('composingSourceMap'));
|
|
406
494
|
assertSuccessfulSyncProcess((0, runtime_1.spawnJavaScriptSync)([
|
|
@@ -416,6 +504,41 @@ async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput,
|
|
|
416
504
|
if (shouldCleanSourcemap) {
|
|
417
505
|
fs.removeSync(path_1.default.join(outputFolder, `${bundleName}.txt.map`));
|
|
418
506
|
}
|
|
507
|
+
return result;
|
|
508
|
+
}
|
|
509
|
+
async function selectHermesBase(hermesCommand, request, result) {
|
|
510
|
+
if (!request || request.option === 'none') {
|
|
511
|
+
if (request) {
|
|
512
|
+
console.log((0, i18n_1.t)('hermesBaseNone', { reason: 'disabled by option' }));
|
|
513
|
+
}
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
const gate = (0, hermes_base_1.classifyHermesCommand)(hermesCommand);
|
|
517
|
+
if (!gate.allowed) {
|
|
518
|
+
console.log((0, i18n_1.t)('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }));
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
const bytecodeVersion = (0, hermes_base_1.probeHbcVersion)(hermesCommand);
|
|
522
|
+
result.bytecodeVersion = bytecodeVersion;
|
|
523
|
+
if (bytecodeVersion === null) {
|
|
524
|
+
console.log((0, i18n_1.t)('hermesBaseNone', { reason: 'could not probe HBC version' }));
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
return await (0, hermes_base_1.resolveHermesBase)({
|
|
529
|
+
option: request.option,
|
|
530
|
+
hermesCommand,
|
|
531
|
+
bytecodeVersion,
|
|
532
|
+
appId: request.appId,
|
|
533
|
+
cacheMaxMb: request.cacheMaxMb,
|
|
534
|
+
fetchBase: api_1.getHermesBase,
|
|
535
|
+
log: (message) => console.log(message),
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
catch (error) {
|
|
539
|
+
console.log((0, i18n_1.t)('hermesBaseNone', { reason: error?.message ?? String(error) }));
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
419
542
|
}
|
|
420
543
|
async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
|
|
421
544
|
if (sourcemapOutput) {
|
package/lib/bundle.d.ts
CHANGED
package/lib/bundle.js
CHANGED
|
@@ -14,9 +14,14 @@ const add_gitignore_1 = require("./utils/add-gitignore");
|
|
|
14
14
|
const check_lockfile_1 = require("./utils/check-lockfile");
|
|
15
15
|
const constants_1 = require("./utils/constants");
|
|
16
16
|
const dep_versions_1 = require("./utils/dep-versions");
|
|
17
|
+
const hermes_base_1 = require("./utils/hermes-base");
|
|
17
18
|
const i18n_1 = require("./utils/i18n");
|
|
18
19
|
const options_1 = require("./utils/options");
|
|
19
20
|
const versions_1 = require("./versions");
|
|
21
|
+
function parseCacheMaxMb(value) {
|
|
22
|
+
const parsed = typeof value === 'string' ? Number(value) : value;
|
|
23
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
|
|
24
|
+
}
|
|
20
25
|
function getAliasedOptionalStringOption(options, key, alias) {
|
|
21
26
|
return ((0, options_1.getOptionalStringOption)(options, key) ??
|
|
22
27
|
(0, options_1.getOptionalStringOption)(options, alias));
|
|
@@ -37,6 +42,9 @@ function normalizeBundleOptions(translatedOptions, platform) {
|
|
|
37
42
|
expo: (0, options_1.getBooleanOption)(translatedOptions, 'expo', false),
|
|
38
43
|
rncli: (0, options_1.getBooleanOption)(translatedOptions, 'rncli', false),
|
|
39
44
|
hermes: (0, options_1.getBooleanOption)(translatedOptions, 'hermes', false),
|
|
45
|
+
hermesBase: (0, options_1.getStringOption)(translatedOptions, 'hermesBase', 'auto'),
|
|
46
|
+
verifyHermesBase: (0, options_1.getBooleanOption)(translatedOptions, 'verifyHermesBase', true),
|
|
47
|
+
cacheMaxMb: parseCacheMaxMb(translatedOptions.cacheMaxMb),
|
|
40
48
|
name: (0, options_1.getOptionalStringOption)(translatedOptions, 'name'),
|
|
41
49
|
description: (0, options_1.getOptionalStringOption)(translatedOptions, 'description'),
|
|
42
50
|
metaInfo: (0, options_1.getOptionalStringOption)(translatedOptions, 'metaInfo'),
|
|
@@ -85,7 +93,21 @@ exports.bundleCommands = {
|
|
|
85
93
|
throw new Error((0, i18n_1.t)('platformRequired'));
|
|
86
94
|
}
|
|
87
95
|
console.log((0, i18n_1.t)('bundlingWithRN', { version: dep_versions_1.depVersions['react-native'] }));
|
|
88
|
-
await (0,
|
|
96
|
+
await (0, hermes_base_1.cleanStaleTmp)().catch(() => { });
|
|
97
|
+
// the hermes base lookup needs the app; resolve it up front but never
|
|
98
|
+
// fail the bundle over it (publishing resolves it again and reports)
|
|
99
|
+
let appIdForBase = typeof options.appId === 'string' && options.appId
|
|
100
|
+
? options.appId
|
|
101
|
+
: undefined;
|
|
102
|
+
if (!appIdForBase && normalized.hermesBase === 'auto') {
|
|
103
|
+
try {
|
|
104
|
+
appIdForBase = (await (0, app_1.getSelectedApp)(platform, options.config)).appId;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
appIdForBase = undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const hermesResult = await (0, bundle_runner_1.runReactNativeBundleCommand)({
|
|
89
111
|
bundleName: normalized.bundleName,
|
|
90
112
|
dev: normalized.dev,
|
|
91
113
|
entryFile: normalized.entryFile,
|
|
@@ -93,6 +115,14 @@ exports.bundleCommands = {
|
|
|
93
115
|
platform,
|
|
94
116
|
sourcemapOutput: normalized.sourcemap || bundleParams.sourcemap ? sourcemapOutput : '',
|
|
95
117
|
forceHermes: normalized.hermes,
|
|
118
|
+
hermesBase: normalized.dev === 'true'
|
|
119
|
+
? undefined
|
|
120
|
+
: {
|
|
121
|
+
option: normalized.hermesBase,
|
|
122
|
+
appId: appIdForBase,
|
|
123
|
+
verify: normalized.verifyHermesBase,
|
|
124
|
+
cacheMaxMb: normalized.cacheMaxMb,
|
|
125
|
+
},
|
|
96
126
|
cli: {
|
|
97
127
|
taro: normalized.taro,
|
|
98
128
|
expo: normalized.expo,
|
|
@@ -101,6 +131,9 @@ exports.bundleCommands = {
|
|
|
101
131
|
isSentry: bundleParams.sentry,
|
|
102
132
|
});
|
|
103
133
|
await (0, bundle_pack_1.packBundle)(path_1.default.resolve(normalized.intermediaDir), realOutput, normalized.bundleName);
|
|
134
|
+
const baseMeta = hermesResult
|
|
135
|
+
? (0, hermes_base_1.hermesBaseMeta)(hermesResult.base, hermesResult.bytecodeVersion)
|
|
136
|
+
: undefined;
|
|
104
137
|
if (normalized.name) {
|
|
105
138
|
await publishBundleVersion(realOutput, platform, {
|
|
106
139
|
name: normalized.name,
|
|
@@ -113,6 +146,7 @@ exports.bundleCommands = {
|
|
|
113
146
|
packageVersionRange: normalized.packageVersionRange,
|
|
114
147
|
rollout: normalized.rollout,
|
|
115
148
|
dryRun: normalized.dryRun,
|
|
149
|
+
hermesBase: baseMeta,
|
|
116
150
|
});
|
|
117
151
|
await uploadSentryArtifactsIfNeeded(bundleParams.sentry, normalized.bundleName, normalized.intermediaDir, sourcemapOutput, platform, {
|
|
118
152
|
sentryRelease: normalized.sentryRelease,
|
|
@@ -123,7 +157,9 @@ exports.bundleCommands = {
|
|
|
123
157
|
if (!(0, options_1.getBooleanOption)(options, 'no-interactive', false)) {
|
|
124
158
|
const v = await (0, utils_1.question)((0, i18n_1.t)('uploadBundlePrompt'));
|
|
125
159
|
if (v.toLowerCase() === 'y') {
|
|
126
|
-
await publishBundleVersion(realOutput, platform, {
|
|
160
|
+
await publishBundleVersion(realOutput, platform, {
|
|
161
|
+
hermesBase: baseMeta,
|
|
162
|
+
});
|
|
127
163
|
await uploadSentryArtifactsIfNeeded(bundleParams.sentry, normalized.bundleName, normalized.intermediaDir, sourcemapOutput, platform, {
|
|
128
164
|
sentryRelease: normalized.sentryRelease,
|
|
129
165
|
sentryDist: normalized.sentryDist,
|
package/lib/cache.d.ts
ADDED
package/lib/cache.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheCommands = void 0;
|
|
4
|
+
const hermes_base_1 = require("./utils/hermes-base");
|
|
5
|
+
const i18n_1 = require("./utils/i18n");
|
|
6
|
+
exports.cacheCommands = {
|
|
7
|
+
cache: async ({ args }) => {
|
|
8
|
+
if (args?.[0] === 'clean') {
|
|
9
|
+
const removed = await (0, hermes_base_1.cleanCache)();
|
|
10
|
+
console.log((0, i18n_1.t)('cacheCleaned', { count: removed }));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const stats = await (0, hermes_base_1.cacheStats)();
|
|
14
|
+
console.log((0, i18n_1.t)('cacheStats', {
|
|
15
|
+
dir: stats.dir,
|
|
16
|
+
files: stats.files,
|
|
17
|
+
mb: (stats.bytes / 1024 / 1024).toFixed(1),
|
|
18
|
+
}));
|
|
19
|
+
},
|
|
20
|
+
};
|
package/lib/locales/en.d.ts
CHANGED
|
@@ -97,6 +97,7 @@ declare const _default: {
|
|
|
97
97
|
rolloutConfigSet: string;
|
|
98
98
|
rolloutRangeError: string;
|
|
99
99
|
runningHermesc: string;
|
|
100
|
+
hermesSourcemapKept: string;
|
|
100
101
|
sentryReactNativeNotFound: string;
|
|
101
102
|
sentryCliNotFound: string;
|
|
102
103
|
sentryReleaseCreated: string;
|
|
@@ -156,5 +157,13 @@ declare const _default: {
|
|
|
156
157
|
unsupportedPlatformForHermes: string;
|
|
157
158
|
invalidManifest: string;
|
|
158
159
|
failedToResolveResource: string;
|
|
160
|
+
hermesBaseNone: string;
|
|
161
|
+
hermesBaseUsing: string;
|
|
162
|
+
hermesBaseDownloading: string;
|
|
163
|
+
hermesBaseCompileFailed: string;
|
|
164
|
+
hermesBaseVerified: string;
|
|
165
|
+
hermesBaseVerifyFailed: string;
|
|
166
|
+
cacheCleaned: string;
|
|
167
|
+
cacheStats: string;
|
|
159
168
|
};
|
|
160
169
|
export default _default;
|
package/lib/locales/en.js
CHANGED
|
@@ -105,6 +105,7 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
105
105
|
rolloutConfigSet: 'Set {{rollout}}% rollout for OTA update {{version}} on native version(s) {{versions}}',
|
|
106
106
|
rolloutRangeError: 'rollout must be an integer between 1-100',
|
|
107
107
|
runningHermesc: 'Running hermesc: {{- command}} {{- args}}',
|
|
108
|
+
hermesSourcemapKept: 'Debug info is stripped from the bytecode (like RN release builds); the Hermes sourcemap is kept at {{- file}} for symbolicating crash stacks later.',
|
|
108
109
|
sentryReactNativeNotFound: 'Cannot find @sentry/react-native, please make sure it is properly installed',
|
|
109
110
|
sentryCliNotFound: 'Cannot find Sentry CLI tool, please make sure @sentry/cli is properly installed',
|
|
110
111
|
sentryReleaseCreated: 'Sentry release created for version: {{version}}',
|
|
@@ -164,4 +165,12 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
164
165
|
unsupportedPlatformForHermes: 'Unsupported platform for Hermes: {{platform}}',
|
|
165
166
|
invalidManifest: 'Invalid manifest',
|
|
166
167
|
failedToResolveResource: 'Failed to resolve resource: {{error}}',
|
|
168
|
+
hermesBaseNone: 'Hermes base: none ({{- reason}}); compiling without -base-bytecode',
|
|
169
|
+
hermesBaseUsing: 'Hermes base: {{- source}} (HBC v{{version}})',
|
|
170
|
+
hermesBaseDownloading: 'Hermes base: downloading {{- url}}',
|
|
171
|
+
hermesBaseCompileFailed: 'Hermes base compile failed ({{- reason}}); retrying without -base-bytecode',
|
|
172
|
+
hermesBaseVerified: 'Hermes base: bytecode verified equivalent to a plain compile',
|
|
173
|
+
hermesBaseVerifyFailed: 'Hermes base: bytecode differs from a plain compile; dropping the base and recompiling',
|
|
174
|
+
cacheCleaned: 'Removed {{count}} cached bundle(s)',
|
|
175
|
+
cacheStats: 'Bundle cache: {{- dir}} — {{files}} file(s), {{mb}} MB',
|
|
167
176
|
};
|