react-native-update-cli 2.16.0 → 2.17.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.
@@ -0,0 +1,506 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get HBC_LAYOUTS () {
13
+ return HBC_LAYOUTS;
14
+ },
15
+ get HBC_TRANSFORM_VERSION () {
16
+ return HBC_TRANSFORM_VERSION;
17
+ },
18
+ get compileLayoutToWire () {
19
+ return compileLayoutToWire;
20
+ },
21
+ get findLayouts () {
22
+ return findLayouts;
23
+ },
24
+ get getHbcVersion () {
25
+ return getHbcVersion;
26
+ },
27
+ get pickLayout () {
28
+ return pickLayout;
29
+ },
30
+ get transformHbc () {
31
+ return transformHbc;
32
+ },
33
+ get transformHbcWithLayout () {
34
+ return transformHbcWithLayout;
35
+ },
36
+ get tryTransformPair () {
37
+ return tryTransformPair;
38
+ }
39
+ });
40
+ /**
41
+ * Hermes 字节码(HBC)delta-friendly 可逆变换。
42
+ *
43
+ * 原理:HBC 中 functionHeaders / smallStringTable 等表的条目携带绝对偏移,
44
+ * 任意一处内容增删都会让其后所有条目的偏移整体 +N,精确匹配型 diff(hdiff)
45
+ * 无法复用这些被移位的条目。对这些偏移字段做前项差分(wrapping,模字段位宽)
46
+ * 后,整体移位在差分域退化为单点变化,diff 显著变小。
47
+ *
48
+ * 布局描述表是纯数据:解释器(本文件 + 客户端 C 版)不含任何版本分支。
49
+ * 新 Hermes 版本只需在 HBC_LAYOUTS 增加/扩展一个条目。CLI 生成 diff 时把
50
+ * 实际使用的描述表以 wire 格式写入 __diff.json,客户端按表执行 T⁻¹,
51
+ * 因此客户端无需跟进 HBC 版本。
52
+ *
53
+ * wrapping 差分与单调性无关、恒可逆:T⁻¹(T(x)) === x 对任意输入成立
54
+ * (只要两侧使用同一份描述表)。
55
+ */ const HBC_MAGIC = Buffer.from([
56
+ 0xc6,
57
+ 0x1f,
58
+ 0xbc,
59
+ 0x03,
60
+ 0xc1,
61
+ 0x03,
62
+ 0x19,
63
+ 0x1f
64
+ ]);
65
+ const HEADER_COUNTS_OFFSET = 32; // magic(8) + version(4) + sourceHash(20)
66
+ const HBC_HEADER_SIZE = 128;
67
+ const FUNC_OFFSET_25 = {
68
+ byte: 0,
69
+ bit: 0,
70
+ bits: 25
71
+ };
72
+ const STRING_OFFSET_23 = {
73
+ byte: 0,
74
+ bit: 1,
75
+ bits: 23
76
+ };
77
+ const PAIR_OFFSET_32 = {
78
+ byte: 0,
79
+ bit: 0,
80
+ bits: 32
81
+ };
82
+ // v98 两种头部变体共享的段布局
83
+ const V98_SECTIONS = [
84
+ {
85
+ name: 'functionHeaders',
86
+ countField: 'functionCount',
87
+ entrySize: 12,
88
+ deltaFields: [
89
+ FUNC_OFFSET_25
90
+ ]
91
+ },
92
+ {
93
+ name: 'stringKinds',
94
+ countField: 'stringKindCount',
95
+ entrySize: 4
96
+ },
97
+ {
98
+ name: 'identifierHashes',
99
+ countField: 'identifierCount',
100
+ entrySize: 4
101
+ },
102
+ {
103
+ name: 'smallStringTable',
104
+ countField: 'stringCount',
105
+ entrySize: 4,
106
+ deltaFields: [
107
+ STRING_OFFSET_23
108
+ ]
109
+ },
110
+ {
111
+ name: 'overflowStringTable',
112
+ countField: 'overflowStringCount',
113
+ entrySize: 8,
114
+ deltaFields: [
115
+ PAIR_OFFSET_32
116
+ ]
117
+ },
118
+ {
119
+ name: 'stringStorage',
120
+ countField: 'stringStorageSize',
121
+ entrySize: 1
122
+ },
123
+ {
124
+ name: 'literalValueBuffer',
125
+ countField: 'literalValueBufferSize',
126
+ entrySize: 1
127
+ },
128
+ {
129
+ name: 'objKeyBuffer',
130
+ countField: 'objKeyBufferSize',
131
+ entrySize: 1
132
+ },
133
+ // ShapeTableEntry 8B:{keyBufferOffset u32, numProps u32}
134
+ {
135
+ name: 'objShapeTable',
136
+ countField: 'objShapeTableCount',
137
+ entrySize: 8,
138
+ deltaFields: [
139
+ PAIR_OFFSET_32
140
+ ]
141
+ },
142
+ {
143
+ name: 'bigIntTable',
144
+ countField: 'bigIntCount',
145
+ entrySize: 8,
146
+ deltaFields: [
147
+ PAIR_OFFSET_32
148
+ ]
149
+ },
150
+ {
151
+ name: 'bigIntStorage',
152
+ countField: 'bigIntStorageSize',
153
+ entrySize: 1
154
+ },
155
+ {
156
+ name: 'regExpTable',
157
+ countField: 'regExpCount',
158
+ entrySize: 8,
159
+ deltaFields: [
160
+ PAIR_OFFSET_32
161
+ ]
162
+ },
163
+ {
164
+ name: 'regExpStorage',
165
+ countField: 'regExpStorageSize',
166
+ entrySize: 1
167
+ },
168
+ {
169
+ name: 'cjsModuleTable',
170
+ countField: 'cjsModuleCount',
171
+ entrySize: 8
172
+ },
173
+ {
174
+ name: 'functionSourceTable',
175
+ countField: 'functionSourceCount',
176
+ entrySize: 8
177
+ }
178
+ ];
179
+ const HBC_LAYOUTS = [
180
+ {
181
+ // hermes 0.12 主线(RN 0.69~0.81+),v87 引入 bigInt 字段后布局稳定
182
+ minVersion: 87,
183
+ maxVersion: 96,
184
+ headerFields: [
185
+ 'fileLength',
186
+ 'globalCodeIndex',
187
+ 'functionCount',
188
+ 'stringKindCount',
189
+ 'identifierCount',
190
+ 'stringCount',
191
+ 'overflowStringCount',
192
+ 'stringStorageSize',
193
+ 'bigIntCount',
194
+ 'bigIntStorageSize',
195
+ 'regExpCount',
196
+ 'regExpStorageSize',
197
+ 'arrayBufferSize',
198
+ 'objKeyBufferSize',
199
+ 'objValueBufferSize',
200
+ 'segmentID',
201
+ 'cjsModuleCount',
202
+ 'functionSourceCount',
203
+ 'debugInfoOffset'
204
+ ],
205
+ sections: [
206
+ // SmallFuncHeader 16B:word0 offset:25|paramCount:7,word2 infoOffset:25|frameSize:7
207
+ {
208
+ name: 'functionHeaders',
209
+ countField: 'functionCount',
210
+ entrySize: 16,
211
+ deltaFields: [
212
+ FUNC_OFFSET_25,
213
+ {
214
+ byte: 8,
215
+ bit: 0,
216
+ bits: 25
217
+ }
218
+ ]
219
+ },
220
+ {
221
+ name: 'stringKinds',
222
+ countField: 'stringKindCount',
223
+ entrySize: 4
224
+ },
225
+ {
226
+ name: 'identifierHashes',
227
+ countField: 'identifierCount',
228
+ entrySize: 4
229
+ },
230
+ // SmallStringTableEntry 4B:isUTF16:1|offset:23|length:8
231
+ {
232
+ name: 'smallStringTable',
233
+ countField: 'stringCount',
234
+ entrySize: 4,
235
+ deltaFields: [
236
+ STRING_OFFSET_23
237
+ ]
238
+ },
239
+ // OverflowStringTableEntry 8B:{offset u32, length u32}
240
+ {
241
+ name: 'overflowStringTable',
242
+ countField: 'overflowStringCount',
243
+ entrySize: 8,
244
+ deltaFields: [
245
+ PAIR_OFFSET_32
246
+ ]
247
+ },
248
+ {
249
+ name: 'stringStorage',
250
+ countField: 'stringStorageSize',
251
+ entrySize: 1
252
+ },
253
+ {
254
+ name: 'arrayBuffer',
255
+ countField: 'arrayBufferSize',
256
+ entrySize: 1
257
+ },
258
+ {
259
+ name: 'objKeyBuffer',
260
+ countField: 'objKeyBufferSize',
261
+ entrySize: 1
262
+ },
263
+ {
264
+ name: 'objValueBuffer',
265
+ countField: 'objValueBufferSize',
266
+ entrySize: 1
267
+ },
268
+ {
269
+ name: 'bigIntTable',
270
+ countField: 'bigIntCount',
271
+ entrySize: 8,
272
+ deltaFields: [
273
+ PAIR_OFFSET_32
274
+ ]
275
+ },
276
+ {
277
+ name: 'bigIntStorage',
278
+ countField: 'bigIntStorageSize',
279
+ entrySize: 1
280
+ },
281
+ {
282
+ name: 'regExpTable',
283
+ countField: 'regExpCount',
284
+ entrySize: 8,
285
+ deltaFields: [
286
+ PAIR_OFFSET_32
287
+ ]
288
+ },
289
+ {
290
+ name: 'regExpStorage',
291
+ countField: 'regExpStorageSize',
292
+ entrySize: 1
293
+ },
294
+ {
295
+ name: 'cjsModuleTable',
296
+ countField: 'cjsModuleCount',
297
+ entrySize: 8
298
+ },
299
+ {
300
+ name: 'functionSourceTable',
301
+ countField: 'functionSourceCount',
302
+ entrySize: 8
303
+ }
304
+ ]
305
+ },
306
+ {
307
+ // Static Hermes 晚期 v98(生产观测到的主流形态):相对早期 v98 头部
308
+ // 多一个 numStringSwitchImms 槽(hermes static_h 在不 bump 版本号的
309
+ // 情况下插入,同一版本号 98 因此存在两种布局,依结构校验区分)。
310
+ // 段布局与早期 v98 相同。
311
+ minVersion: 98,
312
+ maxVersion: 98,
313
+ headerFields: [
314
+ 'fileLength',
315
+ 'globalCodeIndex',
316
+ 'functionCount',
317
+ 'stringKindCount',
318
+ 'identifierCount',
319
+ 'stringCount',
320
+ 'overflowStringCount',
321
+ 'stringStorageSize',
322
+ 'bigIntCount',
323
+ 'bigIntStorageSize',
324
+ 'regExpCount',
325
+ 'regExpStorageSize',
326
+ 'literalValueBufferSize',
327
+ 'objKeyBufferSize',
328
+ 'objShapeTableCount',
329
+ 'numStringSwitchImms',
330
+ 'segmentID',
331
+ 'cjsModuleCount',
332
+ 'functionSourceCount',
333
+ 'debugInfoOffset'
334
+ ],
335
+ sections: V98_SECTIONS
336
+ },
337
+ {
338
+ // Static Hermes 早期 v98(hermes c00cc57595 时点,无 numStringSwitchImms)。
339
+ // 相对 v96:SmallFuncHeader 16B→12B(去 infoOffset/environmentSize);
340
+ // objValueBuffer(字节段)→ objShapeTable(8B 条目);
341
+ // arrayBufferSize 更名 literalValueBufferSize(槽位不变)。
342
+ minVersion: 98,
343
+ maxVersion: 98,
344
+ headerFields: [
345
+ 'fileLength',
346
+ 'globalCodeIndex',
347
+ 'functionCount',
348
+ 'stringKindCount',
349
+ 'identifierCount',
350
+ 'stringCount',
351
+ 'overflowStringCount',
352
+ 'stringStorageSize',
353
+ 'bigIntCount',
354
+ 'bigIntStorageSize',
355
+ 'regExpCount',
356
+ 'regExpStorageSize',
357
+ 'literalValueBufferSize',
358
+ 'objKeyBufferSize',
359
+ 'objShapeTableCount',
360
+ 'segmentID',
361
+ 'cjsModuleCount',
362
+ 'functionSourceCount',
363
+ 'debugInfoOffset'
364
+ ],
365
+ sections: V98_SECTIONS
366
+ }
367
+ ];
368
+ function compileLayoutToWire(layout) {
369
+ if (layout.headerFields[0] !== 'fileLength' || layout.headerFields[layout.headerFields.length - 1] !== 'debugInfoOffset') {
370
+ throw new Error('HbcLayout must start with fileLength and end with debugInfoOffset');
371
+ }
372
+ return {
373
+ counts: layout.headerFields.length,
374
+ sections: layout.sections.map((s)=>{
375
+ var _s_deltaFields;
376
+ return [
377
+ layout.headerFields.indexOf(s.countField),
378
+ s.entrySize,
379
+ ((_s_deltaFields = s.deltaFields) != null ? _s_deltaFields : []).map((f)=>[
380
+ f.byte,
381
+ f.bit,
382
+ f.bits
383
+ ])
384
+ ];
385
+ })
386
+ };
387
+ }
388
+ function getHbcVersion(buf) {
389
+ if (buf.length < HBC_HEADER_SIZE) return null;
390
+ if (!buf.subarray(0, 8).equals(HBC_MAGIC)) return null;
391
+ return buf.readUInt32LE(8);
392
+ }
393
+ function findLayouts(version) {
394
+ return HBC_LAYOUTS.filter((l)=>version >= l.minVersion && version <= l.maxVersion);
395
+ }
396
+ const align4 = (x)=>x + 3 & ~3;
397
+ /**
398
+ * 按描述表解析并校验段边界。任何不一致(截断、计数越界、段区间超出
399
+ * debugInfoOffset)都返回 null——调用方回退到不变换路径。
400
+ * 描述表视为不可信输入,所有算术做显式边界检查。
401
+ */ function resolveSections(buf, layout) {
402
+ const headerEnd = HEADER_COUNTS_OFFSET + layout.headerFields.length * 4;
403
+ if (buf.length < HBC_HEADER_SIZE || headerEnd > HBC_HEADER_SIZE) return null;
404
+ const counts = {};
405
+ layout.headerFields.forEach((name, i)=>{
406
+ counts[name] = buf.readUInt32LE(HEADER_COUNTS_OFFSET + i * 4);
407
+ });
408
+ if (counts.fileLength !== buf.length) return null;
409
+ const debugInfoOffset = counts.debugInfoOffset;
410
+ if (!Number.isInteger(debugInfoOffset) || debugInfoOffset < HBC_HEADER_SIZE || debugInfoOffset > buf.length) {
411
+ return null;
412
+ }
413
+ const resolved = [];
414
+ let off = HBC_HEADER_SIZE;
415
+ for (const desc of layout.sections){
416
+ var _desc_deltaFields;
417
+ const count = counts[desc.countField];
418
+ if (count === undefined || count > 0x0fffffff) return null;
419
+ const size = count * desc.entrySize;
420
+ off = align4(off);
421
+ if (off + size > debugInfoOffset) return null;
422
+ for (const f of (_desc_deltaFields = desc.deltaFields) != null ? _desc_deltaFields : []){
423
+ // 差分字段必须完整落在条目内且可用一次 u32 读写覆盖
424
+ if (f.bits < 1 || f.bits > 32 || f.bit + f.bits > 32 || f.byte + 4 > desc.entrySize) {
425
+ return null;
426
+ }
427
+ }
428
+ resolved.push({
429
+ start: off,
430
+ size,
431
+ desc
432
+ });
433
+ off += size;
434
+ }
435
+ return resolved;
436
+ }
437
+ function applyDelta(out, section, inverse) {
438
+ var _desc_deltaFields;
439
+ const { start, size, desc } = section;
440
+ for (const f of (_desc_deltaFields = desc.deltaFields) != null ? _desc_deltaFields : []){
441
+ // bits === 32 时掩码为全 1;>>> 保持无符号语义
442
+ const mask = f.bits === 32 ? 0xffffffff : (1 << f.bits) - 1 << f.bit;
443
+ const fieldMask = f.bits === 32 ? 0xffffffff : (1 << f.bits) - 1;
444
+ let prev = 0;
445
+ for(let p = start + f.byte; p < start + size; p += desc.entrySize){
446
+ const word = out.readUInt32LE(p);
447
+ const val = word >>> f.bit & fieldMask;
448
+ let enc;
449
+ if (!inverse) {
450
+ enc = val - prev & fieldMask;
451
+ prev = val;
452
+ } else {
453
+ enc = val + prev & fieldMask;
454
+ prev = enc;
455
+ }
456
+ out.writeUInt32LE((word & ~mask | enc << f.bit) >>> 0, p);
457
+ }
458
+ }
459
+ }
460
+ function transformHbc(buf, inverse = false) {
461
+ const layout = pickLayout(buf);
462
+ if (!layout) return null;
463
+ return transformHbcWithLayout(buf, layout, inverse);
464
+ }
465
+ function pickLayout(buf) {
466
+ const version = getHbcVersion(buf);
467
+ if (version === null) return null;
468
+ for (const layout of findLayouts(version)){
469
+ if (resolveSections(buf, layout)) return layout;
470
+ }
471
+ return null;
472
+ }
473
+ function transformHbcWithLayout(buf, layout, inverse) {
474
+ const sections = resolveSections(buf, layout);
475
+ if (!sections) return null;
476
+ const out = Buffer.from(buf);
477
+ for (const s of sections){
478
+ var _s_desc_deltaFields;
479
+ if ((_s_desc_deltaFields = s.desc.deltaFields) == null ? void 0 : _s_desc_deltaFields.length) applyDelta(out, s, inverse);
480
+ }
481
+ return out;
482
+ }
483
+ const HBC_TRANSFORM_VERSION = 1;
484
+ function tryTransformPair(oldBuf, newBuf) {
485
+ const oldVersion = getHbcVersion(oldBuf);
486
+ const newVersion = getHbcVersion(newBuf);
487
+ if (oldVersion === null || newVersion === null || oldVersion !== newVersion) {
488
+ return null;
489
+ }
490
+ for (const layout of findLayouts(newVersion)){
491
+ const tOld = transformHbcWithLayout(oldBuf, layout, false);
492
+ const tNew = transformHbcWithLayout(newBuf, layout, false);
493
+ if (!tOld || !tNew) continue;
494
+ return {
495
+ tOld,
496
+ tNew,
497
+ layout,
498
+ meta: {
499
+ v: HBC_TRANSFORM_VERSION,
500
+ hbcVersion: newVersion,
501
+ layout: compileLayoutToWire(layout)
502
+ }
503
+ };
504
+ }
505
+ return null;
506
+ }
package/lib/versions.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Package, Platform, Version } from './types';
2
2
  interface VersionCommandOptions {
3
3
  [key: string]: unknown;
4
+ config?: string;
5
+ appKey?: string;
4
6
  appId?: string;
5
7
  name?: string;
6
8
  description?: string;
package/lib/versions.js CHANGED
@@ -353,7 +353,10 @@ const versionCommands = {
353
353
  throw new Error((0, _i18n.t)('publishUsage'));
354
354
  }
355
355
  const platform = await (0, _app.getPlatform)(options.platform);
356
- const { appId } = await (0, _app.getSelectedApp)(platform);
356
+ let appId = options.appId;
357
+ if (!appId) {
358
+ appId = (await (0, _app.getSelectedApp)(platform, options.config)).appId;
359
+ }
357
360
  const nonInteractive = (0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)();
358
361
  const { hash } = await (0, _api.uploadFile)(fn);
359
362
  const versionName = name || (nonInteractive ? '' : await (0, _utils.question)((0, _i18n.t)('versionNameQuestion'))) || (0, _i18n.t)('unnamed');
@@ -404,7 +407,7 @@ const versionCommands = {
404
407
  let appId = options.appId;
405
408
  if (!appId) {
406
409
  const platform = await (0, _app.getPlatform)(options.platform);
407
- appId = (await (0, _app.getSelectedApp)(platform)).appId;
410
+ appId = (await (0, _app.getSelectedApp)(platform, options.config)).appId;
408
411
  }
409
412
  const interactive = !((0, _options.getBooleanOption)(options, 'no-interactive', false) || (0, _utils.isNonInteractive)());
410
413
  await listVersions(String(appId), interactive);
@@ -415,7 +418,7 @@ const versionCommands = {
415
418
  let platform = options.platform;
416
419
  if (!appId) {
417
420
  platform = await (0, _app.getPlatform)(platform);
418
- appId = (await (0, _app.getSelectedApp)(platform)).appId;
421
+ appId = (await (0, _app.getSelectedApp)(platform, options.config)).appId;
419
422
  } else if (platform) {
420
423
  platform = await (0, _app.getPlatform)(platform);
421
424
  }
@@ -534,7 +537,7 @@ const versionCommands = {
534
537
  let platform = options.platform;
535
538
  if (!appId) {
536
539
  platform = await (0, _app.getPlatform)(platform);
537
- appId = (await (0, _app.getSelectedApp)(platform)).appId;
540
+ appId = (await (0, _app.getSelectedApp)(platform, options.config)).appId;
538
541
  } else if (platform) {
539
542
  await (0, _app.getPlatform)(platform);
540
543
  }
@@ -558,7 +561,7 @@ const versionCommands = {
558
561
  let appId = options.appId;
559
562
  if (!appId) {
560
563
  const platform = await (0, _app.getPlatform)(options.platform);
561
- appId = (await (0, _app.getSelectedApp)(platform)).appId;
564
+ appId = (await (0, _app.getSelectedApp)(platform, options.config)).appId;
562
565
  }
563
566
  const parsedVersionIds = (_getStringListOption = (0, _options.getStringListOption)(options, 'versionIds')) != null ? _getStringListOption : (0, _options.getStringListOption)(options, 'versionId');
564
567
  let versionIds = parsedVersionIds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.16.0",
3
+ "version": "2.17.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",
package/src/app.ts CHANGED
@@ -26,13 +26,16 @@ export function assertPlatform(platform: string): Platform {
26
26
 
27
27
  export async function getSelectedApp(
28
28
  platform: Platform,
29
+ configPath?: string,
29
30
  ): Promise<{ appId: string; appKey: string; platform: Platform }> {
30
31
  assertPlatform(platform);
31
32
 
32
33
  let updateInfo: Partial<Record<Platform, { appId: number; appKey: string }>> =
33
34
  {};
34
35
  try {
35
- updateInfo = JSON.parse(await fs.promises.readFile('update.json', 'utf8'));
36
+ updateInfo = JSON.parse(
37
+ await fs.promises.readFile(configPath || 'update.json', 'utf8'),
38
+ );
36
39
  } catch (e: any) {
37
40
  if (e.code === 'ENOENT') {
38
41
  throw new Error(t('appNotSelected', { platform }));
@@ -97,10 +100,13 @@ async function selectApp({
97
100
  ? Number.parseInt(args[0], 10)
98
101
  : (await chooseApp(platform)).id;
99
102
 
103
+ const configPath = (options as any).config as string | undefined;
100
104
  let updateInfo: Partial<Record<Platform, { appId: number; appKey: string }>> =
101
105
  {};
102
106
  try {
103
- updateInfo = JSON.parse(await fs.promises.readFile('update.json', 'utf8'));
107
+ updateInfo = JSON.parse(
108
+ await fs.promises.readFile(configPath || 'update.json', 'utf8'),
109
+ );
104
110
  } catch (e: any) {
105
111
  if (e.code !== 'ENOENT') {
106
112
  console.error(t('failedToParseUpdateJson'));
@@ -113,7 +119,7 @@ async function selectApp({
113
119
  appKey,
114
120
  };
115
121
  await fs.promises.writeFile(
116
- 'update.json',
122
+ configPath || 'update.json',
117
123
  JSON.stringify(updateInfo, null, 4),
118
124
  'utf8',
119
125
  );