react-native-update-cli 2.15.2 → 2.15.4

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 (59) hide show
  1. package/cli.json +0 -6
  2. package/lib/api.js +25 -4
  3. package/lib/app.js +1 -0
  4. package/lib/bin-cresc.d.ts +1 -0
  5. package/lib/bin-cresc.js +7 -0
  6. package/lib/bin.js +5 -3
  7. package/lib/bundle-pack.d.ts +1 -1
  8. package/lib/bundle-pack.js +8 -7
  9. package/lib/bundle-runner.d.ts +3 -3
  10. package/lib/bundle-runner.js +68 -49
  11. package/lib/bundle.d.ts +26 -0
  12. package/lib/bundle.js +18 -6
  13. package/lib/diff.js +55 -70
  14. package/lib/install.js +30 -3
  15. package/lib/locales/en.d.ts +13 -0
  16. package/lib/locales/en.js +14 -1
  17. package/lib/locales/zh.d.ts +13 -0
  18. package/lib/locales/zh.js +14 -1
  19. package/lib/package.js +8 -2
  20. package/lib/provider.js +9 -3
  21. package/lib/types.d.ts +2 -2
  22. package/lib/utils/app-info-parser/aab.js +4 -4
  23. package/lib/utils/app-info-parser/xml-parser/binary.js +4 -3
  24. package/lib/utils/app-info-parser/xml-parser/manifest.js +3 -1
  25. package/lib/utils/app-info-parser/zip.d.ts +6 -0
  26. package/lib/utils/app-info-parser/zip.js +20 -5
  27. package/lib/utils/check-lockfile.js +5 -1
  28. package/lib/utils/constants.d.ts +1 -1
  29. package/lib/utils/constants.js +2 -1
  30. package/lib/utils/http-helper.js +20 -23
  31. package/lib/utils/index.js +48 -20
  32. package/lib/utils/zip-entries.js +4 -0
  33. package/lib/versions.d.ts +2 -0
  34. package/lib/versions.js +19 -8
  35. package/package.json +5 -5
  36. package/src/api.ts +30 -5
  37. package/src/app.ts +1 -0
  38. package/src/bin-cresc.ts +8 -0
  39. package/src/bin.ts +3 -3
  40. package/src/bundle-pack.ts +12 -7
  41. package/src/bundle-runner.ts +82 -56
  42. package/src/bundle.ts +13 -8
  43. package/src/diff.ts +87 -109
  44. package/src/install.ts +32 -3
  45. package/src/locales/en.ts +16 -0
  46. package/src/locales/zh.ts +15 -0
  47. package/src/package.ts +4 -4
  48. package/src/provider.ts +7 -3
  49. package/src/types.ts +3 -2
  50. package/src/utils/app-info-parser/aab.ts +4 -4
  51. package/src/utils/app-info-parser/xml-parser/binary.ts +4 -5
  52. package/src/utils/app-info-parser/xml-parser/manifest.ts +6 -3
  53. package/src/utils/app-info-parser/zip.ts +22 -5
  54. package/src/utils/check-lockfile.ts +5 -1
  55. package/src/utils/constants.ts +5 -1
  56. package/src/utils/http-helper.ts +16 -23
  57. package/src/utils/index.ts +51 -36
  58. package/src/utils/zip-entries.ts +4 -0
  59. package/src/versions.ts +15 -11
package/src/diff.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs-extra';
2
2
  import { npm, yarn } from 'global-dirs';
3
3
  import path from 'path';
4
+ import type { Entry, ZipFile as YauzlZipFile } from 'yauzl';
4
5
  import { ZipFile as YazlZipFile } from 'yazl';
5
6
  import type { CommandContext } from './types';
6
7
  import { translateOptions } from './utils';
