react-native-update-cli 2.18.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.
- package/lib/api.d.ts +1 -1
- package/lib/api.js +140 -134
- package/lib/app.d.ts +2 -2
- package/lib/app.js +60 -107
- package/lib/bin.js +38 -35
- package/lib/bundle-pack.js +57 -77
- package/lib/bundle-runner.js +249 -312
- package/lib/bundle.js +71 -89
- package/lib/diff.js +188 -235
- package/lib/exports.js +14 -37
- package/lib/index.js +16 -17
- package/lib/install.js +24 -37
- package/lib/locales/en.js +3 -11
- package/lib/locales/zh.js +3 -11
- package/lib/package.js +164 -218
- package/lib/provider.js +85 -107
- package/lib/types.js +1 -3
- package/lib/user.d.ts +1 -1
- package/lib/user.js +26 -39
- package/lib/utils/add-gitignore.js +16 -29
- package/lib/utils/app-info-parser/aab.js +133 -157
- package/lib/utils/app-info-parser/apk.js +42 -39
- package/lib/utils/app-info-parser/app.js +5 -11
- package/lib/utils/app-info-parser/index.js +21 -31
- package/lib/utils/app-info-parser/ipa.js +35 -35
- package/lib/utils/app-info-parser/resource-finder.js +84 -71
- package/lib/utils/app-info-parser/utils.js +52 -77
- package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
- package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
- package/lib/utils/app-info-parser/zip.js +43 -51
- package/lib/utils/check-lockfile.js +28 -37
- package/lib/utils/check-plugin.js +16 -32
- package/lib/utils/command-result.js +7 -20
- package/lib/utils/constants.js +23 -63
- package/lib/utils/dep-versions.js +21 -27
- package/lib/utils/git.js +20 -64
- package/lib/utils/hbcTransform.js +133 -246
- package/lib/utils/http-helper.js +33 -44
- package/lib/utils/i18n.js +17 -26
- package/lib/utils/index.js +137 -179
- package/lib/utils/latest-version/index.js +128 -137
- package/lib/utils/options.js +13 -34
- package/lib/utils/plugin-config.js +43 -56
- package/lib/utils/runtime.js +50 -108
- package/lib/utils/zip-entries.js +70 -97
- package/lib/utils/zip-options.js +80 -181
- package/lib/versions.js +231 -265
- package/package.json +19 -21
- package/src/api.ts +44 -3
- package/src/package.ts +1 -1
- package/src/user.ts +1 -1
- package/src/versions.ts +1 -1
|
@@ -1,42 +1,4 @@
|
|
|
1
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
2
|
/**
|
|
41
3
|
* Hermes 字节码(HBC)delta-friendly 可逆变换。
|
|
42
4
|
*
|
|
@@ -52,131 +14,85 @@ _export(exports, {
|
|
|
52
14
|
*
|
|
53
15
|
* wrapping 差分与单调性无关、恒可逆:T⁻¹(T(x)) === x 对任意输入成立
|
|
54
16
|
* (只要两侧使用同一份描述表)。
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.HBC_TRANSFORM_VERSION = exports.HBC_LAYOUTS = void 0;
|
|
20
|
+
exports.compileLayoutToWire = compileLayoutToWire;
|
|
21
|
+
exports.getHbcVersion = getHbcVersion;
|
|
22
|
+
exports.findLayouts = findLayouts;
|
|
23
|
+
exports.transformHbc = transformHbc;
|
|
24
|
+
exports.pickLayout = pickLayout;
|
|
25
|
+
exports.transformHbcWithLayout = transformHbcWithLayout;
|
|
26
|
+
exports.tryTransformPair = tryTransformPair;
|
|
27
|
+
const HBC_MAGIC = Buffer.from([0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f]);
|
|
65
28
|
const HEADER_COUNTS_OFFSET = 32; // magic(8) + version(4) + sourceHash(20)
|
|
66
29
|
const HBC_HEADER_SIZE = 128;
|
|
67
|
-
const FUNC_OFFSET_25 = {
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
};
|
|
30
|
+
const FUNC_OFFSET_25 = { byte: 0, bit: 0, bits: 25 };
|
|
31
|
+
const STRING_OFFSET_23 = { byte: 0, bit: 1, bits: 23 };
|
|
32
|
+
const PAIR_OFFSET_32 = { byte: 0, bit: 0, bits: 32 };
|
|
82
33
|
// v98 两种头部变体共享的段布局
|
|
83
34
|
const V98_SECTIONS = [
|
|
84
35
|
{
|
|
85
36
|
name: 'functionHeaders',
|
|
86
37
|
countField: 'functionCount',
|
|
87
38
|
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
|
|
39
|
+
deltaFields: [FUNC_OFFSET_25],
|
|
101
40
|
},
|
|
41
|
+
{ name: 'stringKinds', countField: 'stringKindCount', entrySize: 4 },
|
|
42
|
+
{ name: 'identifierHashes', countField: 'identifierCount', entrySize: 4 },
|
|
102
43
|
{
|
|
103
44
|
name: 'smallStringTable',
|
|
104
45
|
countField: 'stringCount',
|
|
105
46
|
entrySize: 4,
|
|
106
|
-
deltaFields: [
|
|
107
|
-
STRING_OFFSET_23
|
|
108
|
-
]
|
|
47
|
+
deltaFields: [STRING_OFFSET_23],
|
|
109
48
|
},
|
|
110
49
|
{
|
|
111
50
|
name: 'overflowStringTable',
|
|
112
51
|
countField: 'overflowStringCount',
|
|
113
52
|
entrySize: 8,
|
|
114
|
-
deltaFields: [
|
|
115
|
-
PAIR_OFFSET_32
|
|
116
|
-
]
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: 'stringStorage',
|
|
120
|
-
countField: 'stringStorageSize',
|
|
121
|
-
entrySize: 1
|
|
53
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
122
54
|
},
|
|
55
|
+
{ name: 'stringStorage', countField: 'stringStorageSize', entrySize: 1 },
|
|
123
56
|
{
|
|
124
57
|
name: 'literalValueBuffer',
|
|
125
58
|
countField: 'literalValueBufferSize',
|
|
126
|
-
entrySize: 1
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: 'objKeyBuffer',
|
|
130
|
-
countField: 'objKeyBufferSize',
|
|
131
|
-
entrySize: 1
|
|
59
|
+
entrySize: 1,
|
|
132
60
|
},
|
|
61
|
+
{ name: 'objKeyBuffer', countField: 'objKeyBufferSize', entrySize: 1 },
|
|
133
62
|
// ShapeTableEntry 8B:{keyBufferOffset u32, numProps u32}
|
|
134
63
|
{
|
|
135
64
|
name: 'objShapeTable',
|
|
136
65
|
countField: 'objShapeTableCount',
|
|
137
66
|
entrySize: 8,
|
|
138
|
-
deltaFields: [
|
|
139
|
-
PAIR_OFFSET_32
|
|
140
|
-
]
|
|
67
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
141
68
|
},
|
|
142
69
|
{
|
|
143
70
|
name: 'bigIntTable',
|
|
144
71
|
countField: 'bigIntCount',
|
|
145
72
|
entrySize: 8,
|
|
146
|
-
deltaFields: [
|
|
147
|
-
PAIR_OFFSET_32
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'bigIntStorage',
|
|
152
|
-
countField: 'bigIntStorageSize',
|
|
153
|
-
entrySize: 1
|
|
73
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
154
74
|
},
|
|
75
|
+
{ name: 'bigIntStorage', countField: 'bigIntStorageSize', entrySize: 1 },
|
|
155
76
|
{
|
|
156
77
|
name: 'regExpTable',
|
|
157
78
|
countField: 'regExpCount',
|
|
158
79
|
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
|
|
80
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
172
81
|
},
|
|
82
|
+
{ name: 'regExpStorage', countField: 'regExpStorageSize', entrySize: 1 },
|
|
83
|
+
{ name: 'cjsModuleTable', countField: 'cjsModuleCount', entrySize: 8 },
|
|
173
84
|
{
|
|
174
85
|
name: 'functionSourceTable',
|
|
175
86
|
countField: 'functionSourceCount',
|
|
176
|
-
entrySize: 8
|
|
177
|
-
}
|
|
87
|
+
entrySize: 8,
|
|
88
|
+
},
|
|
178
89
|
];
|
|
179
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 布局描述表(唯一需要跟随 Hermes 版本演进的数据)。
|
|
92
|
+
* 字段序照抄 hermes 源码 include/hermes/BCGen/HBC/BytecodeFileFormat.h。
|
|
93
|
+
* v97 为 Static Hermes 短期预览版本,生产占比为零,不支持(自动回退)。
|
|
94
|
+
*/
|
|
95
|
+
exports.HBC_LAYOUTS = [
|
|
180
96
|
{
|
|
181
97
|
// hermes 0.12 主线(RN 0.69~0.81+),v87 引入 bigInt 字段后布局稳定
|
|
182
98
|
minVersion: 87,
|
|
@@ -200,7 +116,7 @@ const HBC_LAYOUTS = [
|
|
|
200
116
|
'segmentID',
|
|
201
117
|
'cjsModuleCount',
|
|
202
118
|
'functionSourceCount',
|
|
203
|
-
'debugInfoOffset'
|
|
119
|
+
'debugInfoOffset',
|
|
204
120
|
],
|
|
205
121
|
sections: [
|
|
206
122
|
// SmallFuncHeader 16B:word0 offset:25|paramCount:7,word2 infoOffset:25|frameSize:7
|
|
@@ -208,100 +124,53 @@ const HBC_LAYOUTS = [
|
|
|
208
124
|
name: 'functionHeaders',
|
|
209
125
|
countField: 'functionCount',
|
|
210
126
|
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
|
|
127
|
+
deltaFields: [FUNC_OFFSET_25, { byte: 8, bit: 0, bits: 25 }],
|
|
229
128
|
},
|
|
129
|
+
{ name: 'stringKinds', countField: 'stringKindCount', entrySize: 4 },
|
|
130
|
+
{ name: 'identifierHashes', countField: 'identifierCount', entrySize: 4 },
|
|
230
131
|
// SmallStringTableEntry 4B:isUTF16:1|offset:23|length:8
|
|
231
132
|
{
|
|
232
133
|
name: 'smallStringTable',
|
|
233
134
|
countField: 'stringCount',
|
|
234
135
|
entrySize: 4,
|
|
235
|
-
deltaFields: [
|
|
236
|
-
STRING_OFFSET_23
|
|
237
|
-
]
|
|
136
|
+
deltaFields: [STRING_OFFSET_23],
|
|
238
137
|
},
|
|
239
138
|
// OverflowStringTableEntry 8B:{offset u32, length u32}
|
|
240
139
|
{
|
|
241
140
|
name: 'overflowStringTable',
|
|
242
141
|
countField: 'overflowStringCount',
|
|
243
142
|
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
|
|
143
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
262
144
|
},
|
|
145
|
+
{ name: 'stringStorage', countField: 'stringStorageSize', entrySize: 1 },
|
|
146
|
+
{ name: 'arrayBuffer', countField: 'arrayBufferSize', entrySize: 1 },
|
|
147
|
+
{ name: 'objKeyBuffer', countField: 'objKeyBufferSize', entrySize: 1 },
|
|
263
148
|
{
|
|
264
149
|
name: 'objValueBuffer',
|
|
265
150
|
countField: 'objValueBufferSize',
|
|
266
|
-
entrySize: 1
|
|
151
|
+
entrySize: 1,
|
|
267
152
|
},
|
|
268
153
|
{
|
|
269
154
|
name: 'bigIntTable',
|
|
270
155
|
countField: 'bigIntCount',
|
|
271
156
|
entrySize: 8,
|
|
272
|
-
deltaFields: [
|
|
273
|
-
PAIR_OFFSET_32
|
|
274
|
-
]
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
name: 'bigIntStorage',
|
|
278
|
-
countField: 'bigIntStorageSize',
|
|
279
|
-
entrySize: 1
|
|
157
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
280
158
|
},
|
|
159
|
+
{ name: 'bigIntStorage', countField: 'bigIntStorageSize', entrySize: 1 },
|
|
281
160
|
{
|
|
282
161
|
name: 'regExpTable',
|
|
283
162
|
countField: 'regExpCount',
|
|
284
163
|
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
|
|
164
|
+
deltaFields: [PAIR_OFFSET_32],
|
|
298
165
|
},
|
|
166
|
+
{ name: 'regExpStorage', countField: 'regExpStorageSize', entrySize: 1 },
|
|
167
|
+
{ name: 'cjsModuleTable', countField: 'cjsModuleCount', entrySize: 8 },
|
|
299
168
|
{
|
|
300
169
|
name: 'functionSourceTable',
|
|
301
170
|
countField: 'functionSourceCount',
|
|
302
|
-
entrySize: 8
|
|
303
|
-
}
|
|
304
|
-
]
|
|
171
|
+
entrySize: 8,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
305
174
|
},
|
|
306
175
|
{
|
|
307
176
|
// Static Hermes 晚期 v98(生产观测到的主流形态):相对早期 v98 头部
|
|
@@ -330,9 +199,9 @@ const HBC_LAYOUTS = [
|
|
|
330
199
|
'segmentID',
|
|
331
200
|
'cjsModuleCount',
|
|
332
201
|
'functionSourceCount',
|
|
333
|
-
'debugInfoOffset'
|
|
202
|
+
'debugInfoOffset',
|
|
334
203
|
],
|
|
335
|
-
sections: V98_SECTIONS
|
|
204
|
+
sections: V98_SECTIONS,
|
|
336
205
|
},
|
|
337
206
|
{
|
|
338
207
|
// Static Hermes 早期 v98(hermes c00cc57595 时点,无 numStringSwitchImms)。
|
|
@@ -360,146 +229,164 @@ const HBC_LAYOUTS = [
|
|
|
360
229
|
'segmentID',
|
|
361
230
|
'cjsModuleCount',
|
|
362
231
|
'functionSourceCount',
|
|
363
|
-
'debugInfoOffset'
|
|
232
|
+
'debugInfoOffset',
|
|
364
233
|
],
|
|
365
|
-
sections: V98_SECTIONS
|
|
366
|
-
}
|
|
234
|
+
sections: V98_SECTIONS,
|
|
235
|
+
},
|
|
367
236
|
];
|
|
368
237
|
function compileLayoutToWire(layout) {
|
|
369
|
-
if (layout.headerFields[0] !== 'fileLength' ||
|
|
238
|
+
if (layout.headerFields[0] !== 'fileLength' ||
|
|
239
|
+
layout.headerFields[layout.headerFields.length - 1] !== 'debugInfoOffset') {
|
|
370
240
|
throw new Error('HbcLayout must start with fileLength and end with debugInfoOffset');
|
|
371
241
|
}
|
|
372
242
|
return {
|
|
373
243
|
counts: layout.headerFields.length,
|
|
374
|
-
sections: layout.sections.map((s)=>
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
((_s_deltaFields = s.deltaFields) != null ? _s_deltaFields : []).map((f)=>[
|
|
380
|
-
f.byte,
|
|
381
|
-
f.bit,
|
|
382
|
-
f.bits
|
|
383
|
-
])
|
|
384
|
-
];
|
|
385
|
-
})
|
|
244
|
+
sections: layout.sections.map((s) => [
|
|
245
|
+
layout.headerFields.indexOf(s.countField),
|
|
246
|
+
s.entrySize,
|
|
247
|
+
(s.deltaFields ?? []).map((f) => [f.byte, f.bit, f.bits]),
|
|
248
|
+
]),
|
|
386
249
|
};
|
|
387
250
|
}
|
|
388
251
|
function getHbcVersion(buf) {
|
|
389
|
-
if (buf.length < HBC_HEADER_SIZE)
|
|
390
|
-
|
|
252
|
+
if (buf.length < HBC_HEADER_SIZE)
|
|
253
|
+
return null;
|
|
254
|
+
if (!buf.subarray(0, 8).equals(HBC_MAGIC))
|
|
255
|
+
return null;
|
|
391
256
|
return buf.readUInt32LE(8);
|
|
392
257
|
}
|
|
258
|
+
/** 同一版本号可能有多个候选布局(按声明顺序即优先级)。 */
|
|
393
259
|
function findLayouts(version) {
|
|
394
|
-
return HBC_LAYOUTS.filter((l)=>version >= l.minVersion && version <= l.maxVersion);
|
|
260
|
+
return exports.HBC_LAYOUTS.filter((l) => version >= l.minVersion && version <= l.maxVersion);
|
|
395
261
|
}
|
|
396
|
-
const align4 = (x)=>x + 3 & ~3;
|
|
262
|
+
const align4 = (x) => (x + 3) & ~3;
|
|
397
263
|
/**
|
|
398
264
|
* 按描述表解析并校验段边界。任何不一致(截断、计数越界、段区间超出
|
|
399
265
|
* debugInfoOffset)都返回 null——调用方回退到不变换路径。
|
|
400
266
|
* 描述表视为不可信输入,所有算术做显式边界检查。
|
|
401
|
-
*/
|
|
267
|
+
*/
|
|
268
|
+
function resolveSections(buf, layout) {
|
|
402
269
|
const headerEnd = HEADER_COUNTS_OFFSET + layout.headerFields.length * 4;
|
|
403
|
-
if (buf.length < HBC_HEADER_SIZE || headerEnd > HBC_HEADER_SIZE)
|
|
270
|
+
if (buf.length < HBC_HEADER_SIZE || headerEnd > HBC_HEADER_SIZE)
|
|
271
|
+
return null;
|
|
404
272
|
const counts = {};
|
|
405
|
-
layout.headerFields.forEach((name, i)=>{
|
|
273
|
+
layout.headerFields.forEach((name, i) => {
|
|
406
274
|
counts[name] = buf.readUInt32LE(HEADER_COUNTS_OFFSET + i * 4);
|
|
407
275
|
});
|
|
408
|
-
if (counts.fileLength !== buf.length)
|
|
276
|
+
if (counts.fileLength !== buf.length)
|
|
277
|
+
return null;
|
|
409
278
|
const debugInfoOffset = counts.debugInfoOffset;
|
|
410
|
-
if (!Number.isInteger(debugInfoOffset) ||
|
|
279
|
+
if (!Number.isInteger(debugInfoOffset) ||
|
|
280
|
+
debugInfoOffset < HBC_HEADER_SIZE ||
|
|
281
|
+
debugInfoOffset > buf.length) {
|
|
411
282
|
return null;
|
|
412
283
|
}
|
|
413
284
|
const resolved = [];
|
|
414
285
|
let off = HBC_HEADER_SIZE;
|
|
415
|
-
for (const desc of layout.sections){
|
|
416
|
-
var _desc_deltaFields;
|
|
286
|
+
for (const desc of layout.sections) {
|
|
417
287
|
const count = counts[desc.countField];
|
|
418
|
-
if (count === undefined || count > 0x0fffffff)
|
|
288
|
+
if (count === undefined || count > 0x0fffffff)
|
|
289
|
+
return null;
|
|
419
290
|
const size = count * desc.entrySize;
|
|
420
291
|
off = align4(off);
|
|
421
|
-
if (off + size > debugInfoOffset)
|
|
422
|
-
|
|
292
|
+
if (off + size > debugInfoOffset)
|
|
293
|
+
return null;
|
|
294
|
+
for (const f of desc.deltaFields ?? []) {
|
|
423
295
|
// 差分字段必须完整落在条目内且可用一次 u32 读写覆盖
|
|
424
|
-
if (f.bits < 1 ||
|
|
296
|
+
if (f.bits < 1 ||
|
|
297
|
+
f.bits > 32 ||
|
|
298
|
+
f.bit + f.bits > 32 ||
|
|
299
|
+
f.byte + 4 > desc.entrySize) {
|
|
425
300
|
return null;
|
|
426
301
|
}
|
|
427
302
|
}
|
|
428
|
-
resolved.push({
|
|
429
|
-
start: off,
|
|
430
|
-
size,
|
|
431
|
-
desc
|
|
432
|
-
});
|
|
303
|
+
resolved.push({ start: off, size, desc });
|
|
433
304
|
off += size;
|
|
434
305
|
}
|
|
435
306
|
return resolved;
|
|
436
307
|
}
|
|
437
308
|
function applyDelta(out, section, inverse) {
|
|
438
|
-
var _desc_deltaFields;
|
|
439
309
|
const { start, size, desc } = section;
|
|
440
|
-
for (const f of
|
|
310
|
+
for (const f of desc.deltaFields ?? []) {
|
|
441
311
|
// bits === 32 时掩码为全 1;>>> 保持无符号语义
|
|
442
|
-
const mask = f.bits === 32 ? 0xffffffff : (1 << f.bits) - 1 << f.bit;
|
|
312
|
+
const mask = f.bits === 32 ? 0xffffffff : ((1 << f.bits) - 1) << f.bit;
|
|
443
313
|
const fieldMask = f.bits === 32 ? 0xffffffff : (1 << f.bits) - 1;
|
|
444
314
|
let prev = 0;
|
|
445
|
-
for(let p = start + f.byte; p < start + size; p += desc.entrySize){
|
|
315
|
+
for (let p = start + f.byte; p < start + size; p += desc.entrySize) {
|
|
446
316
|
const word = out.readUInt32LE(p);
|
|
447
|
-
const val = word >>> f.bit & fieldMask;
|
|
317
|
+
const val = (word >>> f.bit) & fieldMask;
|
|
448
318
|
let enc;
|
|
449
319
|
if (!inverse) {
|
|
450
|
-
enc = val - prev & fieldMask;
|
|
320
|
+
enc = (val - prev) & fieldMask;
|
|
451
321
|
prev = val;
|
|
452
|
-
}
|
|
453
|
-
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
enc = (val + prev) & fieldMask;
|
|
454
325
|
prev = enc;
|
|
455
326
|
}
|
|
456
|
-
out.writeUInt32LE((word & ~mask | enc << f.bit) >>> 0, p);
|
|
327
|
+
out.writeUInt32LE(((word & ~mask) | (enc << f.bit)) >>> 0, p);
|
|
457
328
|
}
|
|
458
329
|
}
|
|
459
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* 对 HBC buffer 执行变换(inverse=false)或逆变换(inverse=true)。
|
|
333
|
+
* 同一版本号可能存在多个候选布局(如 v98 早/晚两种头部),按声明顺序
|
|
334
|
+
* 取第一个通过结构校验的。非 HBC / 无可用布局 → 返回 null。
|
|
335
|
+
* 注意:变换不改动头部计数,同一文件正/逆向解析选中的布局必然一致。
|
|
336
|
+
*/
|
|
460
337
|
function transformHbc(buf, inverse = false) {
|
|
461
338
|
const layout = pickLayout(buf);
|
|
462
|
-
if (!layout)
|
|
339
|
+
if (!layout)
|
|
340
|
+
return null;
|
|
463
341
|
return transformHbcWithLayout(buf, layout, inverse);
|
|
464
342
|
}
|
|
343
|
+
/** 返回该 buffer 结构上匹配的布局(候选中第一个校验通过者)。 */
|
|
465
344
|
function pickLayout(buf) {
|
|
466
345
|
const version = getHbcVersion(buf);
|
|
467
|
-
if (version === null)
|
|
468
|
-
|
|
469
|
-
|
|
346
|
+
if (version === null)
|
|
347
|
+
return null;
|
|
348
|
+
for (const layout of findLayouts(version)) {
|
|
349
|
+
if (resolveSections(buf, layout))
|
|
350
|
+
return layout;
|
|
470
351
|
}
|
|
471
352
|
return null;
|
|
472
353
|
}
|
|
473
354
|
function transformHbcWithLayout(buf, layout, inverse) {
|
|
474
355
|
const sections = resolveSections(buf, layout);
|
|
475
|
-
if (!sections)
|
|
356
|
+
if (!sections)
|
|
357
|
+
return null;
|
|
476
358
|
const out = Buffer.from(buf);
|
|
477
|
-
for (const s of sections){
|
|
478
|
-
|
|
479
|
-
|
|
359
|
+
for (const s of sections) {
|
|
360
|
+
if (s.desc.deltaFields?.length)
|
|
361
|
+
applyDelta(out, s, inverse);
|
|
480
362
|
}
|
|
481
363
|
return out;
|
|
482
364
|
}
|
|
483
|
-
|
|
365
|
+
exports.HBC_TRANSFORM_VERSION = 1;
|
|
366
|
+
/**
|
|
367
|
+
* 若 old/new 均为同版本且存在两侧都通过结构校验的候选布局,返回变换结果、
|
|
368
|
+
* 选中布局与写入 __diff.json 的元数据;否则返回 null。
|
|
369
|
+
*/
|
|
484
370
|
function tryTransformPair(oldBuf, newBuf) {
|
|
485
371
|
const oldVersion = getHbcVersion(oldBuf);
|
|
486
372
|
const newVersion = getHbcVersion(newBuf);
|
|
487
373
|
if (oldVersion === null || newVersion === null || oldVersion !== newVersion) {
|
|
488
374
|
return null;
|
|
489
375
|
}
|
|
490
|
-
for (const layout of findLayouts(newVersion)){
|
|
376
|
+
for (const layout of findLayouts(newVersion)) {
|
|
491
377
|
const tOld = transformHbcWithLayout(oldBuf, layout, false);
|
|
492
378
|
const tNew = transformHbcWithLayout(newBuf, layout, false);
|
|
493
|
-
if (!tOld || !tNew)
|
|
379
|
+
if (!tOld || !tNew)
|
|
380
|
+
continue;
|
|
494
381
|
return {
|
|
495
382
|
tOld,
|
|
496
383
|
tNew,
|
|
497
384
|
layout,
|
|
498
385
|
meta: {
|
|
499
|
-
v: HBC_TRANSFORM_VERSION,
|
|
386
|
+
v: exports.HBC_TRANSFORM_VERSION,
|
|
500
387
|
hbcVersion: newVersion,
|
|
501
|
-
layout: compileLayoutToWire(layout)
|
|
502
|
-
}
|
|
388
|
+
layout: compileLayoutToWire(layout),
|
|
389
|
+
},
|
|
503
390
|
};
|
|
504
391
|
}
|
|
505
392
|
return null;
|
package/lib/utils/http-helper.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get getBaseUrl () {
|
|
13
|
-
return getBaseUrl;
|
|
14
|
-
},
|
|
15
|
-
get ping () {
|
|
16
|
-
return ping;
|
|
17
|
-
},
|
|
18
|
-
get promiseAny () {
|
|
19
|
-
return promiseAny;
|
|
20
|
-
},
|
|
21
|
-
get testUrls () {
|
|
22
|
-
return testUrls;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const _constants = require("./constants");
|
|
26
|
-
const _runtime = require("./runtime");
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBaseUrl = exports.testUrls = exports.ping = void 0;
|
|
4
|
+
exports.promiseAny = promiseAny;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const runtime_1 = require("./runtime");
|
|
7
|
+
// const baseUrl = `http://localhost:9000`;
|
|
8
|
+
// let baseUrl = SERVER.main[0];
|
|
9
|
+
// const baseUrl = `https://p.reactnative.cn/api`;
|
|
27
10
|
function promiseAny(promises) {
|
|
28
|
-
return new Promise((resolve, reject)=>{
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
29
12
|
let count = 0;
|
|
30
|
-
for (const promise of promises){
|
|
31
|
-
Promise.resolve(promise)
|
|
13
|
+
for (const promise of promises) {
|
|
14
|
+
Promise.resolve(promise)
|
|
15
|
+
.then(resolve)
|
|
16
|
+
.catch(() => {
|
|
32
17
|
count++;
|
|
33
18
|
if (count === promises.length) {
|
|
34
19
|
reject(new Error('All promises were rejected'));
|
|
@@ -37,38 +22,41 @@ function promiseAny(promises) {
|
|
|
37
22
|
}
|
|
38
23
|
});
|
|
39
24
|
}
|
|
40
|
-
const ping = async (url)=>{
|
|
25
|
+
const ping = async (url) => {
|
|
41
26
|
let timer;
|
|
42
27
|
try {
|
|
43
28
|
return await Promise.race([
|
|
44
|
-
(0,
|
|
45
|
-
method: 'HEAD'
|
|
46
|
-
}).then(({ status })=>{
|
|
29
|
+
(0, runtime_1.runtimeFetch)(url, {
|
|
30
|
+
method: 'HEAD',
|
|
31
|
+
}).then(({ status }) => {
|
|
47
32
|
if (status === 200) {
|
|
48
33
|
return url;
|
|
49
34
|
}
|
|
50
35
|
throw new Error('ping failed');
|
|
51
36
|
}),
|
|
52
|
-
new Promise((_, reject)=>{
|
|
53
|
-
timer = setTimeout(()=>{
|
|
37
|
+
new Promise((_, reject) => {
|
|
38
|
+
timer = setTimeout(() => {
|
|
54
39
|
reject(new Error('ping timeout'));
|
|
55
40
|
}, 5000);
|
|
56
|
-
})
|
|
41
|
+
}),
|
|
57
42
|
]);
|
|
58
|
-
}
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
59
45
|
// clear the timer so it doesn't keep the process alive for 5s
|
|
60
46
|
clearTimeout(timer);
|
|
61
47
|
}
|
|
62
48
|
};
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
exports.ping = ping;
|
|
50
|
+
const testUrls = async (urls) => {
|
|
51
|
+
if (!urls?.length) {
|
|
65
52
|
return null;
|
|
66
53
|
}
|
|
67
54
|
let ret = null;
|
|
68
55
|
try {
|
|
69
|
-
ret = await promiseAny(urls.map(ping));
|
|
70
|
-
}
|
|
71
|
-
|
|
56
|
+
ret = await promiseAny(urls.map(exports.ping));
|
|
57
|
+
}
|
|
58
|
+
catch (_e) {
|
|
59
|
+
// fallback to urls[0]
|
|
72
60
|
}
|
|
73
61
|
if (ret) {
|
|
74
62
|
return ret;
|
|
@@ -76,13 +64,14 @@ const testUrls = async (urls)=>{
|
|
|
76
64
|
// console.log('all ping failed, use first url:', urls[0]);
|
|
77
65
|
return urls[0];
|
|
78
66
|
};
|
|
79
|
-
|
|
67
|
+
exports.testUrls = testUrls;
|
|
68
|
+
exports.getBaseUrl = (async () => {
|
|
80
69
|
const testEndpoint = process.env.PUSHY_REGISTRY || process.env.RNU_API;
|
|
81
70
|
if (testEndpoint) {
|
|
82
71
|
return testEndpoint;
|
|
83
72
|
}
|
|
84
|
-
return testUrls(
|
|
85
|
-
let baseUrl =
|
|
73
|
+
return (0, exports.testUrls)(constants_1.defaultEndpoints.map((url) => `${url}/status`)).then((ret) => {
|
|
74
|
+
let baseUrl = constants_1.defaultEndpoints[0];
|
|
86
75
|
if (ret) {
|
|
87
76
|
// remove /status
|
|
88
77
|
baseUrl = ret.replace('/status', '');
|