react-native-update-cli 2.24.2 → 2.26.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 (98) hide show
  1. package/README.md +12 -5
  2. package/README.zh-CN.md +12 -5
  3. package/cli.json +7 -1
  4. package/lib/api.d.ts +2 -0
  5. package/lib/api.js +63 -18
  6. package/lib/app.js +25 -3
  7. package/lib/bin.js +39 -45
  8. package/lib/bundle-runner.d.ts +45 -1
  9. package/lib/bundle-runner.js +303 -34
  10. package/lib/bundle.d.ts +1 -1
  11. package/lib/bundle.js +23 -7
  12. package/lib/commands.d.ts +6 -0
  13. package/lib/commands.js +65 -0
  14. package/lib/locales/en.d.ts +7 -14
  15. package/lib/locales/en.js +10 -17
  16. package/lib/locales/zh.d.ts +7 -13
  17. package/lib/locales/zh.js +10 -16
  18. package/lib/package.js +4 -0
  19. package/lib/provider.d.ts +1 -1
  20. package/lib/provider.js +3 -1
  21. package/lib/symbolicate.js +7 -2
  22. package/lib/types.d.ts +1 -0
  23. package/lib/user.js +6 -0
  24. package/lib/utils/add-gitignore.js +7 -1
  25. package/lib/utils/dep-versions.d.ts +7 -0
  26. package/lib/utils/dep-versions.js +78 -26
  27. package/lib/utils/git.js +9 -6
  28. package/lib/utils/hbcTransform.d.ts +15 -0
  29. package/lib/utils/hbcTransform.js +22 -0
  30. package/lib/utils/hermes-base.d.ts +61 -6
  31. package/lib/utils/hermes-base.js +328 -46
  32. package/lib/utils/hermes-literals.d.ts +51 -0
  33. package/lib/utils/hermes-literals.js +210 -0
  34. package/lib/utils/i18n.d.ts +5 -0
  35. package/lib/utils/i18n.js +14 -1
  36. package/lib/utils/index.d.ts +2 -1
  37. package/lib/utils/index.js +9 -4
  38. package/lib/utils/latest-version/index.js +8 -0
  39. package/lib/utils/runtime.d.ts +21 -0
  40. package/lib/utils/runtime.js +138 -5
  41. package/lib/utils/zip-range.js +3 -2
  42. package/lib/versions.js +14 -4
  43. package/package.json +6 -3
  44. package/lib/index.d.ts +0 -1
  45. package/lib/index.js +0 -17
  46. package/src/api.ts +0 -470
  47. package/src/app.ts +0 -241
  48. package/src/auto-update.ts +0 -647
  49. package/src/bin-cresc.ts +0 -8
  50. package/src/bin.ts +0 -115
  51. package/src/bundle-pack.ts +0 -61
  52. package/src/bundle-runner.ts +0 -1430
  53. package/src/bundle.ts +0 -371
  54. package/src/cache.ts +0 -20
  55. package/src/diff.ts +0 -1010
  56. package/src/exports.ts +0 -17
  57. package/src/index.ts +0 -1
  58. package/src/install.ts +0 -50
  59. package/src/locales/en.ts +0 -257
  60. package/src/locales/zh.ts +0 -234
  61. package/src/native-package.ts +0 -338
  62. package/src/package.ts +0 -482
  63. package/src/provider.ts +0 -294
  64. package/src/symbolicate.ts +0 -164
  65. package/src/types.ts +0 -150
  66. package/src/user.ts +0 -39
  67. package/src/utils/add-gitignore.ts +0 -35
  68. package/src/utils/app-info-parser/aab.ts +0 -241
  69. package/src/utils/app-info-parser/apk.ts +0 -92
  70. package/src/utils/app-info-parser/app.ts +0 -7
  71. package/src/utils/app-info-parser/index.ts +0 -54
  72. package/src/utils/app-info-parser/ipa.ts +0 -109
  73. package/src/utils/app-info-parser/resource-finder.ts +0 -508
  74. package/src/utils/app-info-parser/utils.ts +0 -161
  75. package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
  76. package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
  77. package/src/utils/app-info-parser/zip.ts +0 -108
  78. package/src/utils/check-lockfile.ts +0 -93
  79. package/src/utils/check-plugin.ts +0 -38
  80. package/src/utils/command-result.ts +0 -24
  81. package/src/utils/constants.ts +0 -25
  82. package/src/utils/dep-versions.ts +0 -83
  83. package/src/utils/git.ts +0 -71
  84. package/src/utils/hbcTransform.ts +0 -649
  85. package/src/utils/hermes-base.ts +0 -1137
  86. package/src/utils/http-helper.ts +0 -152
  87. package/src/utils/i18n.ts +0 -39
  88. package/src/utils/index.ts +0 -698
  89. package/src/utils/latest-version/index.ts +0 -573
  90. package/src/utils/options.ts +0 -78
  91. package/src/utils/plugin-config.ts +0 -32
  92. package/src/utils/runtime.ts +0 -187
  93. package/src/utils/slim-sourcemap.ts +0 -105
  94. package/src/utils/zip-entries.ts +0 -209
  95. package/src/utils/zip-options.ts +0 -178
  96. package/src/utils/zip-range.ts +0 -727
  97. package/src/utils/zip-raw-writer.ts +0 -247
  98. package/src/versions.ts +0 -892
