react-native-update-cli 2.29.1 → 2.29.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/lib/account.js +2 -4
  2. package/lib/api.d.ts +1 -1
  3. package/lib/api.js +26 -44
  4. package/lib/app.js +13 -27
  5. package/lib/auto-update.d.ts +1 -1
  6. package/lib/auto-update.js +6 -16
  7. package/lib/bin.js +4 -6
  8. package/lib/bundle-pack.js +25 -27
  9. package/lib/bundle-runner.js +55 -54
  10. package/lib/bundle.js +18 -26
  11. package/lib/diff.js +32 -91
  12. package/lib/locales/en.d.ts +0 -10
  13. package/lib/locales/en.js +0 -10
  14. package/lib/locales/zh.d.ts +0 -10
  15. package/lib/locales/zh.js +0 -10
  16. package/lib/native-package.js +20 -60
  17. package/lib/package.d.ts +6 -1
  18. package/lib/package.js +59 -74
  19. package/lib/provider.js +3 -5
  20. package/lib/symbolicate.js +1 -16
  21. package/lib/utils/add-gitignore.js +0 -1
  22. package/lib/utils/app-info-parser/aab.d.ts +5 -22
  23. package/lib/utils/app-info-parser/aab.js +87 -192
  24. package/lib/utils/app-info-parser/apk.d.ts +12 -13
  25. package/lib/utils/app-info-parser/apk.js +28 -78
  26. package/lib/utils/app-info-parser/ipa.d.ts +2 -14
  27. package/lib/utils/app-info-parser/ipa.js +9 -70
  28. package/lib/utils/app-info-parser/resource-finder.d.ts +1 -26
  29. package/lib/utils/app-info-parser/resource-finder.js +41 -183
  30. package/lib/utils/app-info-parser/xml-parser/binary.d.ts +6 -55
  31. package/lib/utils/app-info-parser/xml-parser/binary.js +152 -556
  32. package/lib/utils/app-info-parser/zip.d.ts +6 -24
  33. package/lib/utils/app-info-parser/zip.js +19 -86
  34. package/lib/utils/check-plugin.d.ts +7 -5
  35. package/lib/utils/check-plugin.js +15 -25
  36. package/lib/utils/dep-versions.d.ts +0 -6
  37. package/lib/utils/dep-versions.js +2 -27
  38. package/lib/utils/failure-fingerprint.js +3 -4
  39. package/lib/utils/fs-helpers.d.ts +5 -0
  40. package/lib/utils/fs-helpers.js +19 -0
  41. package/lib/utils/git.d.ts +0 -1
  42. package/lib/utils/git.js +0 -8
  43. package/lib/utils/hash.d.ts +3 -0
  44. package/lib/utils/hash.js +19 -0
  45. package/lib/utils/hbcTransform.d.ts +9 -2
  46. package/lib/utils/hbcTransform.js +41 -70
  47. package/lib/utils/hermes-base.d.ts +1 -5
  48. package/lib/utils/hermes-base.js +93 -156
  49. package/lib/utils/hermes-literals.d.ts +5 -3
  50. package/lib/utils/hermes-literals.js +30 -53
  51. package/lib/utils/hermes-raw.d.ts +7 -0
  52. package/lib/utils/hermes-raw.js +26 -9
  53. package/lib/utils/http-helper.d.ts +0 -1
  54. package/lib/utils/http-helper.js +0 -20
  55. package/lib/utils/i18n.js +0 -2
  56. package/lib/utils/index.d.ts +5 -19
  57. package/lib/utils/index.js +95 -189
  58. package/lib/utils/latest-version.d.ts +19 -0
  59. package/lib/utils/latest-version.js +137 -0
  60. package/lib/utils/options.d.ts +2 -1
  61. package/lib/utils/options.js +5 -7
  62. package/lib/utils/zip-entries.d.ts +23 -0
  63. package/lib/utils/zip-entries.js +125 -102
  64. package/lib/utils/zip-options.js +29 -56
  65. package/lib/utils/zip-range.js +25 -65
  66. package/lib/versions.d.ts +5 -0
  67. package/lib/versions.js +86 -153
  68. package/package.json +1 -3
  69. package/lib/utils/app-info-parser/app.d.ts +0 -4
  70. package/lib/utils/app-info-parser/app.js +0 -10
  71. package/lib/utils/app-info-parser/index.d.ts +0 -16
  72. package/lib/utils/app-info-parser/index.js +0 -46
  73. package/lib/utils/app-info-parser/utils.d.ts +0 -31
  74. package/lib/utils/app-info-parser/utils.js +0 -135
  75. package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +0 -10
  76. package/lib/utils/app-info-parser/xml-parser/manifest.js +0 -202
  77. package/lib/utils/latest-version/index.d.ts +0 -149
  78. package/lib/utils/latest-version/index.js +0 -326
  79. package/lib/utils/plugin-config.d.ts +0 -9
  80. package/lib/utils/plugin-config.js +0 -31
