react-native-update-cli 2.5.0 → 2.7.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/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/cli.json +26 -0
- package/lib/api.js +45 -12
- package/lib/locales/en.js +13 -1
- package/lib/locales/zh.js +13 -1
- package/lib/package.js +53 -6
- package/lib/provider.js +3 -0
- package/lib/utils/app-info-parser/aab.js +165 -201
- package/lib/utils/app-info-parser/apk.js +25 -27
- package/lib/utils/app-info-parser/app.js +10 -11
- package/lib/utils/app-info-parser/index.js +8 -8
- package/lib/utils/app-info-parser/ipa.js +16 -21
- package/lib/utils/app-info-parser/resource-finder.js +365 -305
- package/lib/utils/app-info-parser/utils.js +78 -63
- package/lib/utils/app-info-parser/xml-parser/binary.js +57 -51
- package/lib/utils/app-info-parser/xml-parser/manifest.js +47 -39
- package/lib/utils/app-info-parser/zip.js +21 -11
- package/lib/utils/http-helper.js +1 -1
- package/package.json +1 -1
- package/src/api.ts +45 -19
- package/src/locales/en.ts +17 -0
- package/src/locales/zh.ts +15 -0
- package/src/modules/version-module.ts +1 -1
- package/src/package.ts +102 -11
- package/src/provider.ts +3 -0
- package/src/utils/app-info-parser/aab.ts +240 -0
- package/src/utils/app-info-parser/{apk.js → apk.ts} +30 -41
- package/src/utils/app-info-parser/app.ts +3 -0
- package/src/utils/app-info-parser/index.ts +4 -4
- package/src/utils/app-info-parser/{ipa.js → ipa.ts} +17 -31
- package/src/utils/app-info-parser/resource-finder.ts +508 -0
- package/src/utils/app-info-parser/utils.ts +162 -0
- package/src/utils/app-info-parser/xml-parser/{binary.js → binary.ts} +69 -61
- package/src/utils/app-info-parser/xml-parser/{manifest.js → manifest.ts} +50 -51
- package/src/utils/app-info-parser/zip.ts +86 -0
- package/src/utils/dep-versions.ts +7 -4
- package/src/utils/http-helper.ts +1 -1
- package/src/utils/latest-version/index.ts +2 -1
- package/src/versions.ts +1 -1
- package/src/utils/app-info-parser/aab.js +0 -326
- package/src/utils/app-info-parser/app.js +0 -16
- package/src/utils/app-info-parser/resource-finder.js +0 -495
- package/src/utils/app-info-parser/utils.js +0 -172
- package/src/utils/app-info-parser/zip.js +0 -66
package/src/utils/http-helper.ts
CHANGED
|
@@ -227,7 +227,8 @@ const downloadMetadata = (
|
|
|
227
227
|
};
|
|
228
228
|
const authInfo = registryAuthToken(pkgUrl.toString(), { recursive: true });
|
|
229
229
|
if (authInfo && requestOptions.headers) {
|
|
230
|
-
(requestOptions.headers as any).authorization =
|
|
230
|
+
(requestOptions.headers as any).authorization =
|
|
231
|
+
`${authInfo.type} ${authInfo.token}`;
|
|
231
232
|
}
|
|
232
233
|
if (options?.requestOptions) {
|
|
233
234
|
requestOptions = { ...requestOptions, ...options.requestOptions };
|
package/src/versions.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { t } from './utils/i18n';
|
|
|
4
4
|
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import { satisfies } from 'compare-versions';
|
|
7
|
-
import type { Package, Platform, Version } from './types';
|
|
8
7
|
import { getPlatform, getSelectedApp } from './app';
|
|
9
8
|
import { choosePackage } from './package';
|
|
9
|
+
import type { Package, Platform, Version } from './types';
|
|
10
10
|
import { depVersions } from './utils/dep-versions';
|
|
11
11
|
import { getCommitInfo } from './utils/git';
|
|
12
12
|
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
const Zip = require('./zip');
|
|
2
|
-
const yazl = require('yazl');
|
|
3
|
-
const fs = require('fs-extra');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { open: openZipFile } = require('yauzl');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
|
|
8
|
-
class AabParser extends Zip {
|
|
9
|
-
/**
|
|
10
|
-
* parser for parsing .aab file
|
|
11
|
-
* @param {String | File | Blob} file // file's path in Node, instance of File or Blob in Browser
|
|
12
|
-
*/
|
|
13
|
-
constructor(file) {
|
|
14
|
-
super(file);
|
|
15
|
-
if (!(this instanceof AabParser)) {
|
|
16
|
-
return new AabParser(file);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 从 AAB 提取通用 APK
|
|
22
|
-
* 这个方法会合并 base/ 和所有 split/ 目录的内容
|
|
23
|
-
*
|
|
24
|
-
* @param {String} outputPath - 输出 APK 文件路径
|
|
25
|
-
* @param {Object} options - 选项
|
|
26
|
-
* @param {Boolean} options.includeAllSplits - 是否包含所有 split APK(默认 false,只提取 base)
|
|
27
|
-
* @param {Array<String>} options.splits - 指定要包含的 split APK 名称(如果指定,则只包含这些)
|
|
28
|
-
* @returns {Promise<String>} 返回输出文件路径
|
|
29
|
-
*/
|
|
30
|
-
async extractApk(outputPath, options = {}) {
|
|
31
|
-
const { includeAllSplits = false, splits = null } = options;
|
|
32
|
-
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
if (typeof this.file !== 'string') {
|
|
35
|
-
return reject(
|
|
36
|
-
new Error('AAB file path must be a string in Node.js environment'),
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
openZipFile(this.file, { lazyEntries: true }, async (err, zipfile) => {
|
|
41
|
-
if (err) {
|
|
42
|
-
return reject(err);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
// 1. 收集所有条目及其数据
|
|
47
|
-
const baseEntries = [];
|
|
48
|
-
const splitEntries = [];
|
|
49
|
-
const metaInfEntries = [];
|
|
50
|
-
let pendingReads = 0;
|
|
51
|
-
let hasError = false;
|
|
52
|
-
|
|
53
|
-
const processEntry = (entry, fileName) => {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
zipfile.openReadStream(entry, (err, readStream) => {
|
|
56
|
-
if (err) {
|
|
57
|
-
return reject(err);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const chunks = [];
|
|
61
|
-
readStream.on('data', (chunk) => chunks.push(chunk));
|
|
62
|
-
readStream.on('end', () => {
|
|
63
|
-
const buffer = Buffer.concat(chunks);
|
|
64
|
-
resolve(buffer);
|
|
65
|
-
});
|
|
66
|
-
readStream.on('error', reject);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
zipfile.on('entry', async (entry) => {
|
|
72
|
-
const fileName = entry.fileName;
|
|
73
|
-
|
|
74
|
-
// 跳过目录
|
|
75
|
-
if (fileName.endsWith('/')) {
|
|
76
|
-
zipfile.readEntry();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
pendingReads++;
|
|
81
|
-
try {
|
|
82
|
-
const buffer = await processEntry(entry, fileName);
|
|
83
|
-
|
|
84
|
-
if (fileName.startsWith('base/')) {
|
|
85
|
-
// 将 base/manifest/AndroidManifest.xml 转换为 androidmanifest.xml(APK 中通常是小写)
|
|
86
|
-
// 将 base/resources.arsc 转换为 resources.arsc
|
|
87
|
-
let apkPath = fileName.replace(/^base\//, '');
|
|
88
|
-
if (apkPath === 'manifest/AndroidManifest.xml') {
|
|
89
|
-
apkPath = 'androidmanifest.xml';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
baseEntries.push({
|
|
93
|
-
buffer,
|
|
94
|
-
zipPath: fileName,
|
|
95
|
-
apkPath,
|
|
96
|
-
});
|
|
97
|
-
} else if (fileName.startsWith('split/')) {
|
|
98
|
-
splitEntries.push({
|
|
99
|
-
buffer,
|
|
100
|
-
zipPath: fileName,
|
|
101
|
-
});
|
|
102
|
-
} else if (fileName.startsWith('META-INF/')) {
|
|
103
|
-
metaInfEntries.push({
|
|
104
|
-
buffer,
|
|
105
|
-
zipPath: fileName,
|
|
106
|
-
apkPath: fileName,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// BundleConfig.pb 和其他文件不需要包含在 APK 中
|
|
110
|
-
|
|
111
|
-
pendingReads--;
|
|
112
|
-
zipfile.readEntry();
|
|
113
|
-
} catch (error) {
|
|
114
|
-
pendingReads--;
|
|
115
|
-
if (!hasError) {
|
|
116
|
-
hasError = true;
|
|
117
|
-
reject(error);
|
|
118
|
-
}
|
|
119
|
-
zipfile.readEntry();
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
zipfile.on('end', async () => {
|
|
124
|
-
// 等待所有读取完成
|
|
125
|
-
while (pendingReads > 0) {
|
|
126
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (hasError) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
// 2. 创建新的 APK 文件
|
|
135
|
-
const zipFile = new yazl.ZipFile();
|
|
136
|
-
|
|
137
|
-
// 3. 添加 base 目录的所有文件
|
|
138
|
-
for (const { buffer, apkPath } of baseEntries) {
|
|
139
|
-
zipFile.addBuffer(buffer, apkPath);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// 4. 添加 split APK 的内容(如果需要)
|
|
143
|
-
if (includeAllSplits || splits) {
|
|
144
|
-
const splitsToInclude = splits
|
|
145
|
-
? splitEntries.filter((se) =>
|
|
146
|
-
splits.some((s) => se.zipPath.includes(s)),
|
|
147
|
-
)
|
|
148
|
-
: splitEntries;
|
|
149
|
-
|
|
150
|
-
await this.mergeSplitApksFromBuffers(zipFile, splitsToInclude);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 5. 添加 META-INF(签名信息,虽然可能无效,但保留结构)
|
|
154
|
-
for (const { buffer, apkPath } of metaInfEntries) {
|
|
155
|
-
zipFile.addBuffer(buffer, apkPath);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// 6. 写入文件
|
|
159
|
-
zipFile.outputStream
|
|
160
|
-
.pipe(fs.createWriteStream(outputPath))
|
|
161
|
-
.on('close', () => {
|
|
162
|
-
resolve(outputPath);
|
|
163
|
-
})
|
|
164
|
-
.on('error', (err) => {
|
|
165
|
-
reject(err);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
zipFile.end();
|
|
169
|
-
} catch (error) {
|
|
170
|
-
reject(error);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
zipfile.on('error', reject);
|
|
175
|
-
zipfile.readEntry();
|
|
176
|
-
} catch (error) {
|
|
177
|
-
reject(error);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 合并 split APK 的内容(从已读取的 buffer)
|
|
185
|
-
*/
|
|
186
|
-
async mergeSplitApksFromBuffers(zipFile, splitEntries) {
|
|
187
|
-
for (const { buffer: splitBuffer } of splitEntries) {
|
|
188
|
-
if (splitBuffer) {
|
|
189
|
-
// 创建一个临时的 ZIP 文件来读取 split APK
|
|
190
|
-
const tempSplitPath = path.join(
|
|
191
|
-
os.tmpdir(),
|
|
192
|
-
`split_${Date.now()}_${Math.random().toString(36).substr(2, 9)}.apk`,
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
try {
|
|
196
|
-
await fs.writeFile(tempSplitPath, splitBuffer);
|
|
197
|
-
|
|
198
|
-
await new Promise((resolve, reject) => {
|
|
199
|
-
openZipFile(
|
|
200
|
-
tempSplitPath,
|
|
201
|
-
{ lazyEntries: true },
|
|
202
|
-
async (err, splitZipfile) => {
|
|
203
|
-
if (err) {
|
|
204
|
-
return reject(err);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
splitZipfile.on('entry', (splitEntry) => {
|
|
208
|
-
// 跳过 META-INF,因为签名信息不需要合并
|
|
209
|
-
if (splitEntry.fileName.startsWith('META-INF/')) {
|
|
210
|
-
splitZipfile.readEntry();
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
splitZipfile.openReadStream(splitEntry, (err, readStream) => {
|
|
215
|
-
if (err) {
|
|
216
|
-
splitZipfile.readEntry();
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const chunks = [];
|
|
221
|
-
readStream.on('data', (chunk) => chunks.push(chunk));
|
|
222
|
-
readStream.on('end', () => {
|
|
223
|
-
const buffer = Buffer.concat(chunks);
|
|
224
|
-
// 注意:如果文件已存在(在 base 中),split 中的会覆盖 base 中的
|
|
225
|
-
zipFile.addBuffer(buffer, splitEntry.fileName);
|
|
226
|
-
splitZipfile.readEntry();
|
|
227
|
-
});
|
|
228
|
-
readStream.on('error', () => {
|
|
229
|
-
splitZipfile.readEntry();
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
splitZipfile.on('end', resolve);
|
|
235
|
-
splitZipfile.on('error', reject);
|
|
236
|
-
splitZipfile.readEntry();
|
|
237
|
-
},
|
|
238
|
-
);
|
|
239
|
-
});
|
|
240
|
-
} finally {
|
|
241
|
-
// 清理临时文件
|
|
242
|
-
await fs.remove(tempSplitPath).catch(() => {});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* 解析 AAB 文件信息(类似 APK parser 的 parse 方法)
|
|
250
|
-
* 注意:AAB 中的 AndroidManifest.xml 在 base/manifest/AndroidManifest.xml
|
|
251
|
-
*/
|
|
252
|
-
async parse() {
|
|
253
|
-
// 尝试从 base/manifest/AndroidManifest.xml 读取 manifest
|
|
254
|
-
// 但 AAB 中的 manifest 可能是二进制格式,需要特殊处理
|
|
255
|
-
const manifestPath = 'base/manifest/AndroidManifest.xml';
|
|
256
|
-
const ResourceName = /^base\/resources\.arsc$/;
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
const manifestBuffer = await this.getEntry(
|
|
260
|
-
new RegExp(`^${manifestPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`),
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
if (!manifestBuffer) {
|
|
264
|
-
throw new Error(
|
|
265
|
-
"AndroidManifest.xml can't be found in AAB base/manifest/",
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
let apkInfo = this._parseManifest(manifestBuffer);
|
|
270
|
-
|
|
271
|
-
// 尝试解析 resources.arsc
|
|
272
|
-
try {
|
|
273
|
-
const resourceBuffer = await this.getEntry(ResourceName);
|
|
274
|
-
if (resourceBuffer) {
|
|
275
|
-
const resourceMap = this._parseResourceMap(resourceBuffer);
|
|
276
|
-
const { mapInfoResource } = require('./utils');
|
|
277
|
-
apkInfo = mapInfoResource(apkInfo, resourceMap);
|
|
278
|
-
}
|
|
279
|
-
} catch (e) {
|
|
280
|
-
// resources.arsc 解析失败不影响基本信息
|
|
281
|
-
console.warn('[Warning] Failed to parse resources.arsc:', e.message);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return apkInfo;
|
|
285
|
-
} catch (error) {
|
|
286
|
-
throw new Error(`Failed to parse AAB: ${error.message}`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Parse manifest
|
|
292
|
-
* @param {Buffer} buffer // manifest file's buffer
|
|
293
|
-
*/
|
|
294
|
-
_parseManifest(buffer) {
|
|
295
|
-
try {
|
|
296
|
-
const ManifestXmlParser = require('./xml-parser/manifest');
|
|
297
|
-
const parser = new ManifestXmlParser(buffer, {
|
|
298
|
-
ignore: [
|
|
299
|
-
'application.activity',
|
|
300
|
-
'application.service',
|
|
301
|
-
'application.receiver',
|
|
302
|
-
'application.provider',
|
|
303
|
-
'permission-group',
|
|
304
|
-
],
|
|
305
|
-
});
|
|
306
|
-
return parser.parse();
|
|
307
|
-
} catch (e) {
|
|
308
|
-
throw new Error('Parse AndroidManifest.xml error: ' + e.message);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Parse resourceMap
|
|
314
|
-
* @param {Buffer} buffer // resourceMap file's buffer
|
|
315
|
-
*/
|
|
316
|
-
_parseResourceMap(buffer) {
|
|
317
|
-
try {
|
|
318
|
-
const ResourceFinder = require('./resource-finder');
|
|
319
|
-
return new ResourceFinder().processResourceTable(buffer);
|
|
320
|
-
} catch (e) {
|
|
321
|
-
throw new Error('Parser resources.arsc error: ' + e.message);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
module.exports = AabParser;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const Zip = require('./zip');
|
|
2
|
-
|
|
3
|
-
class AppParser extends Zip {
|
|
4
|
-
/**
|
|
5
|
-
* parser for parsing .apk file
|
|
6
|
-
* @param {String | File | Blob} file // file's path in Node, instance of File or Blob in Browser
|
|
7
|
-
*/
|
|
8
|
-
constructor(file) {
|
|
9
|
-
super(file);
|
|
10
|
-
if (!(this instanceof AppParser)) {
|
|
11
|
-
return new AppParser(file);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = AppParser;
|