react-native-update-cli 2.15.3 → 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.
@@ -241,6 +241,11 @@ export async function runReactNativeBundleCommand({
241
241
  process.env.SENTRY_PROPERTIES = 'ios/sentry.properties';
242
242
  } else if (platform === 'android') {
243
243
  process.env.SENTRY_PROPERTIES = 'android/sentry.properties';
244
+ } else if (
245
+ platform === 'harmony' &&
246
+ fs.existsSync('harmony/sentry.properties')
247
+ ) {
248
+ process.env.SENTRY_PROPERTIES = 'harmony/sentry.properties';
244
249
  }
245
250
  }
246
251
 
@@ -302,20 +307,24 @@ export async function runReactNativeBundleCommand({
302
307
  console.error(data.toString().trim());
303
308
  });
304
309
 
310
+ reactNativeBundleProcess.once('error', reject);
311
+
305
312
  reactNativeBundleProcess.on('close', async (exitCode) => {
306
313
  if (exitCode) {
307
314
  reject(new Error(t('bundleCommandError', { code: exitCode })));
308
315
  return;
309
316
  }
310
317
 
311
- let hermesEnabled: boolean | undefined = false;
318
+ try {
319
+ let hermesEnabled: boolean | undefined = false;
312
320
 
313
- if (forceHermes) {
314
- hermesEnabled = true;
315
- console.log(t('forceHermes'));
316
- } else if (platform === 'android') {
317
- const gradleProperties = await new Promise<{ hermesEnabled?: boolean }>(
318
- (resolve) => {
321
+ if (forceHermes) {
322
+ hermesEnabled = true;
323
+ console.log(t('forceHermes'));
324
+ } else if (platform === 'android') {
325
+ const gradleProperties = await new Promise<{
326
+ hermesEnabled?: boolean;
327
+ }>((resolve) => {
319
328
  properties.parse(
320
329
  './android/gradle.properties',
321
330
  { path: true },
@@ -331,42 +340,48 @@ export async function runReactNativeBundleCommand({
331
340
  resolve(props);
332
341
  },
333
342
  );
334
- },
335
- );
336
- hermesEnabled = gradleProperties.hermesEnabled;
343
+ });
344
+ hermesEnabled = gradleProperties.hermesEnabled;
345
+
346
+ if (typeof hermesEnabled !== 'boolean') {
347
+ hermesEnabled = gradleConfig.enableHermes;
348
+ }
349
+ } else if (
350
+ platform === 'ios' &&
351
+ fs.existsSync('ios/Pods/hermes-engine')
352
+ ) {
353
+ hermesEnabled = true;
354
+ }
337
355
 
338
- if (typeof hermesEnabled !== 'boolean') {
339
- hermesEnabled = gradleConfig.enableHermes;
356
+ if (hermesEnabled) {
357
+ await compileHermesByteCode(
358
+ bundleName,
359
+ outputFolder,
360
+ sourcemapOutput,
361
+ !isSentry,
362
+ );
340
363
  }
341
- } else if (
342
- platform === 'ios' &&
343
- fs.existsSync('ios/Pods/hermes-engine')
344
- ) {
345
- hermesEnabled = true;
346
- }
347
364
 
348
- if (hermesEnabled) {
349
- await compileHermesByteCode(
350
- bundleName,
351
- outputFolder,
352
- sourcemapOutput,
353
- !isSentry,
354
- );
355
- }
365
+ if (platform === 'harmony') {
366
+ const harmonyRawAssetsPath =
367
+ 'harmony/entry/src/main/resources/rawfile/assets';
368
+ fs.ensureDirSync(harmonyRawAssetsPath);
369
+ fs.copySync(outputFolder, harmonyRawAssetsPath, {
370
+ overwrite: true,
371
+ // sourcemaps must not ship inside the native package
372
+ filter: (src) => !src.endsWith('.map'),
373
+ });
374
+ fs.moveSync(
375
+ `${harmonyRawAssetsPath}/bundle.harmony.js`,
376
+ `${harmonyRawAssetsPath}/../bundle.harmony.js`,
377
+ { overwrite: true },
378
+ );
379
+ }
356
380
 
357
- if (platform === 'harmony') {
358
- const harmonyRawAssetsPath =
359
- 'harmony/entry/src/main/resources/rawfile/assets';
360
- fs.ensureDirSync(harmonyRawAssetsPath);
361
- fs.copySync(outputFolder, harmonyRawAssetsPath, { overwrite: true });
362
- fs.moveSync(
363
- `${harmonyRawAssetsPath}/bundle.harmony.js`,
364
- `${harmonyRawAssetsPath}/../bundle.harmony.js`,
365
- { overwrite: true },
366
- );
381
+ resolve();
382
+ } catch (error) {
383
+ reject(error);
367
384
  }
368
-
369
- resolve();
370
385
  });
371
386
  });
372
387
  }