@@ -1,24 +1,6 @@
1
- export declare class Zip {
2
- file: string | File;
3
- constructor(file: string | File);
4
- /**
5
- * get entries by regexps, the return format is: { <filename>: <Buffer|Blob> }
6
- * @param {Array} regexps // regexps for matching files
7
- * @param {String} type // return type, can be buffer or blob, default buffer
8
- */
9
- getEntries(regexps: Array<RegExp | string>, type?: 'buffer' | 'blob'): Promise<Record<string, Blob | Buffer<ArrayBufferLike>>>;
10
- /**
11
- * get entry by regex, return an instance of Buffer or Blob
12
- * @param {Regex} regex // regex for matching file
13
- * @param {String} type // return type, can be buffer or blob, default buffer
14
- */
15
- getEntry(regex: RegExp | string, type?: 'buffer' | 'blob'): Promise<Blob | Buffer<ArrayBufferLike>>;
16
- getEntryFromHarmonyApp(regex: RegExp): Promise<Buffer | Blob | undefined>;
17
- /**
18
- * Read multiple entries in a single pass over the archive (including
19
- * nested .hap extraction), instead of one full scan per entry.
20
- * Returns buffers in the same order as the given regexps.
21
- */
22
- getEntriesFromHarmonyApp(regexps: RegExp[]): Promise<(Buffer | undefined)[]>;
23
- private readEntries;
24
- }
1
+ /**
2
+ * Read the entries matching each pattern in a single pass over the archive
3
+ * (nested .hap archives included). Each entry name is tried as-is and
4
+ * lowercased, with NUL padding stripped. Returns buffers in pattern order.
5
+ */
6
+ export declare function readZipEntries(file: string, patterns: RegExp[]): Promise<(Buffer | undefined)[]>;
@@ -1,92 +1,25 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Zip = void 0;
7
- const path_1 = __importDefault(require("path"));
3
+ exports.readZipEntries = readZipEntries;
8
4
  const zip_entries_1 = require("../zip-entries");
