react-native-update-cli 2.29.1 → 2.29.3
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/account.js +2 -4
- package/lib/api.d.ts +1 -1
- package/lib/api.js +26 -44
- package/lib/app.js +13 -27
- package/lib/auto-update.d.ts +1 -1
- package/lib/auto-update.js +6 -16
- package/lib/bin.js +4 -6
- package/lib/bundle-pack.js +25 -27
- package/lib/bundle-runner.js +55 -54
- package/lib/bundle.js +18 -26
- package/lib/diff.js +32 -91
- package/lib/locales/en.d.ts +0 -10
- package/lib/locales/en.js +0 -10
- package/lib/locales/zh.d.ts +0 -10
- package/lib/locales/zh.js +0 -10
- package/lib/native-package.js +20 -60
- package/lib/package.d.ts +6 -1
- package/lib/package.js +59 -74
- package/lib/provider.js +3 -5
- package/lib/symbolicate.js +1 -16
- package/lib/utils/add-gitignore.js +0 -1
- package/lib/utils/app-info-parser/aab.d.ts +5 -22
- package/lib/utils/app-info-parser/aab.js +87 -192
- package/lib/utils/app-info-parser/apk.d.ts +12 -13
- package/lib/utils/app-info-parser/apk.js +28 -78
- package/lib/utils/app-info-parser/ipa.d.ts +2 -14
- package/lib/utils/app-info-parser/ipa.js +9 -70
- package/lib/utils/app-info-parser/resource-finder.d.ts +1 -26
- package/lib/utils/app-info-parser/resource-finder.js +41 -183
- package/lib/utils/app-info-parser/xml-parser/binary.d.ts +6 -55
- package/lib/utils/app-info-parser/xml-parser/binary.js +152 -556
- package/lib/utils/app-info-parser/zip.d.ts +6 -24
- package/lib/utils/app-info-parser/zip.js +19 -86
- package/lib/utils/check-plugin.d.ts +7 -5
- package/lib/utils/check-plugin.js +15 -25
- package/lib/utils/dep-versions.d.ts +0 -6
- package/lib/utils/dep-versions.js +2 -27
- package/lib/utils/failure-fingerprint.js +3 -4
- package/lib/utils/fs-helpers.d.ts +5 -0
- package/lib/utils/fs-helpers.js +19 -0
- package/lib/utils/git.d.ts +0 -1
- package/lib/utils/git.js +0 -8
- package/lib/utils/hash.d.ts +3 -0
- package/lib/utils/hash.js +19 -0
- package/lib/utils/hbcTransform.d.ts +9 -2
- package/lib/utils/hbcTransform.js +41 -70
- package/lib/utils/hermes-base.d.ts +1 -5
- package/lib/utils/hermes-base.js +93 -156
- package/lib/utils/hermes-literals.d.ts +5 -3
- package/lib/utils/hermes-literals.js +30 -53
- package/lib/utils/hermes-raw.d.ts +7 -0
- package/lib/utils/hermes-raw.js +26 -9
- package/lib/utils/http-helper.d.ts +0 -1
- package/lib/utils/http-helper.js +0 -20
- package/lib/utils/i18n.js +0 -2
- package/lib/utils/index.d.ts +5 -19
- package/lib/utils/index.js +95 -189
- package/lib/utils/latest-version.d.ts +19 -0
- package/lib/utils/latest-version.js +137 -0
- package/lib/utils/options.d.ts +2 -1
- package/lib/utils/options.js +5 -7
- package/lib/utils/zip-entries.d.ts +23 -0
- package/lib/utils/zip-entries.js +125 -102
- package/lib/utils/zip-options.js +29 -56
- package/lib/utils/zip-range.js +25 -65
- package/lib/versions.d.ts +5 -0
- package/lib/versions.js +86 -153
- package/package.json +1 -3
- package/lib/utils/app-info-parser/app.d.ts +0 -4
- package/lib/utils/app-info-parser/app.js +0 -10
- package/lib/utils/app-info-parser/index.d.ts +0 -16
- package/lib/utils/app-info-parser/index.js +0 -46
- package/lib/utils/app-info-parser/utils.d.ts +0 -31
- package/lib/utils/app-info-parser/utils.js +0 -135
- package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +0 -10
- package/lib/utils/app-info-parser/xml-parser/manifest.js +0 -202
- package/lib/utils/latest-version/index.d.ts +0 -149
- package/lib/utils/latest-version/index.js +0 -326
- package/lib/utils/plugin-config.d.ts +0 -9
- package/lib/utils/plugin-config.js +0 -31
package/lib/package.js
CHANGED
|
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.packageCommands = void 0;
|
|
7
|
-
exports.
|
|
7
|
+
exports.toNumericIds = toNumericIds;
|
|
8
|
+
exports.deleteByIds = deleteByIds;
|
|
8
9
|
exports.listPackage = listPackage;
|
|
9
10
|
exports.choosePackage = choosePackage;
|
|
10
11
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -22,13 +23,14 @@ const hermes_base_1 = require("./utils/hermes-base");
|
|
|
22
23
|
const i18n_1 = require("./utils/i18n");
|
|
23
24
|
const options_1 = require("./utils/options");
|
|
24
25
|
const zip_range_1 = require("./utils/zip-range");
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// parse* output is JSON so the bundleHash (content fingerprint) can be piped
|
|
27
|
+
// into jq; the raw bundle bytes are dropped — a Buffer preview is just noise.
|
|
28
|
+
function printPackageInfo({ bundleFile: _bundleFile, ...info }) {
|
|
29
|
+
console.log(JSON.stringify(info, null, 2));
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
// the AAB parser drags in protobufjs; load it only for the aab commands
|
|
32
|
+
function loadExtractApk() {
|
|
33
|
+
return require('./utils/app-info-parser/aab').extractApk;
|
|
32
34
|
}
|
|
33
35
|
function ensureFileByExt(filePath, extension, usageKey) {
|
|
34
36
|
if (!filePath?.endsWith(extension)) {
|
|
@@ -36,19 +38,6 @@ function ensureFileByExt(filePath, extension, usageKey) {
|
|
|
36
38
|
}
|
|
37
39
|
return filePath;
|
|
38
40
|
}
|
|
39
|
-
function parseBooleanOption(value) {
|
|
40
|
-
return value === true || value === 'true';
|
|
41
|
-
}
|
|
42
|
-
function parseCsvOption(value) {
|
|
43
|
-
if (typeof value !== 'string') {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const parsed = value
|
|
47
|
-
.split(',')
|
|
48
|
-
.map((item) => item.trim())
|
|
49
|
-
.filter(Boolean);
|
|
50
|
-
return parsed.length > 0 ? parsed : null;
|
|
51
|
-
}
|
|
52
41
|
function toNumericIds(ids) {
|
|
53
42
|
return ids.map((id) => {
|
|
54
43
|
const numericId = Number(id);
|
|
@@ -58,6 +47,42 @@ function toNumericIds(ids) {
|
|
|
58
47
|
return numericId;
|
|
59
48
|
});
|
|
60
49
|
}
|
|
50
|
+
const deleteMessages = {
|
|
51
|
+
version: {
|
|
52
|
+
one: 'deleteVersionSuccess',
|
|
53
|
+
many: 'deleteVersionsSuccess',
|
|
54
|
+
error: 'deleteVersionError',
|
|
55
|
+
},
|
|
56
|
+
package: {
|
|
57
|
+
one: 'deletePackageSuccess',
|
|
58
|
+
many: 'deletePackagesSuccess',
|
|
59
|
+
error: 'deletePackageError',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Delete versions or packages of an app: one id through
|
|
64
|
+
* `DELETE /app/:appId/<kind>/:id`, several in one `DELETE /app/:appId/<kind>`.
|
|
65
|
+
*/
|
|
66
|
+
async function deleteByIds(appId, kind, ids) {
|
|
67
|
+
const messages = deleteMessages[kind];
|
|
68
|
+
try {
|
|
69
|
+
if (ids.length === 1) {
|
|
70
|
+
const [id] = ids;
|
|
71
|
+
await (0, api_1.doDelete)(`/app/${appId}/${kind}/${id}`);
|
|
72
|
+
console.log((0, i18n_1.t)(messages.one, { [`${kind}Id`]: id }));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
await (0, api_1.doDelete)(`/app/${appId}/${kind}`, {
|
|
76
|
+
[`${kind}Ids`]: toNumericIds(ids),
|
|
77
|
+
});
|
|
78
|
+
console.log((0, i18n_1.t)(messages.many, { count: ids.length, [`${kind}Ids`]: ids.join(', ') }));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
83
|
+
throw new Error((0, i18n_1.t)(messages.error, { [`${kind}Id`]: ids.join(', '), error: message }));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
61
86
|
function getVersionBinding(version) {
|
|
62
87
|
if (!version || typeof version !== 'object') {
|
|
63
88
|
return undefined;
|
|
@@ -96,7 +121,7 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
96
121
|
const slimPackagePath = path_1.default.join(tempRoot, `package${config.extension}`);
|
|
97
122
|
try {
|
|
98
123
|
await (0, native_package_1.createSlimNativePackage)(filePath, slimPackagePath, config.platform);
|
|
99
|
-
const { hash } = await (0, api_1.uploadFile)(slimPackagePath,
|
|
124
|
+
const { hash } = await (0, api_1.uploadFile)(slimPackagePath, appId);
|
|
100
125
|
// where the bundle sits inside the uploaded (slim) archive, so a later
|
|
101
126
|
// `bundle` that falls back to this package as hermes base fetches only
|
|
102
127
|
// the bundle with one HTTP Range request. Harmony .app nests a second
|
|
@@ -110,14 +135,10 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
110
135
|
// already hashed the bundle, so pass that hash instead of hashing twice
|
|
111
136
|
await (0, hermes_base_1.cachePut)(bundleFile, undefined, bundleHash).catch(() => { });
|
|
112
137
|
}
|
|
113
|
-
const normalizedBuildTime = config.normalizeBuildTime
|
|
114
|
-
? config.normalizeBuildTime(buildTime)
|
|
115
|
-
: buildTime;
|
|
116
|
-
const uploadBuildTime = normalizeUploadBuildTime(normalizedBuildTime);
|
|
117
138
|
const { id } = await (0, api_1.post)(`/app/${appId}/package/create`, {
|
|
118
139
|
name: versionName,
|
|
119
140
|
hash,
|
|
120
|
-
buildTime:
|
|
141
|
+
buildTime: String(buildTime),
|
|
121
142
|
// Content identity of the embedded JS bundle; the server matches it
|
|
122
143
|
// against the client-reported bundleHash to decide pdiff applicability.
|
|
123
144
|
// Old servers strip unknown fields, so this is forward-compatible.
|
|
@@ -134,7 +155,7 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
134
155
|
console.log((0, i18n_1.t)(config.successKey, {
|
|
135
156
|
id,
|
|
136
157
|
version: versionName,
|
|
137
|
-
buildTime:
|
|
158
|
+
buildTime: String(buildTime),
|
|
138
159
|
}));
|
|
139
160
|
}
|
|
140
161
|
finally {
|
|
@@ -222,11 +243,10 @@ exports.packageCommands = {
|
|
|
222
243
|
// the shared tmpdir and against concurrent uploads of same-named AABs
|
|
223
244
|
const tempRoot = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-aab-upload-'));
|
|
224
245
|
const output = path_1.default.join(tempRoot, 'universal.apk');
|
|
225
|
-
const includeAllSplits =
|
|
226
|
-
const splits =
|
|
227
|
-
const parser = createAabParser(source);
|
|
246
|
+
const includeAllSplits = (0, options_1.getBooleanOption)(options, 'includeAllSplits');
|
|
247
|
+
const splits = (0, options_1.getStringListOption)(options, 'splits');
|
|
228
248
|
try {
|
|
229
|
-
await
|
|
249
|
+
await loadExtractApk()(source, output, {
|
|
230
250
|
includeAllSplits,
|
|
231
251
|
splits,
|
|
232
252
|
});
|
|
@@ -248,7 +268,6 @@ exports.packageCommands = {
|
|
|
248
268
|
appKeyMismatchKey: 'appKeyMismatchApp',
|
|
249
269
|
successKey: 'appUploadSuccess',
|
|
250
270
|
getInfo: (filePath) => (0, utils_1.getAppInfo)(filePath),
|
|
251
|
-
normalizeBuildTime: (buildTime) => String(buildTime),
|
|
252
271
|
});
|
|
253
272
|
},
|
|
254
273
|
parseApp: async ({ args }) => {
|
|
@@ -256,37 +275,36 @@ exports.packageCommands = {
|
|
|
256
275
|
if (!fn?.endsWith('.app')) {
|
|
257
276
|
throw new Error((0, i18n_1.t)('usageParseApp'));
|
|
258
277
|
}
|
|
259
|
-
|
|
278
|
+
printPackageInfo(await (0, utils_1.getAppInfo)(fn));
|
|
260
279
|
},
|
|
261
280
|
parseIpa: async ({ args }) => {
|
|
262
281
|
const fn = args[0];
|
|
263
282
|
if (!fn?.endsWith('.ipa')) {
|
|
264
283
|
throw new Error((0, i18n_1.t)('usageParseIpa'));
|
|
265
284
|
}
|
|
266
|
-
|
|
285
|
+
printPackageInfo(await (0, utils_1.getIpaInfo)(fn));
|
|
267
286
|
},
|
|
268
287
|
parseApk: async ({ args }) => {
|
|
269
288
|
const fn = args[0];
|
|
270
289
|
if (!fn?.endsWith('.apk')) {
|
|
271
290
|
throw new Error((0, i18n_1.t)('usageParseApk'));
|
|
272
291
|
}
|
|
273
|
-
|
|
292
|
+
printPackageInfo(await (0, utils_1.getApkInfo)(fn));
|
|
274
293
|
},
|
|
275
294
|
parseAab: async ({ args }) => {
|
|
276
295
|
const fn = args[0];
|
|
277
296
|
if (!fn?.endsWith('.aab')) {
|
|
278
297
|
throw new Error((0, i18n_1.t)('usageParseAab'));
|
|
279
298
|
}
|
|
280
|
-
|
|
299
|
+
printPackageInfo(await (0, utils_1.getAabInfo)(fn));
|
|
281
300
|
},
|
|
282
301
|
extractApk: async ({ args, options, }) => {
|
|
283
302
|
const source = ensureFileByExt(args[0], '.aab', 'usageExtractApk');
|
|
284
303
|
const output = options.output ||
|
|
285
304
|
path_1.default.join(path_1.default.dirname(source), `${path_1.default.basename(source, path_1.default.extname(source))}.apk`);
|
|
286
|
-
const includeAllSplits =
|
|
287
|
-
const splits =
|
|
288
|
-
|
|
289
|
-
await parser.extractApk(output, {
|
|
305
|
+
const includeAllSplits = (0, options_1.getBooleanOption)(options, 'includeAllSplits');
|
|
306
|
+
const splits = (0, options_1.getStringListOption)(options, 'splits');
|
|
307
|
+
await loadExtractApk()(source, output, {
|
|
290
308
|
includeAllSplits,
|
|
291
309
|
splits,
|
|
292
310
|
});
|
|
@@ -317,39 +335,6 @@ exports.packageCommands = {
|
|
|
317
335
|
return String(selectedPackage.id);
|
|
318
336
|
});
|
|
319
337
|
}
|
|
320
|
-
|
|
321
|
-
// const confirmDelete = await question(
|
|
322
|
-
// t('confirmDeletePackage', { packageId }),
|
|
323
|
-
// );
|
|
324
|
-
// if (
|
|
325
|
-
// confirmDelete.toLowerCase() !== 'y' &&
|
|
326
|
-
// confirmDelete.toLowerCase() !== 'yes'
|
|
327
|
-
// ) {
|
|
328
|
-
// console.log(t('cancelled'));
|
|
329
|
-
// return;
|
|
330
|
-
// }
|
|
331
|
-
try {
|
|
332
|
-
if (packageIds.length === 1) {
|
|
333
|
-
const [packageId] = packageIds;
|
|
334
|
-
await (0, api_1.doDelete)(`/app/${appId}/package/${packageId}`);
|
|
335
|
-
console.log((0, i18n_1.t)('deletePackageSuccess', { packageId }));
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
await (0, api_1.doDelete)(`/app/${appId}/package`, {
|
|
339
|
-
packageIds: toNumericIds(packageIds),
|
|
340
|
-
});
|
|
341
|
-
console.log((0, i18n_1.t)('deletePackagesSuccess', {
|
|
342
|
-
count: packageIds.length,
|
|
343
|
-
packageIds: packageIds.join(', '),
|
|
344
|
-
}));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
349
|
-
throw new Error((0, i18n_1.t)('deletePackageError', {
|
|
350
|
-
packageId: packageIds.join(', '),
|
|
351
|
-
error: message,
|
|
352
|
-
}));
|
|
353
|
-
}
|
|
338
|
+
await deleteByIds(appId, 'package', packageIds);
|
|
354
339
|
},
|
|
355
340
|
};
|
package/lib/provider.js
CHANGED
|
@@ -60,12 +60,10 @@ class CLIProviderImpl {
|
|
|
60
60
|
await this.sessionInitPromise;
|
|
61
61
|
}
|
|
62
62
|
runMessageCommand(task, fallbackError, successMessage, requireSession = true) {
|
|
63
|
-
return
|
|
64
|
-
if (requireSession) {
|
|
65
|
-
await this.ensureInitialized();
|
|
66
|
-
}
|
|
63
|
+
return this.runDataCommand(async () => {
|
|
67
64
|
await task();
|
|
68
|
-
|
|
65
|
+
return { message: successMessage };
|
|
66
|
+
}, fallbackError, requireSession);
|
|
69
67
|
}
|
|
70
68
|
runDataCommand(task, fallbackError, requireSession = true) {
|
|
71
69
|
return (0, command_result_1.runAsCommandResult)(async () => {
|
package/lib/symbolicate.js
CHANGED
|
@@ -42,21 +42,6 @@ function symbolicateStack(stack, consumer) {
|
|
|
42
42
|
});
|
|
43
43
|
return { text, mapped };
|
|
44
44
|
}
|
|
45
|
-
async function findVersionByHash(appId, hash) {
|
|
46
|
-
const limit = 100;
|
|
47
|
-
// The list is newest-first; crashes are usually about recent versions.
|
|
48
|
-
for (let offset = 0; offset < 100 * limit; offset += limit) {
|
|
49
|
-
const page = await (0, versions_1.fetchVersions)(appId, offset, limit);
|
|
50
|
-
const found = page.find((version) => version.hash === hash);
|
|
51
|
-
if (found) {
|
|
52
|
-
return found;
|
|
53
|
-
}
|
|
54
|
-
if (page.length < limit) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
45
|
async function readStack(source) {
|
|
61
46
|
if (!source || source === '-') {
|
|
62
47
|
// No file and an interactive terminal: nothing is piped in, so waiting on
|
|
@@ -89,7 +74,7 @@ exports.symbolicateCommands = {
|
|
|
89
74
|
.appId;
|
|
90
75
|
let versionId = versionIdOption;
|
|
91
76
|
if (!versionId) {
|
|
92
|
-
const version = await
|
|
77
|
+
const version = await (0, versions_1.findVersion)(appId, (item) => item.hash === hash);
|
|
93
78
|
if (!version) {
|
|
94
79
|
throw new Error((0, i18n_1.t)('symbolicateVersionNotFound', { hash }));
|
|
95
80
|
}
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.addGitIgnore = addGitIgnore;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
// import path from 'path';
|
|
9
8
|
const constants_1 = require("./constants");
|
|
10
9
|
const i18n_1 = require("./i18n");
|
|
11
10
|
function addGitIgnore() {
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* 解析 AAB 文件信息(类似 APK parser 的 parse 方法)
|
|
9
|
-
* 注意:AAB 中的 AndroidManifest.xml 在 base/manifest/AndroidManifest.xml
|
|
10
|
-
*/
|
|
11
|
-
parse(): Promise<Record<string, any>>;
|
|
12
|
-
/**
|
|
13
|
-
* Parse manifest
|
|
14
|
-
* @param {Buffer} buffer // manifest file's buffer
|
|
15
|
-
*/
|
|
16
|
-
private _parseManifest;
|
|
17
|
-
/**
|
|
18
|
-
* Parse resourceMap
|
|
19
|
-
* @param {Buffer} buffer // resourceMap file's buffer
|
|
20
|
-
*/
|
|
21
|
-
private _parseResourceMap;
|
|
22
|
-
}
|
|
1
|
+
/** Build a universal APK from an .aab with bundletool (or npx node-bundletool). */
|
|
2
|
+
export declare function extractApk(aabPath: string, outputPath: string, { includeAllSplits, splits, }: {
|
|
3
|
+
includeAllSplits?: boolean;
|
|
4
|
+
splits?: string[] | null;
|
|
5
|
+
}): Promise<void>;
|
|
@@ -3,217 +3,112 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.extractApk = extractApk;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const yauzl_1 = require("yauzl");
|
|
12
11
|
const fs_helpers_1 = require("../fs-helpers");
|
|
13
12
|
const i18n_1 = require("../i18n");
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const zip_entries_1 = require("../zip-entries");
|
|
14
|
+
/** Build a universal APK from an .aab with bundletool (or npx node-bundletool). */
|
|
15
|
+
async function extractApk(aabPath, outputPath, { includeAllSplits, splits, }) {
|
|
16
|
+
const bundlePath = path_1.default.resolve(aabPath);
|
|
17
|
+
const normalizedSplits = Array.isArray(splits)
|
|
18
|
+
? splits.map((item) => item.trim()).filter(Boolean)
|
|
19
|
+
: [];
|
|
20
|
+
const modules = includeAllSplits
|
|
21
|
+
? null
|
|
22
|
+
: Array.from(new Set(['base', ...normalizedSplits]));
|
|
23
|
+
const modulesArgs = modules ? [`--modules=${modules.join(',')}`] : [];
|
|
24
|
+
const runCommand = (command, args, options = {}) => new Promise((resolve, reject) => {
|
|
25
|
+
const inheritStdio = options.stdio === 'inherit';
|
|
26
|
+
const child = (0, child_process_1.spawn)(command, args, {
|
|
27
|
+
stdio: inheritStdio ? 'inherit' : ['ignore', 'pipe', 'pipe'],
|
|
28
|
+
env: options.env,
|
|
29
|
+
});
|
|
30
|
+
let stderr = '';
|
|
31
|
+
if (!inheritStdio) {
|
|
32
|
+
child.stderr?.on('data', (chunk) => {
|
|
33
|
+
stderr += chunk.toString();
|
|
32
34
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
}
|
|
36
|
+
child.on('error', reject);
|
|
37
|
+
child.on('close', (code) => {
|
|
38
|
+
if (code === 0) {
|
|
39
|
+
resolve();
|
|
40
|
+
return;
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
child.on('close', (code) => {
|
|
41
|
-
if (code === 0) {
|
|
42
|
-
resolve();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
reject(new Error(stderr.trim() || `Command failed: ${command} (code ${code})`));
|
|
46
|
-
});
|
|
42
|
+
reject(new Error(stderr.trim() || `Command failed: ${command} (code ${code})`));
|
|
47
43
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
await runCommand('npx', [
|
|
54
|
-
'--no-install',
|
|
55
|
-
'node-bundletool',
|
|
56
|
-
'--version',
|
|
57
|
-
]);
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
44
|
+
});
|
|
45
|
+
// Create a temp file for the .apks output
|
|
46
|
+
const tempDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'bundletool-'));
|
|
47
|
+
const tempApksPath = path_1.default.join(tempDir, 'output.apks');
|
|
48
|
+
const needsNpxDownload = async () => {
|
|
64
49
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// User might need keystore to sign it properly but for simple extraction we stick to default debug key if possible or unsigned?
|
|
68
|
-
// actually bundletool build-apks signs with debug key by default if no keystore provided.
|
|
69
|
-
try {
|
|
70
|
-
await runCommand('bundletool', [
|
|
71
|
-
'build-apks',
|
|
72
|
-
'--mode=universal',
|
|
73
|
-
`--bundle=${this.file}`,
|
|
74
|
-
`--output=${tempApksPath}`,
|
|
75
|
-
'--overwrite',
|
|
76
|
-
...modulesArgs,
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
// Only fall back when bundletool itself is missing from PATH (spawn
|
|
81
|
-
// ENOENT). Any other failure (corrupt AAB, Java issues, bad args,
|
|
82
|
-
// non-zero exit) must surface as-is instead of being masked by an
|
|
83
|
-
// online npx install.
|
|
84
|
-
if (e?.code !== 'ENOENT') {
|
|
85
|
-
throw e;
|
|
86
|
-
}
|
|
87
|
-
// Fallback to npx node-bundletool if bundletool is not in PATH
|
|
88
|
-
// We use -y to avoid interactive prompt for installation
|
|
89
|
-
if (await needsNpxDownload()) {
|
|
90
|
-
console.log((0, i18n_1.t)('aabBundletoolDownloadHint'));
|
|
91
|
-
}
|
|
92
|
-
await runCommand('npx', [
|
|
93
|
-
'-y',
|
|
94
|
-
'node-bundletool',
|
|
95
|
-
'build-apks',
|
|
96
|
-
'--mode=universal',
|
|
97
|
-
`--bundle=${this.file}`,
|
|
98
|
-
`--output=${tempApksPath}`,
|
|
99
|
-
'--overwrite',
|
|
100
|
-
...modulesArgs,
|
|
101
|
-
], {
|
|
102
|
-
stdio: 'inherit',
|
|
103
|
-
env: {
|
|
104
|
-
...process.env,
|
|
105
|
-
npm_config_progress: 'true',
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// 2. Extract universal.apk from the .apks (zip) file
|
|
110
|
-
await new Promise((resolve, reject) => {
|
|
111
|
-
(0, yauzl_1.open)(tempApksPath, { lazyEntries: true }, (err, zipfile) => {
|
|
112
|
-
if (err || !zipfile) {
|
|
113
|
-
reject(err || new Error((0, i18n_1.t)('aabOpenApksFailed')));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
let found = false;
|
|
117
|
-
zipfile.readEntry();
|
|
118
|
-
zipfile.on('entry', (entry) => {
|
|
119
|
-
if (entry.fileName === 'universal.apk') {
|
|
120
|
-
found = true;
|
|
121
|
-
zipfile.openReadStream(entry, (err, readStream) => {
|
|
122
|
-
if (err || !readStream) {
|
|
123
|
-
reject(err || new Error((0, i18n_1.t)('aabReadUniversalApkFailed')));
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const writeStream = fs_1.default.createWriteStream(outputPath);
|
|
127
|
-
readStream.pipe(writeStream);
|
|
128
|
-
writeStream.on('close', () => {
|
|
129
|
-
zipfile.close();
|
|
130
|
-
resolve();
|
|
131
|
-
});
|
|
132
|
-
readStream.on('error', reject);
|
|
133
|
-
writeStream.on('error', reject);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
zipfile.readEntry();
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
zipfile.on('end', () => {
|
|
141
|
-
if (!found)
|
|
142
|
-
reject(new Error((0, i18n_1.t)('aabUniversalApkNotFound')));
|
|
143
|
-
});
|
|
144
|
-
zipfile.on('error', reject);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
50
|
+
await runCommand('npx', ['--no-install', 'node-bundletool', '--version']);
|
|
51
|
+
return false;
|
|
147
52
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (await (0, fs_helpers_1.pathExists)(tempDir)) {
|
|
151
|
-
await (0, fs_helpers_1.remove)(tempDir);
|
|
152
|
-
}
|
|
53
|
+
catch {
|
|
54
|
+
return true;
|
|
153
55
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const manifestPath = 'base/manifest/AndroidManifest.xml';
|
|
161
|
-
const ResourceName = /^base\/resources\.arsc$/;
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
// 1. Build APKS (universal mode)
|
|
59
|
+
// We assume bundletool is in the path.
|
|
60
|
+
// User might need keystore to sign it properly but for simple extraction we stick to default debug key if possible or unsigned?
|
|
61
|
+
// actually bundletool build-apks signs with debug key by default if no keystore provided.
|
|
162
62
|
try {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
63
|
+
await runCommand('bundletool', [
|
|
64
|
+
'build-apks',
|
|
65
|
+
'--mode=universal',
|
|
66
|
+
`--bundle=${bundlePath}`,
|
|
67
|
+
`--output=${tempApksPath}`,
|
|
68
|
+
'--overwrite',
|
|
69
|
+
...modulesArgs,
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
// Only fall back when bundletool itself is missing from PATH (spawn
|
|
74
|
+
// ENOENT). Any other failure (corrupt AAB, Java issues, bad args,
|
|
75
|
+
// non-zero exit) must surface as-is instead of being masked by an
|
|
76
|
+
// online npx install.
|
|
77
|
+
if (e?.code !== 'ENOENT') {
|
|
78
|
+
throw e;
|
|
174
79
|
}
|
|
175
|
-
|
|
176
|
-
|
|
80
|
+
// Fallback to npx node-bundletool if bundletool is not in PATH
|
|
81
|
+
// We use -y to avoid interactive prompt for installation
|
|
82
|
+
if (await needsNpxDownload()) {
|
|
83
|
+
console.log((0, i18n_1.t)('aabBundletoolDownloadHint'));
|
|
177
84
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
'application.service',
|
|
194
|
-
'application.receiver',
|
|
195
|
-
'application.provider',
|
|
196
|
-
'permission-group',
|
|
197
|
-
],
|
|
85
|
+
await runCommand('npx', [
|
|
86
|
+
'-y',
|
|
87
|
+
'node-bundletool',
|
|
88
|
+
'build-apks',
|
|
89
|
+
'--mode=universal',
|
|
90
|
+
`--bundle=${bundlePath}`,
|
|
91
|
+
`--output=${tempApksPath}`,
|
|
92
|
+
'--overwrite',
|
|
93
|
+
...modulesArgs,
|
|
94
|
+
], {
|
|
95
|
+
stdio: 'inherit',
|
|
96
|
+
env: {
|
|
97
|
+
...process.env,
|
|
98
|
+
npm_config_progress: 'true',
|
|
99
|
+
},
|
|
198
100
|
});
|
|
199
|
-
return parser.parse();
|
|
200
101
|
}
|
|
201
|
-
|
|
202
|
-
|
|
102
|
+
// 2. Extract universal.apk from the .apks (zip) file
|
|
103
|
+
const found = await (0, zip_entries_1.extractFirstEntry)(tempApksPath, (name) => name === 'universal.apk', outputPath);
|
|
104
|
+
if (!found) {
|
|
105
|
+
throw new Error((0, i18n_1.t)('aabUniversalApkNotFound'));
|
|
203
106
|
}
|
|
204
107
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
_parseResourceMap(buffer) {
|
|
210
|
-
try {
|
|
211
|
-
return new resource_finder_1.ResourceFinder().processResourceTable(buffer);
|
|
212
|
-
}
|
|
213
|
-
catch (e) {
|
|
214
|
-
throw new Error((0, i18n_1.t)('aabParseResourcesError', { error: e?.message ?? e }));
|
|
108
|
+
finally {
|
|
109
|
+
// Cleanup
|
|
110
|
+
if (await (0, fs_helpers_1.pathExists)(tempDir)) {
|
|
111
|
+
await (0, fs_helpers_1.remove)(tempDir);
|
|
215
112
|
}
|
|
216
113
|
}
|
|
217
114
|
}
|
|
218
|
-
exports.AabParser = AabParser;
|
|
219
|
-
const escapeRegExp = (value) => value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private _parseManifest;
|
|
9
|
-
/**
|
|
10
|
-
* Parse resourceMap
|
|
11
|
-
* @param {Buffer} buffer // resourceMap file's buffer
|
|
12
|
-
*/
|
|
13
|
-
private _parseResourceMap;
|
|
1
|
+
export interface ApkManifestInfo {
|
|
2
|
+
versionName?: unknown;
|
|
3
|
+
/** `<application>`'s `<meta-data>` entries, resource references resolved */
|
|
4
|
+
metaData: Array<{
|
|
5
|
+
name?: unknown;
|
|
6
|
+
value?: unknown;
|
|
7
|
+
}>;
|
|
14
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The fields of a binary AndroidManifest.xml the CLI reads, with
|
|
11
|
+
* `@<resource>` references resolved through resources.arsc when given.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseApkManifest(manifest: Buffer, resources?: Buffer): ApkManifestInfo;
|