react-native-update-cli 2.17.0 → 2.19.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 (57) hide show
  1. package/lib/api.d.ts +1 -1
  2. package/lib/api.js +140 -134
  3. package/lib/app.d.ts +2 -2
  4. package/lib/app.js +60 -107
  5. package/lib/bin.js +38 -35
  6. package/lib/bundle-pack.js +57 -77
  7. package/lib/bundle-runner.js +249 -312
  8. package/lib/bundle.js +71 -89
  9. package/lib/diff.js +224 -198
  10. package/lib/exports.js +14 -37
  11. package/lib/index.js +16 -17
  12. package/lib/install.js +24 -37
  13. package/lib/locales/en.d.ts +1 -0
  14. package/lib/locales/en.js +4 -11
  15. package/lib/locales/zh.d.ts +1 -0
  16. package/lib/locales/zh.js +4 -11
  17. package/lib/package.js +164 -218
  18. package/lib/provider.js +85 -107
  19. package/lib/types.js +1 -3
  20. package/lib/user.d.ts +1 -1
  21. package/lib/user.js +26 -39
  22. package/lib/utils/add-gitignore.js +16 -29
  23. package/lib/utils/app-info-parser/aab.js +133 -157
  24. package/lib/utils/app-info-parser/apk.js +42 -39
  25. package/lib/utils/app-info-parser/app.js +5 -11
  26. package/lib/utils/app-info-parser/index.js +21 -31
  27. package/lib/utils/app-info-parser/ipa.js +35 -35
  28. package/lib/utils/app-info-parser/resource-finder.js +84 -71
  29. package/lib/utils/app-info-parser/utils.js +52 -77
  30. package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
  31. package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
  32. package/lib/utils/app-info-parser/zip.js +43 -51
  33. package/lib/utils/check-lockfile.js +28 -37
  34. package/lib/utils/check-plugin.js +16 -32
  35. package/lib/utils/command-result.js +7 -20
  36. package/lib/utils/constants.js +23 -63
  37. package/lib/utils/dep-versions.js +21 -27
  38. package/lib/utils/git.js +20 -64
  39. package/lib/utils/hbcTransform.js +133 -246
  40. package/lib/utils/http-helper.js +33 -44
  41. package/lib/utils/i18n.js +17 -26
  42. package/lib/utils/index.js +137 -179
  43. package/lib/utils/latest-version/index.js +128 -137
  44. package/lib/utils/options.js +13 -34
  45. package/lib/utils/plugin-config.js +43 -56
  46. package/lib/utils/runtime.js +50 -108
  47. package/lib/utils/zip-entries.js +70 -97
  48. package/lib/utils/zip-options.js +80 -181
  49. package/lib/versions.js +231 -265
  50. package/package.json +19 -20
  51. package/src/api.ts +44 -3
  52. package/src/diff.ts +129 -2
  53. package/src/locales/en.ts +2 -0
  54. package/src/locales/zh.ts +2 -0
  55. package/src/package.ts +1 -1
  56. package/src/user.ts +1 -1
  57. package/src/versions.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
@@ -32,7 +32,7 @@
32
32
  "cli.json"
33
33
  ],
34
34
  "scripts": {
35
- "build": "rm -rf lib && swc src -d lib --strip-leading-paths && bun run typecheck:build && chmod +x lib/bin.js lib/bin-cresc.js",
35
+ "build": "rm -rf lib && tsc -p tsconfig.build.json && chmod +x lib/bin.js lib/bin-cresc.js",
36
36
  "prepublishOnly": "bun run build",
37
37
  "typecheck": "tsc --noEmit",
38
38
  "typecheck:build": "tsc -p tsconfig.build.json",
@@ -62,25 +62,25 @@
62
62
  "bplist-parser": "^0.3.2",
63
63
  "bytebuffer": "^5.0.1",
64
64
  "cgbi-to-png": "^1.0.7",
65
- "chalk": "4",
65
+ "chalk": "5",
66
66
  "cli-arguments": "^0.2.1",
67
67
  "compare-versions": "^6.1.1",
68
68
  "filesize-parser": "^1.5.1",
69
- "form-data": "^4.0.5",
70
- "fs-extra": "^11.3.5",
69
+ "form-data": "^4.0.6",
70
+ "fs-extra": "^11.3.6",
71
71
  "global-dirs": "^4.0.0",
72
72
  "gradle-to-js": "^2.0.1",
73
- "i18next": "^26.0.4",
73
+ "i18next": "^26.3.5",
74
74
  "node-fetch": "^2.6.1",
75
- "plist": "^3.1.0",
75
+ "plist": "^5.0.0",
76
76
  "progress": "^2.0.3",
77
77
  "properties": "^1.2.1",
78
- "protobufjs": "^7.5.4",
78
+ "protobufjs": "^8.7.0",
79
79
  "read": "^4.1.0",
80
80
  "registry-auth-token": "^5.1.1",
81
- "semver": "^7.7.4",
81
+ "semver": "^7.8.5",
82
82
  "tty-table": "5.0",
83
- "yauzl": "^3.3.0",
83
+ "yauzl": "^3.4.0",
84
84
  "yazl": "3.3.1"
85
85
  },