@@ -1,241 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import * as fs from 'fs-extra';
3
- import os from 'os';
4
- import path from 'path';
5
- import { open as openZipFile } from 'yauzl';
6
- import { t } from '../i18n';
7
- import { ResourceFinder } from './resource-finder';
8
- import { mapInfoResource } from './utils';
9
- import { ManifestParser } from './xml-parser/manifest';
10
- import { Zip } from './zip';
11
-
12
- export class AabParser extends Zip {
13
- async extractApk(
14
- outputPath: string,
15
- {
16
- includeAllSplits,
17
- splits,
18
- }: { includeAllSplits?: boolean; splits?: string[] | null },
19
- ) {
20
- const normalizedSplits = Array.isArray(splits)
21
- ? splits.map((item) => item.trim()).filter(Boolean)
22
- : [];
23
- const modules = includeAllSplits
24
- ? null
25
- : Array.from(new Set(['base', ...normalizedSplits]));
26
- const modulesArgs = modules ? [`--modules=${modules.join(',')}`] : [];
27
-
28
- const runCommand = (
29
- command: string,
30
- args: string[],
31
- options: { stdio?: 'inherit'; env?: NodeJS.ProcessEnv } = {},
32
- ) =>
33
- new Promise<void>((resolve, reject) => {
34
- const inheritStdio = options.stdio === 'inherit';
35
- const child = spawn(command, args, {
36
- stdio: inheritStdio ? 'inherit' : ['ignore', 'pipe', 'pipe'],
37
- env: options.env,
38
- });
39
- let stderr = '';
40
- if (!inheritStdio) {
41
- child.stderr?.on('data', (chunk) => {
42
- stderr += chunk.toString();
43
- });
44
- }
45
- child.on('error', reject);
46
- child.on('close', (code) => {
47
- if (code === 0) {
48
- resolve();
49
- return;
50
- }
51
- reject(
52
- new Error(
53
- stderr.trim() || `Command failed: ${command} (code ${code})`,
54
- ),
55
- );
56
- });
57
- });
58
-
59
- // Create a temp file for the .apks output
60
- const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'bundletool-'));
61
- const tempApksPath = path.join(tempDir, 'output.apks');
62
-
63
- const needsNpxDownload = async () => {
64
- try {
65
- await runCommand('npx', [
66
- '--no-install',
67
- 'node-bundletool',
68
- '--version',
69
- ]);
70
- return false;
71
- } catch {
72
- return true;
73
- }
74
- };
75
-
76
- try {
77
- // 1. Build APKS (universal mode)
78
- // We assume bundletool is in the path.
79
- // User might need keystore to sign it properly but for simple extraction we stick to default debug key if possible or unsigned?
80
- // actually bundletool build-apks signs with debug key by default if no keystore provided.
81
-
82
- try {
83
- await runCommand('bundletool', [
84
- 'build-apks',
85
- '--mode=universal',
86
- `--bundle=${this.file}`,
87
- `--output=${tempApksPath}`,
88
- '--overwrite',
89
- ...modulesArgs,
90
- ]);
91
- } catch (e) {
92
- // Only fall back when bundletool itself is missing from PATH (spawn
93
- // ENOENT). Any other failure (corrupt AAB, Java issues, bad args,
94
- // non-zero exit) must surface as-is instead of being masked by an
95
- // online npx install.
96
- if ((e as NodeJS.ErrnoException)?.code !== 'ENOENT') {
97
- throw e;
98
- }
99
- // Fallback to npx node-bundletool if bundletool is not in PATH
100
- // We use -y to avoid interactive prompt for installation
101
- if (await needsNpxDownload()) {
102
- console.log(t('aabBundletoolDownloadHint'));
103
- }
104
- await runCommand(
105
- 'npx',
106
- [
107
- '-y',
108
- 'node-bundletool',
109
- 'build-apks',
110
- '--mode=universal',
111
- `--bundle=${this.file}`,
112
- `--output=${tempApksPath}`,
113
- '--overwrite',
114
- ...modulesArgs,
115
- ],
116
- {
117
- stdio: 'inherit',
118
- env: {
119
- ...process.env,
120
- npm_config_progress: 'true',
121
- },
122
- },
123
- );
124
- }
125
-
126
- // 2. Extract universal.apk from the .apks (zip) file
127
- await new Promise<void>((resolve, reject) => {
128
- openZipFile(tempApksPath, { lazyEntries: true }, (err, zipfile) => {
129
- if (err || !zipfile) {
130
- reject(err || new Error(t('aabOpenApksFailed')));
131
- return;
132
- }
133
-
134
- let found = false;
135
- zipfile.readEntry();
136
- zipfile.on('entry', (entry) => {
137
- if (entry.fileName === 'universal.apk') {
138
- found = true;
139
- zipfile.openReadStream(entry, (err, readStream) => {
140
- if (err || !readStream) {
141
- reject(err || new Error(t('aabReadUniversalApkFailed')));
142
- return;
143
- }
144
- const writeStream = fs.createWriteStream(outputPath);
145
- readStream.pipe(writeStream);
146
- writeStream.on('close', () => {
147
- zipfile.close();
148
- resolve();
149
- });
150
- readStream.on('error', reject);
151
- writeStream.on('error', reject);
152
- });
153
- } else {
154
- zipfile.readEntry();
155
- }
156
- });
157
-
158
- zipfile.on('end', () => {
159
- if (!found) reject(new Error(t('aabUniversalApkNotFound')));
160
- });
161
- zipfile.on('error', reject);
162
- });
163
- });
164
- } finally {
165
- // Cleanup
166
- if (await fs.pathExists(tempDir)) {
167
- await fs.remove(tempDir);
168
- }
169
- }
170
- }
171
-
172
- /**
173
- * 解析 AAB 文件信息(类似 APK parser 的 parse 方法)
174
- * 注意:AAB 中的 AndroidManifest.xml 在 base/manifest/AndroidManifest.xml
175
- */
176
- async parse() {
177
- const manifestPath = 'base/manifest/AndroidManifest.xml';
178
- const ResourceName = /^base\/resources\.arsc$/;
179
-
180
- try {
181
- const manifestBuffer = await this.getEntry(
182
- new RegExp(`^${escapeRegExp(manifestPath)}$`),
183
- );
184
-
185
- if (!manifestBuffer) {
186
- throw new Error(t('aabManifestNotFound'));
187
- }
188
-
189
- let apkInfo = this._parseManifest(manifestBuffer as Buffer);
190
-
191
- try {
192
- const resourceBuffer = await this.getEntry(ResourceName);
193
- if (resourceBuffer) {
194
- const resourceMap = this._parseResourceMap(resourceBuffer as Buffer);
195
- apkInfo = mapInfoResource(apkInfo, resourceMap);
196
- }
197
- } catch (e: any) {
198
- console.warn(t('aabParseResourcesWarning', { error: e?.message ?? e }));
199
- }
200
-
201
- return apkInfo;
202
- } catch (error: any) {
203
- throw new Error(t('aabParseFailed', { error: error.message ?? error }));
204
- }
205
- }
206
- /**
207
- * Parse manifest
208
- * @param {Buffer} buffer // manifest file's buffer
209
- */
210
- private _parseManifest(buffer: Buffer) {
211
- try {
212
- const parser = new ManifestParser(buffer, {
213
- ignore: [
214
- 'application.activity',
215
- 'application.service',
216
- 'application.receiver',
217
- 'application.provider',
218
- 'permission-group',
219
- ],
220
- });
221
- return parser.parse();
222
- } catch (e: any) {
223
- throw new Error(t('aabParseManifestError', { error: e?.message ?? e }));
224
- }
225
- }
226
-
227
- /**
228
- * Parse resourceMap
229
- * @param {Buffer} buffer // resourceMap file's buffer
230
- */
231
- private _parseResourceMap(buffer: Buffer) {
232
- try {
233
- return new ResourceFinder().processResourceTable(buffer);
234
- } catch (e: any) {
235
- throw new Error(t('aabParseResourcesError', { error: e?.message ?? e }));
236
- }
237
- }
238
- }
239
-
240
- const escapeRegExp = (value: string) =>
241
- value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
@@ -1,92 +0,0 @@
1
- import { ResourceFinder } from './resource-finder';
2
- import { findApkIconPath, getBase64FromBuffer, mapInfoResource } from './utils';
3
- import { ManifestParser } from './xml-parser/manifest';
4
- import { Zip } from './zip';
5
-
6
- const ManifestName = /^androidmanifest\.xml$/;
7
- const ResourceName = /^resources\.arsc$/;
8
-
9
- export class ApkParser extends Zip {
10
- parse(): Promise<any> {
11
- const manifestKey = ManifestName.toString();
12
- const resourceKey = ResourceName.toString();
13
-
14
- return new Promise((resolve, reject) => {
15
- this.getEntries([ManifestName, ResourceName])
16
- .then((buffers: Record<string, Buffer | Blob | undefined>) => {
17
- const manifestBuffer = buffers[manifestKey];
18
- if (!manifestBuffer) {
19
- throw new Error("AndroidManifest.xml can't be found.");
20
- }
21
- let apkInfo: any;
22
- let resourceMap: any;
23
-
24
- apkInfo = this._parseManifest(manifestBuffer as Buffer);
25
-
26
- if (!buffers[resourceKey]) {
27
- resolve(apkInfo);
28
- } else {
29
- resourceMap = this._parseResourceMap(
30
- buffers[resourceKey] as Buffer,
31
- );
32
- apkInfo = mapInfoResource(apkInfo, resourceMap);
33
-
34
- const iconPath = findApkIconPath(apkInfo);
35
- if (iconPath) {
36
- this.getEntry(iconPath)
37
- .then((iconBuffer: Buffer | Blob | undefined) => {
38
- apkInfo.icon = Buffer.isBuffer(iconBuffer)
39
- ? getBase64FromBuffer(iconBuffer)
40
- : null;
41
- resolve(apkInfo);
42
- })
43
- .catch((e: any) => {
44
- apkInfo.icon = null;
45
- resolve(apkInfo);
46
- console.warn('[Warning] failed to parse icon: ', e);
47
- });
48
- } else {
49
- apkInfo.icon = null;
50
- resolve(apkInfo);
51
- }
52
- }
53
- })
54
- .catch((e: any) => {
55
- reject(e);
56
- });
57
- });
58
- }
59
-
60
- /**
61
- * Parse manifest
62
- * @param {Buffer} buffer // manifest file's buffer
63
- */
64
- private _parseManifest(buffer: Buffer) {
65
- try {
66
- const parser = new ManifestParser(buffer, {
67
- ignore: [
68
- 'application.activity',
69
- 'application.service',
70
- 'application.receiver',
71
- 'application.provider',
72
- 'permission-group',
73
- ],
74
- });
75
- return parser.parse();
76
- } catch (e: any) {
77
- throw new Error(`Parse AndroidManifest.xml error: ${e.message || e}`);
78
- }
79
- }
80
-
81
- /**
82
- * Parse resourceMap
83
- * @param {Buffer} buffer // resourceMap file's buffer
84
- */
85
- private _parseResourceMap(buffer: Buffer) {
86
- try {
87
- return new ResourceFinder().processResourceTable(buffer);
88
- } catch (e: any) {
89
- throw new Error(`Parser resources.arsc error: ${e}`);
90
- }
91
- }
92
- }
@@ -1,7 +0,0 @@
1
- import { Zip } from './zip';
2
-
3
- export class AppParser extends Zip {
4
- async parse(): Promise<Record<string, never>> {
5
- return {};
6
- }
7
- }
@@ -1,54 +0,0 @@
1
- import { AabParser } from './aab';
2
- import { ApkParser } from './apk';
3
- import { AppParser } from './app';
4
- import { IpaParser } from './ipa';
5
-
6
- const supportFileTypes = ['ipa', 'apk', 'app', 'aab'] as const;
7
- type SupportedFileType = (typeof supportFileTypes)[number];
8
- type AppInfoInnerParser = AabParser | ApkParser | AppParser | IpaParser;
9
-
10
- class AppInfoParser {
11
- file: string | File;
12
- parser: AppInfoInnerParser;
13
- /**
14
- * parser for parsing .ipa or .apk file
15
- * @param {String | File} file // file's path in Node, instance of File in Browser
16
- */
17
- constructor(file: string | File) {
18
- if (!file) {
19
- throw new Error(
20
- "Param miss: file(file's path in Node, instance of File in browser).",
21
- );
22
- }
23
- const splits = (typeof file === 'string' ? file : file.name).split('.');
24
- const fileType = splits[splits.length - 1].toLowerCase();
25
- if (!supportFileTypes.includes(fileType as SupportedFileType)) {
26
- throw new Error(
27
- 'Unsupported file type, only support .ipa, .apk, .app, or .aab file.',
28
- );
29
- }
30
- this.file = file;
31
-
32
- switch (fileType as SupportedFileType) {
33
- case 'ipa':
34
- this.parser = new IpaParser(this.file);
35
- break;
36
- case 'apk':
37
- this.parser = new ApkParser(this.file);
38
- break;
39
- case 'app':
40
- this.parser = new AppParser(this.file);
41
- break;
42
- case 'aab':
43
- this.parser = new AabParser(this.file);
44
- break;
45
- default:
46
- throw new Error('Unsupported parser file type.');
47
- }
48
- }
49
- parse<T = unknown>(): Promise<T> {
50
- return this.parser.parse() as Promise<T>;
51
- }
52
- }
53
-
54
- export default AppInfoParser;
@@ -1,109 +0,0 @@
1
- const parseBplist = require('bplist-parser').parseBuffer;
2
- const cgbiToPng = require('cgbi-to-png');
3
-
4
- import { findIpaIconPath, getBase64FromBuffer, isBrowser } from './utils';
5
- import { Zip } from './zip';
6
-
7
- const PlistName = /payload\/[^/]+?.app\/info.plist$/i;
8
- const ProvisionName = /payload\/.+?\.app\/embedded.mobileprovision/;
9
-
10
- type ParsePlist = (content: string) => Record<string, any>;
11
-
12
- let parsePlistPromise: Promise<ParsePlist> | undefined;
13
-
14
- function loadParsePlist(): Promise<ParsePlist> {
15
- if (!parsePlistPromise) {
16
- parsePlistPromise = Promise.resolve().then(async () => {
17
- try {
18
- return require('plist').parse as ParsePlist;
19
- } catch (requireError) {
20
- const importModule = new Function(
21
- 'specifier',
22
- 'return import(specifier)',
23
- ) as (specifier: string) => Promise<{
24
- parse?: ParsePlist;
25
- default?: { parse?: ParsePlist };
26
- }>;
27
- const plistModule = await importModule('plist');
28
- const parsePlist = plistModule.parse ?? plistModule.default?.parse;
29
- if (!parsePlist) {
30
- throw requireError;
31
- }
32
- return parsePlist;
33
- }
34
- });
35
- }
36
- return parsePlistPromise;
37
- }
38
-
39
- export class IpaParser extends Zip {
40
- async parse(): Promise<any> {
41
- const parsePlist = await loadParsePlist();
42
- const buffers = await this.getEntries([PlistName, ProvisionName]);
43
- if (!buffers[PlistName as any]) {
44
- throw new Error("Info.plist can't be found.");
45
- }
46
- const plistInfo = this._parsePlist(
47
- buffers[PlistName as any] as Buffer,
48
- parsePlist,
49
- );
50
- const provisionInfo = this._parseProvision(
51
- buffers[ProvisionName as any] as Buffer | undefined,
52
- parsePlist,
53
- );
54
- plistInfo.mobileProvision = provisionInfo;
55
-
56
- const iconRegex = new RegExp(findIpaIconPath(plistInfo).toLowerCase());
57
- const iconBuffer = await this.getEntry(iconRegex);
58
- try {
59
- plistInfo.icon = iconBuffer
60
- ? getBase64FromBuffer(cgbiToPng.revert(iconBuffer))
61
- : null;
62
- } catch (err) {
63
- if (isBrowser()) {
64
- plistInfo.icon = iconBuffer
65
- ? getBase64FromBuffer(
66
- window.btoa(String.fromCharCode(...(iconBuffer as Buffer))),
67
- )
68
- : null;
69
- } else {
70
- plistInfo.icon = null;
71
- console.warn('[Warning] failed to parse icon: ', err);
72
- }
73
- }
74
- return plistInfo;
75
- }
76
- /**
77
- * Parse plist
78
- * @param {Buffer} buffer // plist file's buffer
79
- */
80
- private _parsePlist(buffer: Buffer, parsePlist: ParsePlist) {
81
- let result: any;
82
- const bufferType = buffer[0];
83
- if (bufferType === 60 || bufferType === 239) {
84
- result = parsePlist(buffer.toString());
85
- } else if (bufferType === 98) {
86
- result = parseBplist(buffer)[0];
87
- } else {
88
- throw new Error('Unknown plist buffer type.');
89
- }
90
- return result;
91
- }
92
- /**
93
- * parse provision
94
- * @param {Buffer} buffer // provision file's buffer
95
- */
96
- private _parseProvision(buffer: Buffer | undefined, parsePlist: ParsePlist) {
97
- let info: Record<string, any> = {};
98
- if (buffer) {
99
- let content = buffer.toString('utf-8');
100
- const firstIndex = content.indexOf('<?xml');
101
- const endIndex = content.indexOf('</plist>');
102
- content = content.slice(firstIndex, endIndex + 8);
103
- if (content) {
104
- info = parsePlist(content);
105
- }
106
- }
107
- return info;
108
- }
109
- }