@@ -41,7 +42,10 @@ type DiffCommandConfig = {
41
42
  export { enumZipEntries, readEntry };
42
43
 
43
44
  const loadModule = <T>(pkgName: string): T | undefined => {
44
- const resolvePaths = ['.', npm.packages, yarn.packages];
45
+ const nodePathDirs = (process.env.NODE_PATH || '')
46
+ .split(path.delimiter)
47
+ .filter(Boolean);
48
+ const resolvePaths = ['.', ...nodePathDirs, npm.packages, yarn.packages];
45
49
 
46
50
  try {
47
51
  const resolved = require.resolve(pkgName, { paths: resolvePaths });
@@ -58,14 +62,85 @@ function basename(fn: string): string | undefined {
58
62
  return m?.[1];
59
63
  }
60
64
 
65
+ function createOutputZip(output: string) {
66
+ fs.ensureDirSync(path.dirname(output));
67
+ const zipfile = new YazlZipFile();
68
+ const writePromise = new Promise<void>((resolve, reject) => {
69
+ zipfile.outputStream.on('error', reject);
70
+ zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
71
+ resolve(void 0);
72
+ });
73
+ });
74
+ return { zipfile, writePromise };
75
+ }
76
+
77
+ async function addBundlePatch(
78
+ zipfile: YazlZipFile,
79
+ entry: Entry,
80
+ nextZipfile: YauzlZipFile,
81
+ diffFn: Diff,
82
+ originSource: Buffer | undefined,
83
+ ) {
84
+ const newSource = await readEntry(entry, nextZipfile);
85
+ zipfile.addBuffer(
86
+ diffFn(originSource, newSource),
87
+ `${entry.fileName}.patch`,
88
+ zipOptionsForPatchEntry(),
89
+ );
90
+ }
91
+
92
+ async function addFileFromZipEntry(
93
+ zipfile: YazlZipFile,
94
+ entry: Entry,
95
+ nextZipfile: YauzlZipFile,
96
+ ) {
97
+ const entryPrefix = await readEntryPrefix(
98
+ entry,
99
+ nextZipfile,
100
+ ZIP_ENTRY_SNIFF_BYTES,
101
+ );
102
+ await new Promise<void>((resolve, reject) => {
103
+ nextZipfile.openReadStream(entry, (err, readStream) => {
104
+ if (err) {
105
+ return reject(err);
106
+ }
107
+ if (!readStream) {
108
+ return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
109
+ }
110
+ zipfile.addReadStream(
111
+ readStream,
112
+ entry.fileName,
113
+ zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
114
+ );
115
+ readStream.on('error', reject);
116
+ readStream.on('end', () => {
117
+ resolve(void 0);
118
+ });
119
+ });
120
+ });
121
+ }
122
+
123
+ function finishDiffZip(
124
+ zipfile: YazlZipFile,
125
+ writePromise: Promise<void>,
126
+ manifest: Record<string, unknown>,
127
+ ) {
128
+ const diffManifest = Buffer.from(JSON.stringify(manifest));
129
+ zipfile.addBuffer(
130
+ diffManifest,
131
+ '__diff.json',
132
+ zipOptionsForManifestEntry(diffManifest.length),
133
+ );
134
+ zipfile.end();
135
+ return writePromise;
136
+ }
137
+
61
138
  async function diffFromPPK(
62
139
  origin: string,
63
140
  next: string,
64
141
  output: string,
65
142
  diffFn: Diff,
66
143
  ) {
67
- fs.ensureDirSync(path.dirname(output));
68
-
69
144
  const originEntries: EntryMap = {};
70
145
  const originMap: CrcMap = {};
71
146
 
@@ -90,14 +165,7 @@ async function diffFromPPK(
90
165
 
91
166
  const copies: CopyMap = {};
92
167
 
93
- const zipfile = new YazlZipFile();
94
-
95
- const writePromise = new Promise<void>((resolve, reject) => {
96
- zipfile.outputStream.on('error', reject);
97
- zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
98
- resolve(void 0);
99
- });
100
- });
168
+ const { zipfile, writePromise } = createOutputZip(output);
101
169
 
102
170
  const addedEntry: Record<string, true> = {};
103
171
 
@@ -125,15 +193,7 @@ async function diffFromPPK(
125
193
  addEntry(entry.fileName);
126
194
  }
127
195
  } else if (isPPKBundleFileName(entry.fileName)) {
128
- //console.log('Found bundle');
129
- const newSource = await readEntry(entry, nextZipfile);
130
- //console.log('Begin diff');
131
- zipfile.addBuffer(
132
- diffFn(originSource, newSource),
133
- `${entry.fileName}.patch`,
134
- zipOptionsForPatchEntry(),
135
- );
136
- //console.log('End diff');
196
+ await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource);
137
197
  } else {
138
198
  // If same file.
139
199
  const originEntry = originEntries[entry.fileName];
@@ -159,32 +219,7 @@ async function diffFromPPK(
159
219
  addEntry(basePath);
160
220
  }
161
221
 
162
- const entryPrefix = await readEntryPrefix(
163
- entry,
164
- nextZipfile,
165
- ZIP_ENTRY_SNIFF_BYTES,
166
- );
167
- await new Promise<void>((resolve, reject) => {
168
- nextZipfile.openReadStream(entry, (err, readStream) => {
169
- if (err) {
170
- return reject(err);
171
- }
172
- if (!readStream) {
173
- return reject(
174
- new Error(`Unable to read zip entry: ${entry.fileName}`),
175
- );
176
- }
177
- zipfile.addReadStream(
178
- readStream,
179
- entry.fileName,
180
- zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
181
- );
182
- readStream.on('end', () => {
183
- //console.log('add finished');
184
- resolve(void 0);
185
- });
186
- });
187
- });
222
+ await addFileFromZipEntry(zipfile, entry, nextZipfile);
188
223
  }