9
- const utils_1 = require("./utils");
10
- class Zip {
11
- file;
12
- constructor(file) {
13
- this.file = typeof file === 'string' ? path_1.default.resolve(file) : file;
14
- }
15
- /**
16
- * get entries by regexps, the return format is: { <filename>: <Buffer|Blob> }
17
- * @param {Array} regexps // regexps for matching files
18
- * @param {String} type // return type, can be buffer or blob, default buffer
19
- */
20
- getEntries(regexps, type = 'buffer') {
21
- const decoded = regexps.map((regex) => (0, utils_1.decodeNullUnicode)(regex));
22
- return this.readEntries(decoded, type);
23
- }
24
- /**
25
- * get entry by regex, return an instance of Buffer or Blob
26
- * @param {Regex} regex // regex for matching file
27
- * @param {String} type // return type, can be buffer or blob, default buffer
28
- */
29
- getEntry(regex, type = 'buffer') {
30
- const decoded = (0, utils_1.decodeNullUnicode)(regex);
31
- return this.readEntries([decoded], type).then((buffers) => buffers[decoded]);
32
- }
33
- async getEntryFromHarmonyApp(regex) {
34
- return (await this.getEntriesFromHarmonyApp([regex]))[0];
35
- }
36
- /**
37
- * Read multiple entries in a single pass over the archive (including
38
- * nested .hap extraction), instead of one full scan per entry.
39
- * Returns buffers in the same order as the given regexps.
40
- */
41
- async getEntriesFromHarmonyApp(regexps) {
42
- const results = new Array(regexps.length);
43
- try {
44
- if (typeof this.file !== 'string') {
45
- throw new Error('Param error: [file] must be file path in Node.');
46
- }
47
- await (0, zip_entries_1.enumZipEntries)(this.file, async (entry, zipFile) => {
48
- for (let i = 0; i < regexps.length; i++) {
49
- if (regexps[i].test(entry.fileName)) {
50
- results[i] = await (0, zip_entries_1.readEntry)(entry, zipFile);
51
- }
52
- }
53
- });
5
+ /**
6
+ * Read the entries matching each pattern in a single pass over the archive
7
+ * (nested .hap archives included). Each entry name is tried as-is and
8
+ * lowercased, with NUL padding stripped. Returns buffers in pattern order.
9
+ */
10
+ async function readZipEntries(file, patterns) {
11
+ const results = new Array(patterns.length);
12
+ await (0, zip_entries_1.enumZipEntries)(file, async (entry, zipFile) => {
13
+ if (entry.fileName.endsWith('/')) {
14
+ return;
54
15
  }
55
- catch (error) {
56
- console.error('Error in getEntriesFromHarmonyApp:', error);
16
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: strips NUL padding from entry names
17
+ const name = entry.fileName.replace(/\u0000/g, '');
18
+ const lowerName = name.toLowerCase();
19
+ const index = patterns.findIndex((pattern) => pattern.test(name) || pattern.test(lowerName));
20
+ if (index !== -1) {
21
+ results[index] = await (0, zip_entries_1.readEntry)(entry, zipFile);
57
22
  }
58
- return results;
59
- }
60
- async readEntries(decoded, type) {
61
- if (typeof this.file !== 'string') {
62
- throw new Error('Param error: [file] must be file path in Node.');
63
- }
64
- const buffers = {};
65
- await (0, zip_entries_1.enumZipEntries)(this.file, async (entry, zipFile) => {
66
- if (entry.fileName.endsWith('/')) {
67
- return;
68
- }
69
- const entryName = (0, utils_1.decodeNullUnicode)(entry.fileName).toString();
70
- const lowerEntryName = entryName.toLowerCase();
71
- const matched = decoded.find((pattern) => {
72
- if (typeof pattern === 'string') {
73
- return pattern === entryName || pattern === lowerEntryName;
74
- }
75
- pattern.lastIndex = 0;
76
- if (pattern.test(entryName)) {
77
- return true;
78
- }
79
- pattern.lastIndex = 0;
80
- return pattern.test(lowerEntryName);
81
- });
82
- if (!matched) {
83
- return;
84
- }
85
- const buffer = await (0, zip_entries_1.readEntry)(entry, zipFile);
86
- buffers[matched] =
87
- type === 'blob' ? new Blob([buffer]) : buffer;
88
- });
89
- return buffers;
90
- }
23
+ });
24
+ return results;
91
25
  }
92
- exports.Zip = Zip;
@@ -1,7 +1,9 @@
1
- interface BundleParams {
1
+ /**
2
+ * Bundle params implied by the project's plugins. Sentry (a sentry.properties
3
+ * under ios/ or android/) turns on its source map upload, and with it the
4
+ * source map itself.
5
+ */
6
+ export declare function checkPlugins(): Promise<{
2
7
  sentry: boolean;
3
8
  sourcemap: boolean;
4
- [key: string]: any;
5
- }
6
- export declare function checkPlugins(): Promise<BundleParams>;
7
- export {};
9
+ }>;
@@ -1,31 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkPlugins = checkPlugins;
4
+ const fs_helpers_1 = require("./fs-helpers");
4
5
  const i18n_1 = require("./i18n");
5
- const plugin_config_1 = require("./plugin-config");
6
+ /**
7
+ * Bundle params implied by the project's plugins. Sentry (a sentry.properties
8
+ * under ios/ or android/) turns on its source map upload, and with it the
9
+ * source map itself.
10
+ */
6
11
  async function checkPlugins() {
7
- const params = {
8
- sentry: false,
9
- sourcemap: false,
10
- };
11
- const results = await Promise.all(plugin_config_1.plugins.map(async (plugin) => {
12
- try {
13
- const isEnabled = await plugin.detect();
14
- return { isEnabled, error: null };
15
- }
16
- catch (error) {
17
- return { isEnabled: false, error };
18
- }
19
- }));
20
- results.forEach(({ isEnabled, error }, index) => {
21
- const plugin = plugin_config_1.plugins[index];
22
- if (error) {
23
- console.warn((0, i18n_1.t)('pluginDetectionError', { name: plugin.name, error }));
24
- }
25
- else if (isEnabled && plugin.bundleParams) {
26
- Object.assign(params, plugin.bundleParams);
27
- console.log((0, i18n_1.t)('pluginDetected', { name: plugin.name }));
28
- }
29
- });
30
- return params;
12
+ const [ios, android] = await Promise.all([
13
+ (0, fs_helpers_1.pathExists)('ios/sentry.properties'),
14
+ (0, fs_helpers_1.pathExists)('android/sentry.properties'),
15
+ ]);
16
+ const sentry = ios || android;
17
+ if (sentry) {
18
+ console.log((0, i18n_1.t)('pluginDetected', { name: 'sentry' }));
19
+ }
20
+ return { sentry, sourcemap: sentry };
31
21
  }
@@ -7,9 +7,3 @@ export declare function getDepVersions(): Record<string, string>;
7
7
  * before every command must not scale with the size of the project.
8
8
  */
9
9
  export declare function getDepVersion(name: string, cwd?: string): string | undefined;
10
- /**
11
- * Same data as `getDepVersions()` but as a lazily populated object, for the
12
- * remaining property-access call sites (`depVersions['react-native']`).
13
- * Nothing is resolved until the first property access.
14
- */
15
- export declare const depVersions: Record<string, string>;
@@ -8,7 +8,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.depVersions = void 0;
12
11
  exports.getDepVersions = getDepVersions;
13
12
  exports.getDepVersion = getDepVersion;
14
13
  const fs_1 = __importDefault(require("fs"));
@@ -68,12 +67,9 @@ function readDepVersions(cwd) {
68
67
  }
69
68
  }
70
69
  // sorted keys: the object is sent to the server as-is and diffed
71
- return Object.keys(versions)
70
+ return Object.fromEntries(Object.keys(versions)
72
71
  .sort()
73
- .reduce((obj, key) => {
74
- obj[key] = versions[key];
75
- return obj;
76
- }, {});
72
+ .map((key) => [key, versions[key]]));
77
73
  }
78
74
  /** Installed versions of the cwd project's dependencies, keys sorted. */
79
75
  function getDepVersions() {
@@ -101,24 +97,3 @@ function getDepVersion(name, cwd = process.cwd()) {
101
97
  }
102
98
  return readInstalledVersion(name, resolvedCwd);
103
99
  }
104
- /**
105
- * Same data as `getDepVersions()` but as a lazily populated object, for the
106
- * remaining property-access call sites (`depVersions['react-native']`).
107
- * Nothing is resolved until the first property access.
108
- */
109
- exports.depVersions = new Proxy({}, {
110
- get: (_target, key) => typeof key === 'string' ? getDepVersions()[key] : undefined,
111
- has: (_target, key) => typeof key === 'string' && key in getDepVersions(),
112
- ownKeys: () => Object.keys(getDepVersions()),
113
- getOwnPropertyDescriptor: (_target, key) => {
114
- if (typeof key !== 'string' || !(key in getDepVersions())) {
115
- return undefined;
116
- }
117
- return {
118
- value: getDepVersions()[key],
119
- writable: false,
120
- enumerable: true,
121
- configurable: true,
122
- };
123
- },
124
- });
@@ -18,10 +18,9 @@ exports.failureFingerprint = failureFingerprint;
18
18
  * leaves the machine. The local console keeps the unredacted text: that is
19
19
  * where the name is actually useful.
20
20
  */
21
- const node_crypto_1 = require("node:crypto");
22
- const sha = (value) => (0, node_crypto_1.createHash)('sha256').update(value).digest('hex');
21
+ const hash_1 = require("./hash");
23
22
  /** stable stand-in for one redacted value; the same input always yields it */
24
- const token = (kind, value) => `${kind}#${sha(value).slice(0, 8)}`;
23
+ const token = (kind, value) => `${kind}#${(0, hash_1.sha256Hex)(value).slice(0, 8)}`;
25
24
  /**
26
25
  * Replace the parts of a detail line that can only come from the user's code:
27
26
  * quoted string operands (property names, string literals), function names,
@@ -68,5 +67,5 @@ function failureFingerprint(detail) {
68
67
  .replace(/\d+/g, 'N')
69
68
  .replace(/\s+/g, ' ')
70
69
  .trim();
71
- return sha(shape).slice(0, 32);
70
+ return (0, hash_1.sha256Hex)(shape).slice(0, 32);
72
71
  }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * The per-user cache directory for `name`: $XDG_CACHE_HOME when set (on every
3
+ * platform; also lets tests isolate), else the platform's cache location.
4
+ */
5
+ export declare function userCacheDir(name: string): string;
1
6
  /** `rm -rf`: no error when the path is already gone. */
2
7
  export declare function remove(target: string): Promise<void>;
3
8
  export declare function removeSync(target: string): void;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.userCacheDir = userCacheDir;
7
8
  exports.remove = remove;
8
9
  exports.removeSync = removeSync;
9
10
  exports.ensureDir = ensureDir;
@@ -12,7 +13,25 @@ exports.pathExists = pathExists;
12
13
  exports.emptyDirSync = emptyDirSync;
13
14
  exports.moveSync = moveSync;
14
15
  const fs_1 = __importDefault(require("fs"));
16
+ const os_1 = require("os");
15
17
  const path_1 = __importDefault(require("path"));
18
+ /**
19
+ * The per-user cache directory for `name`: $XDG_CACHE_HOME when set (on every
20
+ * platform; also lets tests isolate), else the platform's cache location.
21
+ */
22
+ function userCacheDir(name) {
23
+ if (process.env.XDG_CACHE_HOME) {
24
+ return path_1.default.join(process.env.XDG_CACHE_HOME, name);
25
+ }
26
+ switch (process.platform) {
27
+ case 'darwin':
28
+ return path_1.default.join((0, os_1.homedir)(), 'Library', 'Caches', name);
29
+ case 'win32':
30
+ return path_1.default.join(process.env.LOCALAPPDATA ?? path_1.default.join((0, os_1.homedir)(), 'AppData', 'Local'), name, 'Cache');
31
+ default:
32
+ return path_1.default.join((0, os_1.homedir)(), '.cache', name);
33
+ }
34
+ }
16
35
  /** `rm -rf`: no error when the path is already gone. */
17
36
  function remove(target) {
18
37
  return fs_1.default.promises.rm(target, { recursive: true, force: true });
@@ -5,5 +5,4 @@ export interface CommitInfo {
5
5
  timestamp: string;
6
6
  origin?: string;
7
7
  }
8
- export declare function getCurrentCommit(): string;
9
8
  export declare function getCommitInfo(): Promise<CommitInfo | undefined>;
package/lib/utils/git.js CHANGED
@@ -1,17 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCurrentCommit = getCurrentCommit;
4
3
  exports.getCommitInfo = getCommitInfo;
5
4
  const child_process_1 = require("child_process");
6
5
  const util_1 = require("util");
7
6
  const execFile = (0, util_1.promisify)(child_process_1.execFile);
8
- function getCurrentCommit() {
9
- const result = (0, child_process_1.spawnSync)('git', ['rev-parse', 'HEAD']);
10
- if (result.status !== 0) {
11
- throw new Error('Not a git repository');
12
- }
13
- return result.stdout.toString().trim();
14
- }
15
7
  async function gitOutput(args, cwd = process.cwd()) {
16
8
  const { stdout } = await execFile('git', args, {
17
9
  cwd,
@@ -0,0 +1,3 @@
1
+ export declare function sha256Hex(data: Buffer | string): string;
2
+ /** sha256 of a file, streamed (a bundle or cached base can be tens of MB) */
3
+ export declare function sha256File(file: string): Promise<string>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sha256Hex = sha256Hex;
7
+ exports.sha256File = sha256File;
8
+ const crypto_1 = require("crypto");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ function sha256Hex(data) {
11
+ return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
12
+ }
13
+ /** sha256 of a file, streamed (a bundle or cached base can be tens of MB) */
14
+ async function sha256File(file) {
15
+ const hash = (0, crypto_1.createHash)('sha256');
16
+ for await (const chunk of fs_1.default.createReadStream(file))
17
+ hash.update(chunk);
18
+ return hash.digest('hex');
19
+ }
@@ -14,6 +14,8 @@
14
14
  * wrapping 差分与单调性无关、恒可逆:T⁻¹(T(x)) === x 对任意输入成立
15
15
  * (只要两侧使用同一份描述表)。
16
16
  */
17
+ export declare const HBC_MAGIC: Buffer<ArrayBuffer>;
18
+ export declare const HBC_HEADER_SIZE = 128;
17
19
  /** 差分字段:条目内 byte 偏移处按小端读 u32,取 [bit, bit+bits) 位。 */
18
20
  type DeltaField = {
19
21
  byte: number;
@@ -70,6 +72,7 @@ export type HbcSectionRange = {
70
72
  */
71
73
  export declare function resolveHbcSections(header: Buffer, fileLength: number): {
72
74
  version: number;
75
+ layout: HbcLayout;
73
76
  sections: Map<string, HbcSectionRange>;
74
77
  } | null;
75
78
  /**
@@ -79,14 +82,18 @@ export declare function resolveHbcSections(header: Buffer, fileLength: number):
79
82
  * 注意:变换不改动头部计数,同一文件正/逆向解析选中的布局必然一致。
80
83
  */
81
84
  export declare function transformHbc(buf: Buffer, inverse?: boolean): Buffer | null;
82
- /** 返回该 buffer 结构上匹配的布局(候选中第一个校验通过者)。 */
83
- export declare function pickLayout(buf: Buffer): HbcLayout | null;
84
85
  export declare function transformHbcWithLayout(buf: Buffer, layout: HbcLayout, inverse: boolean): Buffer | null;
85
86
  /**
86
87
  * 原地变换:直接改写 buf,不再分配整块副本。调用方须持有 buf 的所有权
87
88
  * (例如 patch() 刚返回的新 Buffer)。结构不匹配时返回 false 且 buf 不变。
88
89
  */
89
90
  export declare function transformHbcWithLayoutInPlace(buf: Buffer, layout: HbcLayout, inverse: boolean): boolean;
91
+ type HbcFileHeader = {
92
+ header: Buffer;
93
+ size: number;
94
+ };
95
+ /** 读取文件头 128 字节与总长;文件过短或非 HBC 时返回 null。 */
96
+ export declare function readHbcFileHeader(filePath: string): Promise<HbcFileHeader | null>;
90
97
  /**
91
98
  * 文件版 transformHbcWithLayout:把 src 复制到 dst,再仅对含差分字段的
92
99
  * 段(位于 [128, 最后一段末尾) 区间内)做定位读写改写。任一时刻内存中
@@ -16,22 +16,24 @@
16
16
  * (只要两侧使用同一份描述表)。
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.HBC_TRANSFORM_VERSION = exports.HBC_LAYOUTS = void 0;
19
+ exports.HBC_TRANSFORM_VERSION = exports.HBC_LAYOUTS = exports.HBC_HEADER_SIZE = exports.HBC_MAGIC = void 0;
20
20
  exports.compileLayoutToWire = compileLayoutToWire;
21
21
  exports.getHbcVersion = getHbcVersion;
22
22
  exports.findLayouts = findLayouts;
23
23
  exports.resolveHbcSections = resolveHbcSections;
24
24
  exports.transformHbc = transformHbc;
25
- exports.pickLayout = pickLayout;
26
25
  exports.transformHbcWithLayout = transformHbcWithLayout;
27
26
  exports.transformHbcWithLayoutInPlace = transformHbcWithLayoutInPlace;
27
+ exports.readHbcFileHeader = readHbcFileHeader;
28
28
  exports.transformHbcFile = transformHbcFile;
29
29
  exports.tryTransformPair = tryTransformPair;
30
30
  exports.tryTransformPairFiles = tryTransformPairFiles;
31
31
  const promises_1 = require("node:fs/promises");
32
- const HBC_MAGIC = Buffer.from([0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f]);
32
+ exports.HBC_MAGIC = Buffer.from([
33
+ 0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f,
34
+ ]);
33
35
  const HEADER_COUNTS_OFFSET = 32; // magic(8) + version(4) + sourceHash(20)
34
- const HBC_HEADER_SIZE = 128;
36
+ exports.HBC_HEADER_SIZE = 128;
35
37
  const FUNC_OFFSET_25 = { byte: 0, bit: 0, bits: 25 };
36
38
  const STRING_OFFSET_23 = { byte: 0, bit: 1, bits: 23 };
37
39
  const PAIR_OFFSET_32 = { byte: 0, bit: 0, bits: 32 };
@@ -205,16 +207,10 @@ exports.HBC_LAYOUTS = [
205
207
  // 多一个 numStringSwitchImms 槽(hermes static_h 在不 bump 版本号的
206
208
  // 情况下插入,同一版本号 98 因此存在两种布局,依结构校验区分)。
207
209
  // 段布局与早期 v98 相同。
208
- minVersion: 98,
209
- maxVersion: 98,
210
- headerFields: V98_LATE_HEADER_FIELDS,
211
- sections: V98_SECTIONS,
212
- },
213
- {
214
- // Hermes V1 v99(hermes-compiler 260318099,RN 0.88+):文件头与段布局
210
+ // Hermes V1 v99(hermes-compiler 260318099,RN 0.88+)文件头与段布局
215
211
  // 同晚期 v98,只改了函数头内部位域(去 NumCacheNewObject)与操作码表,
216
212
  // 二者都不在本变换触及的范围内。
217
- minVersion: 99,
213
+ minVersion: 98,
218
214
  maxVersion: 99,
219
215
  headerFields: V98_LATE_HEADER_FIELDS,
220
216
  sections: V98_SECTIONS,
@@ -226,27 +222,7 @@ exports.HBC_LAYOUTS = [
226
222
  // arrayBufferSize 更名 literalValueBufferSize(槽位不变)。
227
223
  minVersion: 98,
228
224
  maxVersion: 98,
229
- headerFields: [
230
- 'fileLength',
231
- 'globalCodeIndex',
232
- 'functionCount',
233
- 'stringKindCount',
234
- 'identifierCount',
235
- 'stringCount',
236
- 'overflowStringCount',
237
- 'stringStorageSize',
238
- 'bigIntCount',
239
- 'bigIntStorageSize',
240
- 'regExpCount',
241
- 'regExpStorageSize',
242
- 'literalValueBufferSize',
243
- 'objKeyBufferSize',
244
- 'objShapeTableCount',
245
- 'segmentID',
246
- 'cjsModuleCount',
247
- 'functionSourceCount',
248
- 'debugInfoOffset',
249
- ],
225
+ headerFields: V98_LATE_HEADER_FIELDS.filter((field) => field !== 'numStringSwitchImms'),
250
226
  sections: V98_SECTIONS,
251
227
  },
252
228
  ];
@@ -265,9 +241,9 @@ function compileLayoutToWire(layout) {
265
241
  };
266
242
  }
267
243
  function getHbcVersion(buf) {
268
- if (buf.length < HBC_HEADER_SIZE)
244
+ if (buf.length < exports.HBC_HEADER_SIZE)
269
245
  return null;
270
- if (!buf.subarray(0, 8).equals(HBC_MAGIC))
246
+ if (!buf.subarray(0, 8).equals(exports.HBC_MAGIC))
271
247
  return null;
272
248
  return buf.readUInt32LE(8);
273
249
  }
@@ -290,9 +266,9 @@ function resolveSections(buf, layout) {
290
266
  */
291
267
  function resolveSectionsFromHeader(header, fileLength, layout) {
292
268
  const headerEnd = HEADER_COUNTS_OFFSET + layout.headerFields.length * 4;
293
- if (header.length < HBC_HEADER_SIZE ||
294
- fileLength < HBC_HEADER_SIZE ||
295
- headerEnd > HBC_HEADER_SIZE) {
269
+ if (header.length < exports.HBC_HEADER_SIZE ||
270
+ fileLength < exports.HBC_HEADER_SIZE ||
271
+ headerEnd > exports.HBC_HEADER_SIZE) {
296
272
  return null;
297
273
  }
298
274
  const counts = {};
@@ -303,12 +279,12 @@ function resolveSectionsFromHeader(header, fileLength, layout) {
303
279
  return null;
304
280
  const debugInfoOffset = counts.debugInfoOffset;
305
281
  if (!Number.isInteger(debugInfoOffset) ||
306
- debugInfoOffset < HBC_HEADER_SIZE ||
282
+ debugInfoOffset < exports.HBC_HEADER_SIZE ||
307
283
  debugInfoOffset > fileLength) {
308
284
  return null;
309
285
  }
310
286
  const resolved = [];
311
- let off = HBC_HEADER_SIZE;
287
+ let off = exports.HBC_HEADER_SIZE;
312
288
  for (const desc of layout.sections) {
313
289
  const count = counts[desc.countField];
314
290
  if (count === undefined || count > 0x0fffffff)
@@ -346,6 +322,7 @@ function resolveHbcSections(header, fileLength) {
346
322
  if (resolved) {
347
323
  return {
348
324
  version,
325
+ layout,
349
326
  sections: new Map(resolved.map((s) => [s.desc.name, { start: s.start, size: s.size }])),
350
327
  };
351
328
  }
@@ -426,9 +403,9 @@ function applyDeltaSections(out, sections, inverse) {
426
403
  /** 读取文件头 128 字节与总长;文件过短或非 HBC 时返回 null。 */
427
404
  async function readHbcFileHeader(filePath) {
428
405
  const { size } = await (0, promises_1.stat)(filePath);
429
- if (size < HBC_HEADER_SIZE)
406
+ if (size < exports.HBC_HEADER_SIZE)
430
407
  return null;
431
- const header = Buffer.alloc(HBC_HEADER_SIZE);
408
+ const header = Buffer.alloc(exports.HBC_HEADER_SIZE);
432
409
  const handle = await (0, promises_1.open)(filePath, 'r');
433
410
  try {
434
411
  await readExact(handle, header, 0);
@@ -498,31 +475,34 @@ async function transformHbcFile(src, dst, layout, inverse) {
498
475
  return true;
499
476
  }
500
477
  exports.HBC_TRANSFORM_VERSION = 1;
478
+ /** 两侧共同的 HBC 版本;任一侧不是 HBC 或版本不同时为 null */
479
+ function sharedHbcVersion(oldHeader, newHeader) {
480
+ const version = getHbcVersion(newHeader);
481
+ return version !== null && getHbcVersion(oldHeader) === version
482
+ ? version
483
+ : null;
484
+ }
485
+ function transformMeta(hbcVersion, layout) {
486
+ return {
487
+ v: exports.HBC_TRANSFORM_VERSION,
488
+ hbcVersion,
489
+ layout: compileLayoutToWire(layout),
490
+ };
491
+ }
501
492
  /**
502
493
  * 若 old/new 均为同版本且存在两侧都通过结构校验的候选布局,返回变换结果、
503
494
  * 选中布局与写入 __diff.json 的元数据;否则返回 null。
504
495
  */
505
496
  function tryTransformPair(oldBuf, newBuf) {
506
- const oldVersion = getHbcVersion(oldBuf);
507
- const newVersion = getHbcVersion(newBuf);
508
- if (oldVersion === null || newVersion === null || oldVersion !== newVersion) {
497
+ const version = sharedHbcVersion(oldBuf, newBuf);
498
+ if (version === null)
509
499
  return null;
510
- }
511
- for (const layout of findLayouts(newVersion)) {
500
+ for (const layout of findLayouts(version)) {
512
501
  const tOld = transformHbcWithLayout(oldBuf, layout, false);
513
502
  const tNew = transformHbcWithLayout(newBuf, layout, false);
514
503
  if (!tOld || !tNew)
515
504
  continue;
516
- return {
517
- tOld,
518
- tNew,
519
- layout,
520
- meta: {
521
- v: exports.HBC_TRANSFORM_VERSION,
522
- hbcVersion: newVersion,
523
- layout: compileLayoutToWire(layout),
524
- },
525
- };
505
+ return { tOld, tNew, layout, meta: transformMeta(version, layout) };
526
506
  }
527
507
  return null;
528
508
  }
@@ -538,12 +518,10 @@ async function tryTransformPairFiles(oldPath, newPath, tOldPath, tNewPath) {
538
518
  ]);
539
519
  if (!oldInfo || !newInfo)
540
520
  return null;
541
- const oldVersion = getHbcVersion(oldInfo.header);
542
- const newVersion = getHbcVersion(newInfo.header);
543
- if (oldVersion === null || newVersion === null || oldVersion !== newVersion) {
521
+ const version = sharedHbcVersion(oldInfo.header, newInfo.header);
522
+ if (version === null)
544
523
  return null;
545
- }
546
- for (const layout of findLayouts(newVersion)) {
524
+ for (const layout of findLayouts(version)) {
547
525
  if (!resolveSectionsFromHeader(oldInfo.header, oldInfo.size, layout) ||
548
526
  !resolveSectionsFromHeader(newInfo.header, newInfo.size, layout)) {
549
527
  continue;
@@ -554,14 +532,7 @@ async function tryTransformPairFiles(oldPath, newPath, tOldPath, tNewPath) {
554
532
  ]);
555
533
  if (!tOld || !tNew)
556
534
  continue;
557
- return {
558
- layout,
559
- meta: {
560
- v: exports.HBC_TRANSFORM_VERSION,
561
- hbcVersion: newVersion,
562
- layout: compileLayoutToWire(layout),
563
- },
564
- };
535
+ return { layout, meta: transformMeta(version, layout) };
565
536
  }
566
537
  return null;
567
538
  }
@@ -80,9 +80,6 @@ export declare function classifyHermesCommand(hermesCommand: string): {
80
80
  version?: string;
81
81
  reason?: string;
82
82
  };
83
- export declare function sha256Hex(data: Buffer): string;
84
- /** sha256 of a file, streamed (a cached base can be tens of MB) */
85
- export declare function sha256File(file: string): Promise<string>;
86
83
  /** HBC version from the first bytes of a file, without reading the rest */
87
84
  export declare function readFileHbcVersion(file: string): Promise<number | null>;
88
85
  /**
@@ -176,7 +173,6 @@ interface FetchedBaseBundle {
176
173
  export declare function fetchBaseBundle(record: HermesBaseServerRecord, artifactType: BaseArtifactType, archive: string, log?: (message: string) => void, expectHbcVersion?: number): Promise<FetchedBaseBundle>;
177
174
  export interface ResolveHermesBaseParams {
178
175
  option: HermesBaseOption;
179
- hermesCommand: string;
180
176
  bytecodeVersion: number;
181
177
  appId?: string;
182
178
  cacheMaxMb?: number;
@@ -223,7 +219,7 @@ export interface HermesEquivalenceResult {
223
219
  functions: number;
224
220
  /**
225
221
  * `instruction`: literals decoded from the binary buffers at each
226
- * New*WithBuffer instruction (HBC v87–96 and v98); `buffer`: the dumped
222
+ * New*WithBuffer instruction (HBC v87–96, v98 and v99); `buffer`: the dumped
227
223
  * buffers compared as a whole (unknown layout)
228
224
  */
229
225
  literals?: 'instruction' | 'buffer';