rn-update-cli 1.0.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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/README.zh-CN.md +167 -0
  4. package/cli.json +525 -0
  5. package/lib/api.d.ts +56 -0
  6. package/lib/api.js +671 -0
  7. package/lib/app.d.ts +107 -0
  8. package/lib/app.js +329 -0
  9. package/lib/auto-update.d.ts +35 -0
  10. package/lib/auto-update.js +507 -0
  11. package/lib/bin.d.ts +2 -0
  12. package/lib/bin.js +133 -0
  13. package/lib/bundle-pack.d.ts +6 -0
  14. package/lib/bundle-pack.js +91 -0
  15. package/lib/bundle-runner.d.ts +168 -0
  16. package/lib/bundle-runner.js +1305 -0
  17. package/lib/bundle.d.ts +45 -0
  18. package/lib/bundle.js +226 -0
  19. package/lib/cache.d.ts +10 -0
  20. package/lib/cache.js +25 -0
  21. package/lib/commands.d.ts +11 -0
  22. package/lib/commands.js +72 -0
  23. package/lib/diff.d.ts +18 -0
  24. package/lib/diff.js +690 -0
  25. package/lib/exports.d.ts +11 -0
  26. package/lib/exports.js +20 -0
  27. package/lib/install.d.ts +9 -0
  28. package/lib/install.js +51 -0
  29. package/lib/locales/en.d.ts +187 -0
  30. package/lib/locales/en.js +194 -0
  31. package/lib/locales/zh.d.ts +187 -0
  32. package/lib/locales/zh.js +194 -0
  33. package/lib/native-package.d.ts +21 -0
  34. package/lib/native-package.js +298 -0
  35. package/lib/package.d.ts +68 -0
  36. package/lib/package.js +487 -0
  37. package/lib/provider.d.ts +24 -0
  38. package/lib/provider.js +244 -0
  39. package/lib/standalone-publish.d.ts +17 -0
  40. package/lib/standalone-publish.js +433 -0
  41. package/lib/symbolicate.d.ts +35 -0
  42. package/lib/symbolicate.js +130 -0
  43. package/lib/types.d.ts +152 -0
  44. package/lib/types.js +2 -0
  45. package/lib/user.d.ts +8 -0
  46. package/lib/user.js +50 -0
  47. package/lib/utils/add-gitignore.d.ts +6 -0
  48. package/lib/utils/add-gitignore.js +44 -0
  49. package/lib/utils/app-info-parser/aab.d.ts +27 -0
  50. package/lib/utils/app-info-parser/aab.js +256 -0
  51. package/lib/utils/app-info-parser/apk.d.ts +19 -0
  52. package/lib/utils/app-info-parser/apk.js +95 -0
  53. package/lib/utils/app-info-parser/app.d.ts +9 -0
  54. package/lib/utils/app-info-parser/app.js +15 -0
  55. package/lib/utils/app-info-parser/index.d.ts +21 -0
  56. package/lib/utils/app-info-parser/index.js +51 -0
  57. package/lib/utils/app-info-parser/ipa.d.ts +19 -0
  58. package/lib/utils/app-info-parser/ipa.js +101 -0
  59. package/lib/utils/app-info-parser/resource-finder.d.ts +49 -0
  60. package/lib/utils/app-info-parser/resource-finder.js +429 -0
  61. package/lib/utils/app-info-parser/utils.d.ts +36 -0
  62. package/lib/utils/app-info-parser/utils.js +140 -0
  63. package/lib/utils/app-info-parser/xml-parser/binary.d.ts +61 -0
  64. package/lib/utils/app-info-parser/xml-parser/binary.js +577 -0
  65. package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +15 -0
  66. package/lib/utils/app-info-parser/xml-parser/manifest.js +207 -0
  67. package/lib/utils/app-info-parser/zip.d.ts +29 -0
  68. package/lib/utils/app-info-parser/zip.js +97 -0
  69. package/lib/utils/check-lockfile.d.ts +6 -0
  70. package/lib/utils/check-lockfile.js +93 -0
  71. package/lib/utils/check-plugin.d.ts +12 -0
  72. package/lib/utils/check-plugin.js +36 -0
  73. package/lib/utils/command-result.d.ts +8 -0
  74. package/lib/utils/command-result.js +27 -0
  75. package/lib/utils/constants.d.ts +10 -0
  76. package/lib/utils/constants.js +39 -0
  77. package/lib/utils/dep-versions.d.ts +20 -0
  78. package/lib/utils/dep-versions.js +129 -0
  79. package/lib/utils/git.d.ts +14 -0
  80. package/lib/utils/git.js +64 -0
  81. package/lib/utils/hbcTransform.d.ts +111 -0
  82. package/lib/utils/hbcTransform.js +561 -0
  83. package/lib/utils/hermes-base.d.ts +227 -0
  84. package/lib/utils/hermes-base.js +1287 -0
  85. package/lib/utils/hermes-literals.d.ts +64 -0
  86. package/lib/utils/hermes-literals.js +260 -0
  87. package/lib/utils/http-helper.d.ts +10 -0
  88. package/lib/utils/http-helper.js +150 -0
  89. package/lib/utils/i18n.d.ts +22 -0
  90. package/lib/utils/i18n.js +46 -0
  91. package/lib/utils/index.d.ts +67 -0
  92. package/lib/utils/index.js +545 -0
  93. package/lib/utils/latest-version/index.d.ts +154 -0
  94. package/lib/utils/latest-version/index.js +331 -0
  95. package/lib/utils/options.d.ts +10 -0
  96. package/lib/utils/options.js +68 -0
  97. package/lib/utils/plugin-config.d.ts +14 -0
  98. package/lib/utils/plugin-config.js +66 -0
  99. package/lib/utils/runtime.d.ts +54 -0
  100. package/lib/utils/runtime.js +263 -0
  101. package/lib/utils/slim-sourcemap.d.ts +28 -0
  102. package/lib/utils/slim-sourcemap.js +106 -0
  103. package/lib/utils/zip-entries.d.ts +10 -0
  104. package/lib/utils/zip-entries.js +211 -0
  105. package/lib/utils/zip-options.d.ts +17 -0
  106. package/lib/utils/zip-options.js +190 -0
  107. package/lib/utils/zip-range.d.ts +148 -0
  108. package/lib/utils/zip-range.js +581 -0
  109. package/lib/utils/zip-raw-writer.d.ts +52 -0
  110. package/lib/utils/zip-raw-writer.js +209 -0
  111. package/lib/version-operations.d.ts +21 -0
  112. package/lib/version-operations.js +320 -0
  113. package/lib/versions.d.ts +66 -0
  114. package/lib/versions.js +402 -0
  115. package/package.json +113 -0
  116. package/proto/Configuration.proto +183 -0
  117. package/proto/Resources.proto +569 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ /**
3
+ * [INPUT]: 依赖项目 package.json、已安装依赖目录、文件系统与路径解析
4
+ * [OUTPUT]: 对外提供 getDepVersions、getDepVersion 与惰性 depVersions 代理
5
+ * [POS]: CLI 运行时版本信息边界,按需读取依赖版本并缓存,供诊断和命令编排消费
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.depVersions = void 0;
12
+ exports.getDepVersions = getDepVersions;
13
+ exports.getDepVersion = getDepVersion;
14
+ // Installed versions of the dependencies/devDependencies of the project in
15
+ // cwd. Resolving them means reading one package.json per dependency, so the
16
+ // full map is built lazily (on first use) and memoized rather than at import
17
+ // time, and the version banner printed by every command asks for the single
18
+ // dependency it needs (`getDepVersion`) instead of the whole map.
19
+ const fs_1 = __importDefault(require("fs"));
20
+ const path_1 = __importDefault(require("path"));
21
+ let cachedCwd;
22
+ let cached;
23
+ function readProjectPackageJson(cwd) {
24
+ try {
25
+ return JSON.parse(fs_1.default.readFileSync(path_1.default.join(cwd, 'package.json'), 'utf8'));
26
+ }
27
+ catch {
28
+ // no package.json (or not JSON): the project simply declares nothing
29
+ return null;
30
+ }
31
+ }
32
+ /** direct dependency names (dependencies + devDependencies), deduplicated */
33
+ function directDependencyNames(pkg) {
34
+ return [
35
+ ...new Set([
36
+ ...Object.keys(pkg.dependencies ?? {}),
37
+ ...Object.keys(pkg.devDependencies ?? {}),
38
+ ]),
39
+ ];
40
+ }
41
+ /**
42
+ * Version of the installed copy of `dep`: the nearest
43
+ * `node_modules/<dep>/package.json` from `cwd` upwards, read directly. Not
44
+ * `require.resolve`: a package whose `exports` map omits package.json makes
45
+ * it throw, and bun caches its answer per specifier, ignoring `paths`.
46
+ */
47
+ function readInstalledVersion(dep, cwd) {
48
+ let dir = path_1.default.resolve(cwd);
49
+ for (;;) {
50
+ try {
51
+ const pkg = JSON.parse(fs_1.default.readFileSync(path_1.default.join(dir, 'node_modules', dep, 'package.json'), 'utf8'));
52
+ return typeof pkg.version === 'string' ? pkg.version : undefined;
53
+ }
54
+ catch {
55
+ // not installed at this level
56
+ }
57
+ const parent = path_1.default.dirname(dir);
58
+ if (parent === dir) {
59
+ return undefined;
60
+ }
61
+ dir = parent;
62
+ }
63
+ }
64
+ function readDepVersions(cwd) {
65
+ const versions = {};
66
+ const pkg = readProjectPackageJson(cwd);
67
+ if (pkg) {
68
+ for (const dep of directDependencyNames(pkg)) {
69
+ const version = readInstalledVersion(dep, cwd);
70
+ if (version) {
71
+ versions[dep] = version;
72
+ }
73
+ }
74
+ }
75
+ // sorted keys: the object is sent to the server as-is and diffed
76
+ return Object.keys(versions)
77
+ .sort()
78
+ .reduce((obj, key) => {
79
+ obj[key] = versions[key];
80
+ return obj;
81
+ }, {});
82
+ }
83
+ /** Installed versions of the cwd project's dependencies, keys sorted. */
84
+ function getDepVersions() {
85
+ const cwd = path_1.default.resolve(process.cwd());
86
+ if (!cached || cachedCwd !== cwd) {
87
+ cached = readDepVersions(cwd);
88
+ cachedCwd = cwd;
89
+ }
90
+ return cached;
91
+ }
92
+ /**
93
+ * Installed version of one direct (dev)dependency of the cwd project, or
94
+ * undefined when the project does not declare it or it is not installed.
95
+ * Two file reads instead of one per dependency: the version banner printed
96
+ * before every command must not scale with the size of the project.
97
+ */
98
+ function getDepVersion(name, cwd = process.cwd()) {
99
+ const resolvedCwd = path_1.default.resolve(cwd);
100
+ if (cached && cachedCwd === resolvedCwd) {
101
+ return cached[name];
102
+ }
103
+ const pkg = readProjectPackageJson(resolvedCwd);
104
+ if (!pkg || !directDependencyNames(pkg).includes(name)) {
105
+ return undefined;
106
+ }
107
+ return readInstalledVersion(name, resolvedCwd);
108
+ }
109
+ /**
110
+ * Same data as `getDepVersions()` but as a lazily populated object, for the
111
+ * remaining property-access call sites (`depVersions['react-native']`).
112
+ * Nothing is resolved until the first property access.
113
+ */
114
+ exports.depVersions = new Proxy({}, {
115
+ get: (_target, key) => typeof key === 'string' ? getDepVersions()[key] : undefined,
116
+ has: (_target, key) => typeof key === 'string' && key in getDepVersions(),
117
+ ownKeys: () => Object.keys(getDepVersions()),
118
+ getOwnPropertyDescriptor: (_target, key) => {
119
+ if (typeof key !== 'string' || !(key in getDepVersions())) {
120
+ return undefined;
121
+ }
122
+ return {
123
+ value: getDepVersions()[key],
124
+ writable: false,
125
+ enumerable: true,
126
+ configurable: true,
127
+ };
128
+ },
129
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * [INPUT]: 依赖 Git 子进程、回调转 Promise 与当前工作树状态
3
+ * [OUTPUT]: 对外提供 CommitInfo、getCurrentCommit 与 getCommitInfo
4
+ * [POS]: CLI 版本元数据适配层,只读取提交信息,不修改仓库状态
5
+ */
6
+ export interface CommitInfo {
7
+ hash: string;
8
+ message: string;
9
+ author: string;
10
+ timestamp: string;
11
+ origin?: string;
12
+ }
13
+ export declare function getCurrentCommit(): string;
14
+ export declare function getCommitInfo(): Promise<CommitInfo | undefined>;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * [INPUT]: 依赖 Git 子进程、回调转 Promise 与当前工作树状态
4
+ * [OUTPUT]: 对外提供 CommitInfo、getCurrentCommit 与 getCommitInfo
5
+ * [POS]: CLI 版本元数据适配层,只读取提交信息,不修改仓库状态
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getCurrentCommit = getCurrentCommit;
9
+ exports.getCommitInfo = getCommitInfo;
10
+ const child_process_1 = require("child_process");
11
+ const util_1 = require("util");
12
+ const execFile = (0, util_1.promisify)(child_process_1.execFile);
13
+ function getCurrentCommit() {
14
+ const result = (0, child_process_1.spawnSync)('git', ['rev-parse', 'HEAD']);
15
+ if (result.status !== 0) {
16
+ throw new Error('Not a git repository');
17
+ }
18
+ return result.stdout.toString().trim();
19
+ }
20
+ async function gitOutput(args, cwd = process.cwd()) {
21
+ const { stdout } = await execFile('git', args, {
22
+ cwd,
23
+ encoding: 'utf8',
24
+ windowsHide: true,
25
+ });
26
+ return stdout.trimEnd();
27
+ }
28
+ async function getRemoteOrigin(cwd) {
29
+ const origin = await gitOutput(['remote', 'get-url', 'origin'], cwd).catch(() => '');
30
+ if (origin) {
31
+ return origin;
32
+ }
33
+ const remotes = await gitOutput(['remote'], cwd).catch(() => '');
34
+ const firstRemote = remotes.split(/\r?\n/).find(Boolean);
35
+ if (!firstRemote) {
36
+ return undefined;
37
+ }
38
+ return gitOutput(['remote', 'get-url', firstRemote], cwd).catch(() => undefined);
39
+ }
40
+ async function getCommitInfo() {
41
+ try {
42
+ const gitRoot = await gitOutput(['rev-parse', '--show-toplevel']);
43
+ // one `git log` for every commit field (NUL-separated, the multi-line
44
+ // message last) instead of one git process per field
45
+ const [log, origin] = await Promise.all([
46
+ gitOutput(['log', '-1', '--format=%H%x00%an%x00%ct%x00%B'], gitRoot),
47
+ getRemoteOrigin(gitRoot),
48
+ ]);
49
+ const [hash, author, timestamp, ...message] = log.split('\0');
50
+ if (!hash) {
51
+ return;
52
+ }
53
+ return {
54
+ hash,
55
+ message: message.join('\0'),
56
+ author,
57
+ timestamp,
58
+ origin,
59
+ };
60
+ }
61
+ catch (_error) {
62
+ return;
63
+ }
64
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * [INPUT]: 依赖 Hermes HBC 二进制布局、Buffer/文件句柄与差分字段规则
3
+ * [OUTPUT]: 对外提供 HBC 布局探测、可逆变换、文件变换、段范围解析及版本元数据能力
4
+ * [POS]: CLI Hermes delta 优化底座,为 base-bytecode 差分提供确定性字节变换
5
+ */
6
+ /** 差分字段:条目内 byte 偏移处按小端读 u32,取 [bit, bit+bits) 位。 */
7
+ type DeltaField = {
8
+ byte: number;
9
+ bit: number;
10
+ bits: number;
11
+ };
12
+ type SectionDesc = {
13
+ name: string;
14
+ /** 段大小 = header[countField] × entrySize;字节段 entrySize 为 1 */
15
+ countField: string;
16
+ entrySize: number;
17
+ deltaFields?: DeltaField[];
18
+ };
19
+ export type HbcLayout = {
20
+ minVersion: number;
21
+ maxVersion: number;
22
+ /** 头部 u32 计数字段名序列,从文件偏移 32 开始连续排列 */
23
+ headerFields: string[];
24
+ /** 各段按文件顺序排列(其后是函数字节码区,以 debugInfoOffset 为界) */
25
+ sections: SectionDesc[];
26
+ };
27
+ /**
28
+ * 布局描述表(唯一需要跟随 Hermes 版本演进的数据)。
29
+ * 字段序照抄 hermes 源码 include/hermes/BCGen/HBC/BytecodeFileFormat.h。
30
+ * v97 为 Static Hermes 短期预览版本,生产占比为零,不支持(自动回退)。
31
+ */
32
+ export declare const HBC_LAYOUTS: HbcLayout[];
33
+ /**
34
+ * 随 patch 下发的 wire 格式(客户端 C 解释器的输入,全数字、无名字):
35
+ * counts: 头部 u32 计数字段个数(从偏移 32 起连续读取)
36
+ * sections: [countIndex, entrySize, [[byte, bit, bits], ...]][]
37
+ *
38
+ * 位置约定(C 端校验依赖,两端必须一致):
39
+ * counts 槽位 0 = fileLength,最后一个槽位 = debugInfoOffset。
40
+ */
41
+ export type HbcLayoutWire = {
42
+ counts: number;
43
+ sections: [number, number, [number, number, number][]][];
44
+ };
45
+ export declare function compileLayoutToWire(layout: HbcLayout): HbcLayoutWire;
46
+ export declare function getHbcVersion(buf: Buffer): number | null;
47
+ /** 同一版本号可能有多个候选布局(按声明顺序即优先级)。 */
48
+ export declare function findLayouts(version: number): HbcLayout[];
49
+ /** Byte range of one section of an HBC file (see resolveHbcSections). */
50
+ export type HbcSectionRange = {
51
+ start: number;
52
+ size: number;
53
+ };
54
+ /**
55
+ * Section byte ranges of an HBC file from its 128-byte header and total
56
+ * length, keyed by section name (arrayBuffer, objKeyBuffer, ... for v87–96;
57
+ * literalValueBuffer, objShapeTable, ... for v98). Null when no known layout
58
+ * fits, which callers treat as "cannot read this file structurally".
59
+ */
60
+ export declare function resolveHbcSections(header: Buffer, fileLength: number): {
61
+ version: number;
62
+ sections: Map<string, HbcSectionRange>;
63
+ } | null;
64
+ /**
65
+ * 对 HBC buffer 执行变换(inverse=false)或逆变换(inverse=true)。
66
+ * 同一版本号可能存在多个候选布局(如 v98 早/晚两种头部),按声明顺序
67
+ * 取第一个通过结构校验的。非 HBC / 无可用布局 → 返回 null。
68
+ * 注意:变换不改动头部计数,同一文件正/逆向解析选中的布局必然一致。
69
+ */
70
+ export declare function transformHbc(buf: Buffer, inverse?: boolean): Buffer | null;
71
+ /** 返回该 buffer 结构上匹配的布局(候选中第一个校验通过者)。 */
72
+ export declare function pickLayout(buf: Buffer): HbcLayout | null;
73
+ export declare function transformHbcWithLayout(buf: Buffer, layout: HbcLayout, inverse: boolean): Buffer | null;
74
+ /**
75
+ * 原地变换:直接改写 buf,不再分配整块副本。调用方须持有 buf 的所有权
76
+ * (例如 patch() 刚返回的新 Buffer)。结构不匹配时返回 false 且 buf 不变。
77
+ */
78
+ export declare function transformHbcWithLayoutInPlace(buf: Buffer, layout: HbcLayout, inverse: boolean): boolean;
79
+ /**
80
+ * 文件版 transformHbcWithLayout:把 src 复制到 dst,再仅对含差分字段的
81
+ * 段(位于 [128, 最后一段末尾) 区间内)做定位读写改写。任一时刻内存中
82
+ * 只有一个段的内容,不会持有整个 bundle。输出与内存版逐字节一致。
83
+ * 结构不匹配时返回 false 并清理 dst。
84
+ */
85
+ export declare function transformHbcFile(src: string, dst: string, layout: HbcLayout, inverse: boolean): Promise<boolean>;
86
+ export declare const HBC_TRANSFORM_VERSION = 1;
87
+ export type HbcTransformMeta = {
88
+ v: number;
89
+ hbcVersion: number;
90
+ layout: HbcLayoutWire;
91
+ };
92
+ /**
93
+ * 若 old/new 均为同版本且存在两侧都通过结构校验的候选布局,返回变换结果、
94
+ * 选中布局与写入 __diff.json 的元数据;否则返回 null。
95
+ */
96
+ export declare function tryTransformPair(oldBuf: Buffer, newBuf: Buffer): {
97
+ tOld: Buffer;
98
+ tNew: Buffer;
99
+ layout: HbcLayout;
100
+ meta: HbcTransformMeta;
101
+ } | null;
102
+ /**
103
+ * tryTransformPair 的文件版:只读两侧头部即可选定布局,变换结果直接写到
104
+ * tOldPath / tNewPath,全程不把 bundle 读进内存。无可用布局时返回 null
105
+ * (不产生输出文件)。
106
+ */
107
+ export declare function tryTransformPairFiles(oldPath: string, newPath: string, tOldPath: string, tNewPath: string): Promise<{
108
+ layout: HbcLayout;
109
+ meta: HbcTransformMeta;
110
+ } | null>;
111
+ export {};