86
86
  "overrides": {
@@ -90,22 +90,21 @@
90
90
  "node": ">= 18.17.0"
91
91
  },
92
92
  "devDependencies": {
93
- "@biomejs/biome": "^2.4.12",
94
- "@swc/cli": "^0.8.1",
95
- "@swc/core": "^1.15.41",
96
- "@types/bun": "^1.3.12",
93
+ "@babel/parser": "^8.0.0",
94
+ "@biomejs/biome": "^2.5.3",
95
+ "@types/bun": "^1.3.14",
97
96
  "@types/filesize-parser": "^1.5.3",
98
97
  "@types/fs-extra": "^11.0.4",
99
- "@types/node": "^25.6.0",
98
+ "@types/node": "^26.1.1",
100
99
  "@types/node-fetch": "^2.6.13",
101
100
  "@types/progress": "^2.0.7",
102
101
  "@types/semver": "^7.7.1",
103
- "@types/yauzl": "^2.10.3",
104
- "@types/yazl": "^2.4.6",
105
- "typescript": "^6.0.2"
102
+ "@types/yauzl": "^3.4.0",
103
+ "@types/yazl": "^3.3.1",
104
+ "node-hdiffpatch": "^2.2.1",
105
+ "typescript": "^7.0.2"
106
106
  },
107
107
  "trustedDependencies": [
108
- "@biomejs/biome",
109
- "@swc/core"
108
+ "@biomejs/biome"
110
109
  ]
111
110
  }
package/src/api.ts CHANGED
@@ -4,10 +4,10 @@ import fs from 'fs';
4
4
  import fetch from 'node-fetch';
5
5
  import path from 'path';
6
6
  import ProgressBar from 'progress';
7
- import { getBaseUrl } from 'utils/http-helper';
8
7
  import packageJson from '../package.json';
9
8
  import type { Package, Session } from './types';
10
9
  import { credentialFile, IS_CRESC, pricingPageUrl } from './utils/constants';
10
+ import { getBaseUrl } from './utils/http-helper';
11
11
  import { t } from './utils/i18n';