@@ -418,7 +433,9 @@ function normalizeString(value: string | undefined): string | undefined {
418
433
  export function resolveHermesCommand(projectRoot = process.cwd()): string {
419
434
  const osBin = getHermesOSBin();
420
435
  if (!osBin) {
421
- throw new Error(`Unsupported platform for Hermes: ${os.platform()}`);
436
+ throw new Error(
437
+ t('unsupportedPlatformForHermes', { platform: os.platform() }),
438
+ );
422
439
  }
423
440
 
424
441
  const executableName = getHermesExecutableName();
@@ -529,9 +546,15 @@ async function compileHermesByteCode(
529
546
  hermesCommand,
530
547
  );
531
548
  if (sourcemapOutput) {
532
- const composerPath =
533
- 'node_modules/react-native/scripts/compose-source-maps.js';
534
- if (!fs.existsSync(composerPath)) {
549
+ let composerPath: string;
550
+ try {
551
+ // resolve through the project so hoisted node_modules (monorepos) work
552
+ composerPath = require.resolve(
553
+ 'react-native/scripts/compose-source-maps.js',
554
+ { paths: [process.cwd()] },
555
+ );
556
+ } catch {
557
+ console.warn(t('composeSourceMapsNotFound'));
535
558
  return;
536
559
  }
537
560
  console.log(t('composingSourceMap'));
@@ -571,7 +594,7 @@ export async function copyDebugidForSentry(
571
594
  },
572
595
  );
573
596
  } catch {
574
- console.error(t('sentryCliNotFound'));
597
+ console.error(t('sentryReactNativeNotFound'));
575
598
  return;
576
599
  }
577
600
 
package/src/bundle.ts CHANGED
@@ -70,16 +70,17 @@ function getAliasedOptionalStringOption(
70
70
  );
71
71
  }
72
72
 
73
- function normalizeBundleOptions(
73
+ export function normalizeBundleOptions(
74
74
  translatedOptions: Record<string, unknown>,
75
75
  platform: string,
76
76
  ): NormalizedBundleOptions {
77
77
  return {
78
- bundleName: getStringOption(
79
- translatedOptions,
80
- 'bundleName',
81
- 'index.bundlejs',
82
- ),
78
+ // harmony bundles always use this fixed name (runReactNativeBundleCommand
79
+ // forces it), so sourcemap paths and Sentry uploads must match
80
+ bundleName:
81
+ platform === 'harmony'
82
+ ? 'bundle.harmony.js'
83
+ : getStringOption(translatedOptions, 'bundleName', 'index.bundlejs'),
83
84
  entryFile: getStringOption(translatedOptions, 'entryFile', 'index.js'),
84
85
  intermediaDir: getStringOption(
85
86
  translatedOptions,
@@ -203,7 +204,7 @@ export const bundleCommands = {
203
204
  throw new Error(t('platformRequired'));
204
205
  }
205
206
 
206
- console.log(`Bundling with react-native: ${depVersions['react-native']}`);
207
+ console.log(t('bundlingWithRN', { version: depVersions['react-native'] }));
207
208
 
208
209
  await runReactNativeBundleCommand({
209
210
  bundleName: normalized.bundleName,
@@ -222,7 +223,11 @@ export const bundleCommands = {
222
223
  isSentry: bundleParams.sentry,
223
224
  });
224
225
 
225
- await packBundle(path.resolve(normalized.intermediaDir), realOutput);
226
+ await packBundle(
227
+ path.resolve(normalized.intermediaDir),
228
+ realOutput,
229
+ normalized.bundleName,
230
+ );
226
231
 
227
232
  if (normalized.name) {
228
233
  await publishBundleVersion(realOutput, platform, {
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';
@@ -61,14 +62,85 @@ function basename(fn: string): string | undefined {
61
62
  return m?.[1];
62
63
  }
63
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
+
64
138
  async function diffFromPPK(
65
139
  origin: string,
66
140
  next: string,
67
141
  output: string,
68
142
  diffFn: Diff,
69
143
  ) {
70
- fs.ensureDirSync(path.dirname(output));
71
-
72
144
  const originEntries: EntryMap = {};
73
145
  const originMap: CrcMap = {};
74
146
 
@@ -93,14 +165,7 @@ async function diffFromPPK(
93
165
 
94
166
  const copies: CopyMap = {};
95
167
 
96
- const zipfile = new YazlZipFile();
97
-
98
- const writePromise = new Promise<void>((resolve, reject) => {
99
- zipfile.outputStream.on('error', reject);
100
- zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
101
- resolve(void 0);
102
- });
103
- });
168
+ const { zipfile, writePromise } = createOutputZip(output);
104
169
 
105
170
  const addedEntry: Record<string, true> = {};
106
171
 
@@ -128,15 +193,7 @@ async function diffFromPPK(
128
193
  addEntry(entry.fileName);
129
194
  }
130
195
  } else if (isPPKBundleFileName(entry.fileName)) {
131
- //console.log('Found bundle');
132
- const newSource = await readEntry(entry, nextZipfile);
133
- //console.log('Begin diff');
134
- zipfile.addBuffer(
135
- diffFn(originSource, newSource),
136
- `${entry.fileName}.patch`,
137
- zipOptionsForPatchEntry(),
138
- );
139
- //console.log('End diff');
196
+ await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource);
140
197
  } else {
141
198
  // If same file.
142
199
  const originEntry = originEntries[entry.fileName];
@@ -162,33 +219,7 @@ async function diffFromPPK(
162
219
  addEntry(basePath);
163
220
  }
164
221
 
165
- const entryPrefix = await readEntryPrefix(
166
- entry,
167
- nextZipfile,
168
- ZIP_ENTRY_SNIFF_BYTES,
169
- );
170
- await new Promise<void>((resolve, reject) => {
171
- nextZipfile.openReadStream(entry, (err, readStream) => {
172
- if (err) {
173
- return reject(err);
174
- }
175
- if (!readStream) {
176
- return reject(
177
- new Error(`Unable to read zip entry: ${entry.fileName}`),
178
- );
179
- }
180
- zipfile.addReadStream(
181
- readStream,
182
- entry.fileName,
183
- zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
184
- );
185
- readStream.on('error', reject);
186
- readStream.on('end', () => {
187
- //console.log('add finished');
188
- resolve(void 0);
189
- });
190
- });
191
- });
222
+ await addFileFromZipEntry(zipfile, entry, nextZipfile);
192
223
  }
193
224
  });
194
225
 
@@ -201,15 +232,7 @@ async function diffFromPPK(
201
232
  }
202
233
  }
203
234
 
204
- //console.log({copies, deletes});
205
- const diffManifest = Buffer.from(JSON.stringify({ copies, deletes }));
206
- zipfile.addBuffer(
207
- diffManifest,
208
- '__diff.json',
209
- zipOptionsForManifestEntry(diffManifest.length),
210
- );
211
- zipfile.end();
212
- await writePromise;
235
+ await finishDiffZip(zipfile, writePromise, { copies, deletes });
213
236
  }
214
237
 
215
238
  async function diffFromPackage(
@@ -220,8 +243,6 @@ async function diffFromPackage(
220
243
  originBundleName: string,
221
244
  transformPackagePath: (v: string) => string | undefined = (v: string) => v,
222
245
  ) {
223
- fs.ensureDirSync(path.dirname(output));
224
-
225
246
  const originEntries: Record<string, number> = {};
226
247
  const originMap: CrcMap = {};
227
248
 
@@ -259,29 +280,14 @@ async function diffFromPackage(
259
280
 
260
281
  const copies: CopyMap = {};
261
282
 
262
- const zipfile = new YazlZipFile();
263
-
264
- const writePromise = new Promise<void>((resolve, reject) => {
265
- zipfile.outputStream.on('error', reject);
266
- zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
267
- resolve(void 0);
268
- });
269
- });
283
+ const { zipfile, writePromise } = createOutputZip(output);
270
284
 
271
285
  await enumZipEntries(next, async (entry, nextZipfile) => {
272
286
  if (/\/$/.test(entry.fileName)) {
273
287
  // Directory
274
288
  zipfile.addEmptyDirectory(entry.fileName);
275
289
  } else if (isPPKBundleFileName(entry.fileName)) {
276
- //console.log('Found bundle');
277
- const newSource = await readEntry(entry, nextZipfile);
278
- //console.log('Begin diff');
279
- zipfile.addBuffer(
280
- diffFn(originSource, newSource),
281
- `${entry.fileName}.patch`,
282
- zipOptionsForPatchEntry(),
283
- );
284
- //console.log('End diff');
290
+ await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource);
285
291
  } else {
286
292
  // If same file.
287
293
  if (originEntries[entry.fileName] === entry.crc32) {
@@ -299,44 +305,11 @@ async function diffFromPackage(
299
305
  return;
300
306
  }
301
307
 
302
- const entryPrefix = await readEntryPrefix(
303
- entry,
304
- nextZipfile,
305
- ZIP_ENTRY_SNIFF_BYTES,
306
- );
307
- await new Promise<void>((resolve, reject) => {
308
- nextZipfile.openReadStream(entry, (err, readStream) => {
309
- if (err) {
310
- return reject(err);
311
- }
312
- if (!readStream) {
313
- return reject(
314
- new Error(`Unable to read zip entry: ${entry.fileName}`),
315
- );
316
- }
317
- zipfile.addReadStream(
318
- readStream,
319
- entry.fileName,
320
- zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
321
- );
322
- readStream.on('error', reject);
323
- readStream.on('end', () => {
324
- //console.log('add finished');
325
- resolve(void 0);
326
- });
327
- });
328
- });
308
+ await addFileFromZipEntry(zipfile, entry, nextZipfile);
329
309
  }
330
310
  });
331
311
 
332
- const diffManifest = Buffer.from(JSON.stringify({ copies, copiesCrc }));
333
- zipfile.addBuffer(
334
- diffManifest,
335
- '__diff.json',
336
- zipOptionsForManifestEntry(diffManifest.length),
337
- );
338
- zipfile.end();
339
- await writePromise;
312
+ await finishDiffZip(zipfile, writePromise, { copies, copiesCrc });
340
313
  }
341
314
 
342
315
  type DiffCommandOptions = {
@@ -374,7 +347,7 @@ function diffArgsCheck(
374
347
  tempDir,
375
348
  } as DiffCommandOptions & { tempDir: string });
376
349
  if (typeof output !== 'string') {
377
- throw new Error('Output path is required.');
350
+ throw new Error(t('outputPathRequired'));
378
351
  }
379
352
 
380
353
  return {
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,6 +184,8 @@ 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.',
185
189
  installPackageRequired:
186
190
  'Please specify the package to install, e.g. "{{scriptName}} install node-hdiffpatch"',
187
191
  installFailed: 'Failed to install {{packages}}: {{error}}',
@@ -189,4 +193,13 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
189
193
  'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
190
194
  proxyNetworkErrorTips:
191
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}}',
192
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,6 +169,8 @@ 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 不匹配。',
171
174
  installPackageRequired:
172
175
  '请指定要安装的包,例如 "{{scriptName}} install node-hdiffpatch"',
173
176
  installFailed: '安装 {{packages}} 失败: {{error}}',
@@ -175,4 +178,13 @@ export default {
175
178
  '网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
176
179
  proxyNetworkErrorTips:
177
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}}',
178
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
  });
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[];
@@ -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
  }
@@ -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