189
224
  });
190
225
 
@@ -197,15 +232,7 @@ async function diffFromPPK(
197
232
  }
198
233
  }
199
234
 
200
- //console.log({copies, deletes});
201
- const diffManifest = Buffer.from(JSON.stringify({ copies, deletes }));
202
- zipfile.addBuffer(
203
- diffManifest,
204
- '__diff.json',
205
- zipOptionsForManifestEntry(diffManifest.length),
206
- );
207
- zipfile.end();
208
- await writePromise;
235
+ await finishDiffZip(zipfile, writePromise, { copies, deletes });
209
236
  }
210
237
 
211
238
  async function diffFromPackage(
@@ -216,8 +243,6 @@ async function diffFromPackage(
216
243
  originBundleName: string,
217
244
  transformPackagePath: (v: string) => string | undefined = (v: string) => v,
218
245
  ) {
219
- fs.ensureDirSync(path.dirname(output));
220
-
221
246
  const originEntries: Record<string, number> = {};
222
247
  const originMap: CrcMap = {};
223
248
 
@@ -255,29 +280,14 @@ async function diffFromPackage(
255
280
 
256
281
  const copies: CopyMap = {};
257
282
 
258
- const zipfile = new YazlZipFile();
259
-
260
- const writePromise = new Promise<void>((resolve, reject) => {
261
- zipfile.outputStream.on('error', reject);
262
- zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
263
- resolve(void 0);
264
- });
265
- });
283
+ const { zipfile, writePromise } = createOutputZip(output);
266
284
 
267
285
  await enumZipEntries(next, async (entry, nextZipfile) => {
268
286
  if (/\/$/.test(entry.fileName)) {
269
287
  // Directory
270
288
  zipfile.addEmptyDirectory(entry.fileName);
271
289
  } else if (isPPKBundleFileName(entry.fileName)) {
272
- //console.log('Found bundle');
273
- const newSource = await readEntry(entry, nextZipfile);
274
- //console.log('Begin diff');
275
- zipfile.addBuffer(
276
- diffFn(originSource, newSource),
277
- `${entry.fileName}.patch`,
278
- zipOptionsForPatchEntry(),
279
- );
280
- //console.log('End diff');
290
+ await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource);
281
291
  } else {
282
292
  // If same file.
283
293
  if (originEntries[entry.fileName] === entry.crc32) {
@@ -295,43 +305,11 @@ async function diffFromPackage(
295
305
  return;
296
306
  }
297
307
 
298
- const entryPrefix = await readEntryPrefix(
299
- entry,
300
- nextZipfile,
301
- ZIP_ENTRY_SNIFF_BYTES,
302
- );
303
- await new Promise<void>((resolve, reject) => {
304
- nextZipfile.openReadStream(entry, (err, readStream) => {
305
- if (err) {
306
- return reject(err);
307
- }
308
- if (!readStream) {
309
- return reject(
310
- new Error(`Unable to read zip entry: ${entry.fileName}`),
311
- );
312
- }
313
- zipfile.addReadStream(
314
- readStream,
315
- entry.fileName,
316
- zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
317
- );
318
- readStream.on('end', () => {
319
- //console.log('add finished');
320
- resolve(void 0);
321
- });
322
- });
323
- });
308
+ await addFileFromZipEntry(zipfile, entry, nextZipfile);
324
309
  }
325
310
  });
326
311
 
327
- const diffManifest = Buffer.from(JSON.stringify({ copies, copiesCrc }));
328
- zipfile.addBuffer(
329
- diffManifest,
330
- '__diff.json',
331
- zipOptionsForManifestEntry(diffManifest.length),
332
- );
333
- zipfile.end();
334
- await writePromise;
312
+ await finishDiffZip(zipfile, writePromise, { copies, copiesCrc });
335
313
  }