12
12
  import {
13
13
  measureTcpLatency,
@@ -202,10 +202,18 @@ export const post = queryWithBody('POST');
202
202
  export const put = queryWithBody('PUT');
203
203
  export const doDelete = queryWithBody('DELETE');
204
204
 
205
- export async function uploadFile(fn: string, key?: string) {
206
- const { url, backupUrl, formData, maxSize } = await post('/upload', {
205
+ export async function uploadFile(
206
+ fn: string,
207
+ key?: string,
208
+ appId?: string | number,
209
+ ) {
210
+ // appId 用于服务端路由:绑定了自托管节点(rnu-node)的应用,
211
+ // 上传指令会指向节点或其对象存储
212
+ const resp = await post('/upload', {
207
213
  ext: path.extname(fn),
214
+ ...(appId ? { appId: Number(appId) } : {}),
208
215
  });
216
+ const { url, backupUrl, formData, maxSize } = resp;
209
217
  let realUrl = url;
210
218
  if (backupUrl) {
211
219
  if (global.USE_ACC_OSS) {
@@ -240,6 +248,39 @@ export async function uploadFile(fn: string, key?: string) {
240
248
  total: fileSize,
241
249
  });
242
250
 
251
+ // 自托管节点的 s3 直传:服务端下发预签名 PUT,字节直达用户的对象存储
252
+ if (resp.method === 'PUT') {
253
+ const fileStream = fs.createReadStream(fn);
254
+ fileStream.on('data', (data) => {
255
+ bar.tick(data.length);
256
+ });
257
+ let putRes: fetch.Response;
258
+ try {
259
+ putRes = await fetch(realUrl, {
260
+ method: 'PUT',
261
+ body: fileStream,
262
+ // 预签名 PUT 不接受 chunked 传输,必须显式声明长度
263
+ headers: { 'content-length': String(fileSize), ...(resp.headers || {}) },
264
+ });
265
+ } catch (error) {
266
+ if (isProxyRelatedError(error)) {
267
+ const rawMessage =
268
+ error instanceof Error ? error.message : String(error);
269
+ throw new Error(
270
+ `${rawMessage}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
271
+ );
272
+ }
273
+ throw createRequestError(error, realUrl);
274
+ }
275
+ if (putRes.status > 299) {
276
+ throw createRequestError(
277
+ `${putRes.status}: ${putRes.statusText || 'Upload failed'}`,
278
+ realUrl,
279
+ );
280
+ }
281
+ return { hash: resp.key };
282
+ }
283
+
243
284
  const form = new FormData();
244
285
 
245
286
  for (const [k, v] of Object.entries(formData)) {
package/src/diff.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as fs from 'fs-extra';
2
2
  import { npm, yarn } from 'global-dirs';
3
+ import os from 'os';
3
4
  import path from 'path';
4
5
  import type { Entry, ZipFile as YauzlZipFile } from 'yauzl';
5
6
  import { ZipFile as YazlZipFile } from 'yazl';
@@ -29,9 +30,23 @@ type Diff = (
29
30
  newSource?: Buffer,
30
31
  ) => Buffer | Promise<Buffer>;
31
32
  type Patch = (oldSource: Buffer, diffData: Buffer) => Buffer;
33
+ type DiffStream = (
34
+ oldPath: string,
35
+ newPath: string,
36
+ outDiffPath: string,
37
+ ) => unknown | Promise<unknown>;
38
+ type PatchStream = (
39
+ oldPath: string,
40
+ diffPath: string,
41
+ outNewPath: string,
42
+ ) => unknown | Promise<unknown>;
32
43
  type HdiffModule = {
33
44
  diff?: Diff;
34
45
  patch?: Patch;
46
+ diffStream?: DiffStream;
47
+ patchStream?: PatchStream;
48
+ diffSingleStream?: DiffStream;
49
+ patchSingleStream?: PatchStream;
35
50
  };
36
51
  type EntryMap = Record<string, { crc32: number; fileName: string }>;
37
52
  type CrcMap = Record<number, string>;
@@ -93,8 +108,72 @@ type BundleDiffOptions = {
93
108
  patchFn?: Patch;
94
109
  /** 测试用:覆写跳过变换尝试的 baseline 大小下限 */
95
110
  minBaselineBytes?: number;
111
+ /**
112
+ * bundle 尺寸达到该字节数时改走流式 diff:生成端内存 O(块匹配),
113
+ * 彻底绕开内存 diff 的后缀数组峰值(~6× bundle)。0/未设 = 关闭。
114
+ * 优先使用 single 格式流式生成(diffSingleStream,产物与 diff() 同格式,
115
+ * 老客户端可直接应用,任何轨道均可开启);仅当 single 流式不可用时回退
116
+ * HDIFF13(diffStream)——该格式老客户端不识别,只应在 v2 轨道下开启。
117
+ */
118
+ streamThresholdBytes?: number;
119
+ diffStreamFn?: DiffStream;
120
+ patchStreamFn?: PatchStream;
121
+ /** 流式产物是否为 single 格式(决定 baseline 轨道是否可用) */
122
+ streamEmitsSingleFormat?: boolean;
96
123
  };
97
124
 
125
+ /**
126
+ * 大 bundle 流式路径:可选 HBC 变换(在 buffer 上做,写临时文件)后
127
+ * diffStream 生成 HDIFF13,并以 patchStream + T⁻¹ 做 round-trip 自检。
128
+ * 自检失败直接抛错(此路径没有 baseline 可回退——内存 diff 正是要避免的),
129
+ * 由上层按任务失败重试/告警处理。
130
+ */
131
+ async function buildStreamBundlePatch(
132
+ originSource: Buffer,
133
+ newSource: Buffer,
134
+ options: BundleDiffOptions,
135
+ ): Promise<{ patchData: Buffer; hbcTransform?: HbcTransformMeta }> {
136
+ const diffStreamFn = options.diffStreamFn;
137
+ const patchStreamFn = options.patchStreamFn;
138
+ if (!diffStreamFn || !patchStreamFn) {
139
+ throw new Error(
140
+ 'stream diff requires diffStream/patchStream from node-hdiffpatch',
141
+ );
142
+ }
143
+
144
+ const pair = options.hbcTransform
145
+ ? tryTransformPair(originSource, newSource)
146
+ : null;
147
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-stream-diff-'));
148
+ try {
149
+ const oldFile = path.join(tempRoot, 'old.bin');
150
+ const newFile = path.join(tempRoot, 'new.bin');
151
+ const patchFile = path.join(tempRoot, 'patch.bin');
152
+ const restoredFile = path.join(tempRoot, 'restored.bin');
153
+ fs.writeFileSync(oldFile, pair ? pair.tOld : originSource);
154
+ fs.writeFileSync(newFile, pair ? pair.tNew : newSource);
155
+
156
+ await diffStreamFn(oldFile, newFile, patchFile);
157
+
158
+ // round-trip 自检:patchStream 还原(变换域则再做 T⁻¹)必须与新 bundle 一致
159
+ await patchStreamFn(oldFile, patchFile, restoredFile);
160
+ const restoredRaw: Buffer = fs.readFileSync(restoredFile);
161
+ const restored = pair
162
+ ? transformHbcWithLayout(restoredRaw, pair.layout, true)
163
+ : restoredRaw;
164
+ if (!restored || Buffer.compare(restored, newSource) !== 0) {
165
+ throw new Error('stream diff round-trip verification failed');
166
+ }
167
+
168
+ return {
169
+ patchData: fs.readFileSync(patchFile),
170
+ ...(pair ? { hbcTransform: pair.meta } : {}),
171
+ };
172
+ } finally {
173
+ fs.rmSync(tempRoot, { recursive: true, force: true });
174
+ }
175
+ }
176
+
98
177
  /**
99
178
  * 生成 bundle patch:默认现状路径;开启 hbcTransform 时对 Hermes bundle
100
179
  * 做双候选择优(baseline vs 变换域 + 元数据开销),且变换候选必须通过
@@ -106,6 +185,15 @@ async function buildBundlePatch(
106
185
  newSource: Buffer,
107
186
  options: BundleDiffOptions,
108
187
  ): Promise<{ patchData: Buffer; hbcTransform?: HbcTransformMeta }> {
188
+ if (
189
+ options.streamThresholdBytes &&
190
+ originSource &&
191
+ Math.max(originSource.length, newSource.length) >=
192
+ options.streamThresholdBytes
193
+ ) {
194
+ return buildStreamBundlePatch(originSource, newSource, options);
195
+ }
196
+
109
197
  const baseline = await diffFn(originSource, newSource);
110
198
  if (
111
199
  !options.hbcTransform ||
@@ -422,8 +510,13 @@ async function diffFromPackage(
422
510
  type DiffCommandOptions = {
423
511
  customDiff?: Diff;
424
512
  customPatch?: Patch;
513
+ customDiffStream?: DiffStream;
514
+ customPatchStream?: PatchStream;
515
+ customDiffSingleStream?: DiffStream;
516
+ customPatchSingleStream?: PatchStream;
425
517
  customHdiffModule?: HdiffModule;
426
518
  hbcTransform?: boolean;
519
+ bundleStreamThreshold?: number;
427
520
  [key: string]: any;
428
521
  };
429
522
 
@@ -453,17 +546,51 @@ function resolvePatchImplementation(
453
546
  function resolveBundleDiffOptions(
454
547
  options: DiffCommandOptions,
455
548
  ): BundleDiffOptions {
549
+ const hdiffModule = options.customHdiffModule ?? hdiff;
550
+ const streamOptions: Pick<
551
+ BundleDiffOptions,
552
+ | 'streamThresholdBytes'
553
+ | 'diffStreamFn'
554
+ | 'patchStreamFn'
555
+ | 'streamEmitsSingleFormat'
556
+ > = {};
557
+ if (
558
+ typeof options.bundleStreamThreshold === 'number' &&
559
+ options.bundleStreamThreshold > 0
560
+ ) {
561
+ const singleDiffStreamFn =
562
+ options.customDiffSingleStream ?? hdiffModule?.diffSingleStream;
563
+ const singlePatchStreamFn =
564
+ options.customPatchSingleStream ?? hdiffModule?.patchSingleStream;
565
+ const diffStreamFn = options.customDiffStream ?? hdiffModule?.diffStream;
566
+ const patchStreamFn = options.customPatchStream ?? hdiffModule?.patchStream;
567
+ if (singleDiffStreamFn && singlePatchStreamFn) {
568
+ streamOptions.streamThresholdBytes = options.bundleStreamThreshold;
569
+ streamOptions.diffStreamFn = singleDiffStreamFn;
570
+ streamOptions.patchStreamFn = singlePatchStreamFn;
571
+ streamOptions.streamEmitsSingleFormat = true;
572
+ } else if (diffStreamFn && patchStreamFn) {
573
+ streamOptions.streamThresholdBytes = options.bundleStreamThreshold;
574
+ streamOptions.diffStreamFn = diffStreamFn;
575
+ streamOptions.patchStreamFn = patchStreamFn;
576
+ streamOptions.streamEmitsSingleFormat = false;
577
+ } else {
578
+ console.warn(t('bundleStreamNeedsHdiffpatch'));
579
+ }
580
+ }
581
+
456
582
  if (!options.hbcTransform) {
457
- return {};
583
+ return { ...streamOptions };
458
584
  }
459
585
  const patchFn = resolvePatchImplementation(options);
460
586
  if (!patchFn) {
461
587
  console.warn(t('hbcTransformNeedsPatch'));
462
- return {};
588
+ return { ...streamOptions };
463
589
  }
464
590
  return {
465
591
  hbcTransform: true,
466
592
  patchFn,
593
+ ...streamOptions,
467
594
  ...(typeof options.hbcTransformMinBaseline === 'number'
468
595
  ? { minBaselineBytes: options.hbcTransformMinBaseline }
469
596
  : {}),
package/src/locales/en.ts CHANGED
@@ -187,6 +187,8 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
187
187
  'HBC transform round-trip verification failed; falling back to plain diff.',
188
188
  hbcTransformNeedsPatch:
189
189
  'hbcTransform requires patch support from node-hdiffpatch; option ignored.',
190
+ bundleStreamNeedsHdiffpatch:
191
+ 'bundleStreamThreshold requires diffStream/patchStream from node-hdiffpatch; option ignored.',
190
192
  apkExtracted: 'APK extracted to {{output}}',
191
193
  composeSourceMapsNotFound:
192
194
  'Cannot find react-native/scripts/compose-source-maps.js, skipping hermes sourcemap composing. The uploaded sourcemap may not match the compiled bundle.',
package/src/locales/zh.ts CHANGED
@@ -172,6 +172,8 @@ export default {
172
172
  'HBC 变换 round-trip 自检未通过,已回退普通 diff。',
173
173
  hbcTransformNeedsPatch:
174
174
  'hbcTransform 需要 node-hdiffpatch 的 patch 能力,选项已忽略。',
175
+ bundleStreamNeedsHdiffpatch:
176
+ 'bundleStreamThreshold 需要 node-hdiffpatch 的 diffStream/patchStream 能力,选项已忽略。',
175
177
  apkExtracted: 'APK 已提取到 {{output}}',
176
178
  composeSourceMapsNotFound:
177
179
  '找不到 react-native/scripts/compose-source-maps.js,跳过 hermes sourcemap 合成。上传的 sourcemap 可能与编译后的 bundle 不匹配。',
package/src/package.ts CHANGED
@@ -141,7 +141,7 @@ async function uploadNativePackage(
141
141
  console.log(t('usingCustomVersion', { version: versionName }));
142
142
  }
143
143
 
144
- const { hash } = await uploadFile(filePath);
144
+ const { hash } = await uploadFile(filePath, undefined, appId);
145
145
  const normalizedBuildTime = config.normalizeBuildTime
146
146
  ? config.normalizeBuildTime(buildTime)
147
147
  : buildTime;
package/src/user.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import crypto from 'crypto';
2
- import type { CommandContext } from 'types';
3
2
  import { closeSession, get, post, replaceSession, saveSession } from './api';
3
+ import type { CommandContext } from './types';
4
4
  import { question } from './utils';
5
5
  import { t } from './utils/i18n';
6
6
 
package/src/versions.ts CHANGED
@@ -475,7 +475,7 @@ export const versionCommands = {
475
475
  const nonInteractive =
476
476
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
477
477
 
478
- const { hash } = await uploadFile(fn);
478
+ const { hash } = await uploadFile(fn, undefined, appId);
479
479
 
480
480
  const versionName =
481
481
  name ||