336
314
 
337
315
  type DiffCommandOptions = {
@@ -369,7 +347,7 @@ function diffArgsCheck(
369
347
  tempDir,
370
348
  } as DiffCommandOptions & { tempDir: string });
371
349
  if (typeof output !== 'string') {
372
- throw new Error('Output path is required.');
350
+ throw new Error(t('outputPathRequired'));
373
351
  }
374
352
 
375
353
  return {
package/src/install.ts CHANGED
@@ -1,21 +1,50 @@
1
1
  import { spawnSync } from 'child_process';
2
2
  import path from 'path';
3
3
  import type { CommandContext } from './types';
4
+ import { scriptName } from './utils/constants';
5
+ import { t } from './utils/i18n';
4
6
  import { getInstallCommand } from './utils/runtime';
5
7
 
8
+ // package names / version specs only — rejects shell metacharacters since
9
+ // Windows needs shell: true to run package manager .cmd shims
10
+ const SAFE_PACKAGE_ARG = /^[@a-z0-9^~._/-]+$/i;
11
+
6
12
  export const installCommands = {
7
13
  install: async ({ args }: CommandContext) => {
8
14
  if (args.length === 0) {
9
- return;
15
+ throw new Error(t('installPackageRequired', { scriptName }));
16
+ }
17
+ for (const arg of args) {
18
+ if (!SAFE_PACKAGE_ARG.test(arg)) {
19
+ throw new Error(t('installPackageRequired', { scriptName }));
20
+ }
10
21
  }
11
22
 
12
23
  const cliDir = path.resolve(__dirname, '..');
13
24
  const installCommand = getInstallCommand(args, cliDir);
14
25
 
15
- spawnSync(installCommand.command, installCommand.args, {
26
+ const result = spawnSync(installCommand.command, installCommand.args, {
16
27
  cwd: cliDir,
17
28
  stdio: 'inherit',
18
- shell: true,
29
+ // package manager executables are .cmd shims on Windows
30
+ shell: process.platform === 'win32',
19
31
  });
32
+
33
+ if (result.error) {
34
+ throw new Error(
35
+ t('installFailed', {
36
+ packages: args.join(' '),
37
+ error: result.error.message,
38
+ }),
39
+ );
40
+ }
41
+ if (result.status !== 0) {
42
+ throw new Error(
43
+ t('installFailed', {
44
+ packages: args.join(' '),
45
+ error: `${installCommand.command} exited with code ${result.status}`,
46
+ }),
47
+ );
48
+ }
20
49
  },
21
50
  };
package/src/locales/en.ts CHANGED
@@ -132,6 +132,8 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
132
132
  'Set {{rollout}}% rollout for OTA update {{version}} on native version(s) {{versions}}',
133
133
  rolloutRangeError: 'rollout must be an integer between 1-100',
134
134
  runningHermesc: 'Running hermesc: {{- command}} {{- args}}',
135
+ sentryReactNativeNotFound:
136
+ 'Cannot find @sentry/react-native, please make sure it is properly installed',
135
137
  sentryCliNotFound:
136
138
  'Cannot find Sentry CLI tool, please make sure @sentry/cli is properly installed',
137
139
  sentryReleaseCreated: 'Sentry release created for version: {{version}}',
@@ -182,8 +184,22 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
182
184
  nodeHdiffpatchRequired:
183
185
  'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
184
186
  apkExtracted: 'APK extracted to {{output}}',
187
+ composeSourceMapsNotFound:
188
+ 'Cannot find react-native/scripts/compose-source-maps.js, skipping hermes sourcemap composing. The uploaded sourcemap may not match the compiled bundle.',
189
+ installPackageRequired:
190
+ 'Please specify the package to install, e.g. "{{scriptName}} install node-hdiffpatch"',
191
+ installFailed: 'Failed to install {{packages}}: {{error}}',
185
192
  proxyNetworkError:
186
193
  'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
187
194
  proxyNetworkErrorTips:
188
195
  'Common fixes:\n1. Disable system proxy or VPN\n2. Check HTTP_PROXY / HTTPS_PROXY environment variables\n3. Check proxy settings in .npmrc',
196
+ invalidId: 'Invalid id: {{id}}',
197
+ outputPathRequired: 'Output path is required.',
198
+ unsupportedFileType: 'Unsupported file type: {{fileType}}',
199
+ failedToLoadSession: 'Failed to load session',
200
+ appIdRequired: 'appId is required',
201
+ unknownCommand: 'Unknown command: {{command}}',
202
+ unsupportedPlatformForHermes: 'Unsupported platform for Hermes: {{platform}}',
203
+ invalidManifest: 'Invalid manifest',
204
+ failedToResolveResource: 'Failed to resolve resource: {{error}}',
189
205
  };
package/src/locales/zh.ts CHANGED
@@ -123,6 +123,7 @@ export default {
123
123
  '已在原生版本 {{versions}} 上设置灰度发布 {{rollout}}% 热更包 {{version}}',
124
124
  rolloutRangeError: 'rollout 必须是 1-100 的整数',
125
125
  runningHermesc: '运行 hermesc:{{- command}} {{- args}}',
126
+ sentryReactNativeNotFound: '无法找到 @sentry/react-native,请确保已正确安装',
126
127
  sentryCliNotFound: '无法找到 Sentry CLI 工具,请确保已正确安装 @sentry/cli',
127
128
  sentryReleaseCreated: '已为版本 {{version}} 创建 Sentry release',
128
129
  totalApps: '共 {{count}} 个 {{platform}} 应用',
@@ -168,8 +169,22 @@ export default {
168
169
  nodeHdiffpatchRequired:
169
170
  '此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
170
171
  apkExtracted: 'APK 已提取到 {{output}}',
172
+ composeSourceMapsNotFound:
173
+ '找不到 react-native/scripts/compose-source-maps.js,跳过 hermes sourcemap 合成。上传的 sourcemap 可能与编译后的 bundle 不匹配。',
174
+ installPackageRequired:
175
+ '请指定要安装的包,例如 "{{scriptName}} install node-hdiffpatch"',
176
+ installFailed: '安装 {{packages}} 失败: {{error}}',
171
177
  proxyNetworkError:
172
178
  '网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
173
179
  proxyNetworkErrorTips:
174
180
  '常见解决方法:\n1. 关闭系统代理或 VPN\n2. 检查 HTTP_PROXY / HTTPS_PROXY 环境变量\n3. 检查 .npmrc 中的 proxy 配置',
181
+ invalidId: '无效的 id:{{id}}',
182
+ outputPathRequired: '必须指定输出路径。',
183
+ unsupportedFileType: '不支持的文件类型:{{fileType}}',
184
+ failedToLoadSession: '加载登录状态失败',
185
+ appIdRequired: '必须指定 appId',
186
+ unknownCommand: '未知命令:{{command}}',
187
+ unsupportedPlatformForHermes: 'Hermes 不支持当前系统平台:{{platform}}',
188
+ invalidManifest: '无效的 manifest',
189
+ failedToResolveResource: '资源解析失败:{{error}}',
175
190
  };
package/src/package.ts CHANGED
@@ -90,7 +90,7 @@ function toNumericIds(ids: string[]) {
90
90
  return ids.map((id) => {
91
91
  const numericId = Number(id);
92
92
  if (!Number.isInteger(numericId) || numericId <= 0) {
93
- throw new Error(`Invalid id: ${id}`);
93
+ throw new Error(t('invalidId', { id }));
94
94
  }
95
95
  return numericId;
96
96
  });
@@ -375,10 +375,10 @@ export const packageCommands = {
375
375
  throw new Error(t('noPackagesFound', { appId }));
376
376
  }
377
377
 
378
+ const allPkgsMap = new Map(allPkgs.map((pkg) => [pkg.name, pkg]));
379
+
378
380
  packageIds = packageVersions.map((packageVersion) => {
379
- const selectedPackage = allPkgs.find(
380
- (pkg) => pkg.name === packageVersion,
381
- );
381
+ const selectedPackage = allPkgsMap.get(packageVersion);
382
382
  if (!selectedPackage) {
383
383
  throw new Error(t('packageNotFound', { packageVersion }));
384
384
  }
package/src/provider.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
  UploadOptions,
13
13
  } from './types';
14
14
  import { runAsCommandResult } from './utils/command-result';
15
+ import { t } from './utils/i18n';
15
16
 
16
17
  const DEFAULT_BUNDLE_OUTPUT =
17
18
  '$' + '{tempDir}/output/$' + '{platform}.$' + '{time}.ppk';
@@ -164,7 +165,7 @@ export class CLIProviderImpl implements CLIProvider {
164
165
  : undefined;
165
166
 
166
167
  if (!uploadHandler) {
167
- throw new Error(`Unsupported file type: ${fileType}`);
168
+ throw new Error(t('unsupportedFileType', { fileType }));
168
169
  }
169
170
  await uploadHandler(context);
170
171
  },
@@ -244,15 +245,18 @@ export class CLIProviderImpl implements CLIProvider {
244
245
  async loadSession(): Promise<Session> {
245
246
  await this.ensureInitialized();
246
247
  if (!this.session) {
247
- throw new Error('Failed to load session');
248
+ throw new Error(t('failedToLoadSession'));
248
249
  }
249
250
  return this.session;
250
251
  }
251
252
 
252
253
  async listPackages(appId?: string): Promise<CommandResult> {
253
254
  return this.runDataCommand(async () => {
255
+ if (!appId) {
256
+ throw new Error(t('appIdRequired'));
257
+ }
254
258
  const { listPackage } = await import('./package');
255
- return listPackage(appId || '');
259
+ return listPackage(appId);
256
260
  }, 'Unknown error listing packages');
257
261
  }
258
262
  }
package/src/types.ts CHANGED
@@ -10,7 +10,8 @@ export interface Session {
10
10
  export type Platform = 'ios' | 'android' | 'harmony';
11
11
 
12
12
  export interface Package {
13
- id: string;
13
+ // server-side ids are numeric (auto-increment primary keys)
14
+ id: number;
14
15
  name: string;
15
16
  version?: string;
16
17
  status?: string;
@@ -22,7 +23,7 @@ export interface Package {
22
23
  }
23
24
 
24
25
  export interface Version {
25
- id: string;
26
+ id: number;
26
27
  hash: string;
27
28
  name: string;
28
29
  packages?: Package[];
@@ -57,8 +57,8 @@ export class AabParser extends Zip {
57
57
  });
58
58
 
59
59
  // Create a temp file for the .apks output
60
- const tempDir = os.tmpdir();
61
- const tempApksPath = path.join(tempDir, `temp-${Date.now()}.apks`);
60
+ const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'bundletool-'));
61
+ const tempApksPath = path.join(tempDir, 'output.apks');
62
62
 
63
63
  const needsNpxDownload = async () => {
64
64
  try {
@@ -155,8 +155,8 @@ export class AabParser extends Zip {
155
155
  });
156
156
  } finally {
157
157
  // Cleanup
158
- if (await fs.pathExists(tempApksPath)) {
159
- await fs.remove(tempApksPath);
158
+ if (await fs.pathExists(tempDir)) {
159
+ await fs.remove(tempDir);
160
160
  }
161
161
  }
162
162
  }
@@ -173,7 +173,7 @@ export class BinaryXmlParser {
173
173
  };
174
174
 
175
175
  const value = this.readU32();
176
- const unit = (dimension.value ?? 0) & 0xff;
176
+ const unit = value & 0xff;
177
177
 
178
178
  dimension.value = value >> 8;
179
179
  dimension.rawUnit = unit;
@@ -567,10 +567,9 @@ and is supposed to end at offset ${end}. Ignoring the rest of the value.`);
567
567
 
568
568
  if (valueRef > 0) {
569
569
  if (attr.name === 'versionName') {
570
- this.strings[valueRef] = this.strings[valueRef].replace(
571
- /[^\x21-\x7E]/g,
572
- '',
573
- );
570
+ // strip UTF-16 null padding only; keep spaces and non-ASCII chars
571
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: removing NUL padding is the point
572
+ this.strings[valueRef] = this.strings[valueRef].replace(/\u0000/g, '');
574
573
  }
575
574
  attr.value = this.strings[valueRef];
576
575
  }
@@ -15,9 +15,12 @@ export class ManifestParser {
15
15
 
16
16
  private collapseAttributes(element: any) {
17
17
  const collapsed: Record<string, any> = Object.create(null);
18
- for (const attr of Array.from(
19
- element.attributes as Array<{ name: string; typedValue: { value: any } }>,
20
- )) {
18
+ const attributes = element.attributes as Array<{
19
+ name: string;
20
+ typedValue: { value: any };
21
+ }>;
22
+ for (let i = 0, len = attributes.length; i < len; i++) {
23
+ const attr = attributes[i];
21
24
  collapsed[attr.name] = attr.typedValue.value;
22
25
  }
23
26
  return collapsed;
@@ -37,20 +37,33 @@ export class Zip {
37
37
  async getEntryFromHarmonyApp(
38
38
  regex: RegExp,
39
39
  ): Promise<Buffer | Blob | undefined> {
40
+ return (await this.getEntriesFromHarmonyApp([regex]))[0];
41
+ }
42
+
43
+ /**
44
+ * Read multiple entries in a single pass over the archive (including
45
+ * nested .hap extraction), instead of one full scan per entry.
46
+ * Returns buffers in the same order as the given regexps.
47
+ */
48
+ async getEntriesFromHarmonyApp(
49
+ regexps: RegExp[],
50
+ ): Promise<(Buffer | undefined)[]> {
51
+ const results: (Buffer | undefined)[] = new Array(regexps.length);
40
52
  try {
41
- let originSource: Buffer | Blob | undefined;
42
53
  if (typeof this.file !== 'string') {
43
54
  throw new Error('Param error: [file] must be file path in Node.');
44
55
  }
45
56
  await enumZipEntries(this.file, async (entry, zipFile) => {
46
- if (regex.test(entry.fileName)) {
47
- originSource = await readEntry(entry, zipFile);
57
+ for (let i = 0; i < regexps.length; i++) {
58
+ if (regexps[i].test(entry.fileName)) {
59
+ results[i] = await readEntry(entry, zipFile);
60
+ }
48
61
  }
49
62
  });
50
- return originSource;
51
63
  } catch (error) {
52
- console.error('Error in getEntryFromHarmonyApp:', error);
64
+ console.error('Error in getEntriesFromHarmonyApp:', error);
53
65
  }
66
+ return results;
54
67
  }
55
68
 
56
69
  private async readEntries(
@@ -74,6 +87,10 @@ export class Zip {
74
87
  return pattern === entryName || pattern === lowerEntryName;
75
88
  }
76
89
  pattern.lastIndex = 0;
90
+ if (pattern.test(entryName)) {
91
+ return true;
92
+ }
93
+ pattern.lastIndex = 0;
77
94
  return pattern.test(lowerEntryName);
78
95
  });
79
96
 
@@ -10,8 +10,12 @@ const lockFiles = [
10
10
  'bun.lock',
11
11
  ];
12
12
 
13
- // Function to check if a package.json has a workspaces field
13
+ // Function to check if a directory is a monorepo root
14
+ // (package.json workspaces field, or pnpm-workspace.yaml)
14
15
  function hasWorkspaces(dir: string): boolean {
16
+ if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
17
+ return true;
18
+ }
15
19
  const pkgPath = path.join(dir, 'package.json');
16
20
  if (fs.existsSync(pkgPath)) {
17
21
  try {
@@ -1,6 +1,10 @@
1
1
  import path from 'path';
2
2
 
3
- export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
3
+ export const scriptName =
4
+ process.env.RNU_BRAND === 'cresc' ||
5
+ path.basename(process.argv[1] ?? '') === 'cresc'
6
+ ? 'cresc'
7
+ : 'pushy';
4
8
  export const IS_CRESC = scriptName === 'cresc';
5
9
 
6
10
  export const ppkBundleFileNames = ['index.bundlejs', 'bundle.harmony.js'];
@@ -23,34 +23,27 @@ export function promiseAny<T>(promises: Promise<T>[]) {
23
23
  }
24
24
 
25
25
  export const ping = async (url: string) => {
26
- let pingFinished = false;
27
- return Promise.race([
28
- runtimeFetch(url, {
29
- method: 'HEAD',
30
- })
31
- .then(({ status }) => {
32
- pingFinished = true;
26
+ let timer: ReturnType<typeof setTimeout> | undefined;
27
+ try {
28
+ return await (Promise.race([
29
+ runtimeFetch(url, {
30
+ method: 'HEAD',
31
+ }).then(({ status }) => {
33
32
  if (status === 200) {
34
- // console.log('ping success', url);
35
33
  return url;
36
34
  }
37
- // console.log('ping failed', url, status, statusText);
38
35
  throw new Error('ping failed');
39
- })
40
- .catch((_e) => {
41
- pingFinished = true;
42
- // console.log('ping error', url, e);
43
- throw new Error('ping error');
44
36
  }),
45
- new Promise((_, reject) =>
46
- setTimeout(() => {
47
- reject(new Error('ping timeout'));
48
- if (!pingFinished) {
49
- // console.log('ping timeout', url);
50
- }
51
- }, 5000),
52
- ),
53
- ]) as Promise<string | null>;
37
+ new Promise((_, reject) => {
38
+ timer = setTimeout(() => {
39
+ reject(new Error('ping timeout'));
40
+ }, 5000);
41
+ }),
42
+ ]) as Promise<string | null>);
43
+ } finally {
44
+ // clear the timer so it doesn't keep the process alive for 5s
45
+ clearTimeout(timer);
46
+ }
54
47
  };
55
48
 
56
49
  export const testUrls = async (urls?: string[]) => {