react-native-update-cli 2.15.2 → 2.15.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/cli.json CHANGED
@@ -221,9 +221,6 @@
221
221
  }
222
222
  }
223
223
  },
224
- "build": {
225
- "description": "Bundle javascript and copy assets."
226
- },
227
224
  "bundle": {
228
225
  "description": "Bundle javascript code only and optionally publish.",
229
226
  "options": {
@@ -316,9 +313,6 @@
316
313
  }
317
314
  }
318
315
  },
319
- "release": {
320
- "description": "Push builded file to server."
321
- },
322
316
  "hdiff": {
323
317
  "description": "Create hdiff patch",
324
318
  "options": {
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // Dedicated entry for the `cresc` bin so brand detection does not depend on
4
+ // process.argv[1], which on Windows npm shims always points to the js file
5
+ // instead of the invoked command name.
6
+ process.env.RNU_BRAND = 'cresc';
7
+ require('./bin');
package/lib/bin.js CHANGED
@@ -64,10 +64,10 @@ async function run() {
64
64
  } catch (err) {
65
65
  if (err.status === 401) {
66
66
  console.log((0, _i18n.t)('loginFirst'));
67
- return;
67
+ process.exit(1);
68
68
  }
69
69
  console.error(err.stack);
70
- process.exit(-1);
70
+ process.exit(1);
71
71
  }
72
72
  }
73
73
  run();
@@ -50,9 +50,9 @@ export declare function resolveExpoCli(projectRoot?: string): ResolvedExpoCli;
50
50
  export declare function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, cli, isSentry, }: RunBundleCommandOptions): Promise<void>;
51
51
  export declare function resolveHermesCommand(projectRoot?: string): string;
52
52
  export declare function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string): Promise<void>;
53
- export declare function prepareSentryUploadArtifacts(bundleName: string, outputFolder: string, platform: string): SentryUploadArtifacts;
54
- export declare function readSourcemapDebugId(sourcemapPath: string): string | undefined;
55
- export declare function resolveSentryUploadMode(sourcemapPath: string, options?: SentryUploadOptions): SentryUploadMode;
53
+ export declare function prepareSentryUploadArtifacts(bundleName: string, outputFolder: string, platform: string): Promise<SentryUploadArtifacts>;
54
+ export declare function readSourcemapDebugId(sourcemapPath: string): Promise<string | undefined>;
55
+ export declare function resolveSentryUploadMode(sourcemapPath: string, options?: SentryUploadOptions): Promise<SentryUploadMode>;
56
56
  export declare function buildSentrySourcemapsUploadArgs({ sentryCliPath, bundlePath, sourcemapPath, release, dist, stripPrefix, debugIdReference, useStandaloneSourcemapsCommand, }: BuildSentrySourcemapsUploadArgsOptions): string[];
57
57
  export declare function uploadSourcemapForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string, platform?: string, sentryOptions?: SentryUploadOptions): Promise<void>;
58
58
  export {};
@@ -464,7 +464,7 @@ async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
464
464
  }
465
465
  _fsextra.removeSync(_path.default.join(outputFolder, `${bundleName}.txt.map`));
466
466
  }
467
- function prepareSentryUploadArtifacts(bundleName, outputFolder, platform) {
467
+ async function prepareSentryUploadArtifacts(bundleName, outputFolder, platform) {
468
468
  const bundlePath = _path.default.join(outputFolder, bundleName);
469
469
  const sourcemapPath = _path.default.join(outputFolder, `${bundleName}.map`);
470
470
  if (platform !== 'android' || bundleName === ANDROID_SENTRY_BUNDLE_NAME) {
@@ -475,19 +475,19 @@ function prepareSentryUploadArtifacts(bundleName, outputFolder, platform) {
475
475
  }
476
476
  const androidBundlePath = _path.default.join(outputFolder, ANDROID_SENTRY_BUNDLE_NAME);
477
477
  const androidSourcemapPath = _path.default.join(outputFolder, `${ANDROID_SENTRY_BUNDLE_NAME}.map`);
478
- _fsextra.copyFileSync(bundlePath, androidBundlePath);
479
- const sourcemap = JSON.parse(_fsextra.readFileSync(sourcemapPath, 'utf8'));
478
+ await _fsextra.promises.copyFile(bundlePath, androidBundlePath);
479
+ const sourcemap = JSON.parse(await _fsextra.promises.readFile(sourcemapPath, 'utf8'));
480
480
  sourcemap.file = ANDROID_SENTRY_BUNDLE_NAME;
481
- _fsextra.writeFileSync(androidSourcemapPath, JSON.stringify(sourcemap));
481
+ await _fsextra.promises.writeFile(androidSourcemapPath, JSON.stringify(sourcemap));
482
482
  return {
483
483
  bundlePath: androidBundlePath,
484
484
  sourcemapPath: androidSourcemapPath
485
485
  };
486
486
  }
487
- function readSourcemapDebugId(sourcemapPath) {
487
+ async function readSourcemapDebugId(sourcemapPath) {
488
488
  try {
489
489
  var _sourcemap_debugId;
490
- const sourcemap = JSON.parse(_fsextra.readFileSync(sourcemapPath, 'utf8'));
490
+ const sourcemap = JSON.parse(await _fsextra.promises.readFile(sourcemapPath, 'utf8'));
491
491
  const debugId = (_sourcemap_debugId = sourcemap.debugId) != null ? _sourcemap_debugId : sourcemap.debug_id;
492
492
  return typeof debugId === 'string' ? normalizeString(debugId) : undefined;
493
493
  } catch (unused) {
@@ -504,7 +504,7 @@ function resolveSentryReleaseFromValues(releaseValue, distValue) {
504
504
  dist: normalizeString(distValue)
505
505
  };
506
506
  }
507
- function resolveSentryUploadMode(sourcemapPath, options = {}) {
507
+ async function resolveSentryUploadMode(sourcemapPath, options = {}) {
508
508
  const optionRelease = resolveSentryReleaseFromValues(options.sentryRelease, options.sentryDist);
509
509
  if (optionRelease) {
510
510
  return {
@@ -512,7 +512,7 @@ function resolveSentryUploadMode(sourcemapPath, options = {}) {
512
512
  ...optionRelease
513
513
  };
514
514
  }
515
- const debugId = readSourcemapDebugId(sourcemapPath);
515
+ const debugId = await readSourcemapDebugId(sourcemapPath);
516
516
  if (debugId) {
517
517
  return {
518
518
  type: 'debug-id',
@@ -644,8 +644,8 @@ async function uploadSourcemapForSentry(bundleName, outputFolder, sourcemapOutpu
644
644
  if (!_fsextra.existsSync(sentryCliPath)) {
645
645
  return;
646
646
  }
647
- const { bundlePath, sourcemapPath } = prepareSentryUploadArtifacts(bundleName, outputFolder, platform);
648
- const uploadMode = resolveSentryUploadMode(sourcemapPath, sentryOptions);
647
+ const { bundlePath, sourcemapPath } = await prepareSentryUploadArtifacts(bundleName, outputFolder, platform);
648
+ const uploadMode = await resolveSentryUploadMode(sourcemapPath, sentryOptions);
649
649
  const useStandaloneSourcemapsCommand = supportsStandaloneSentrySourcemapsUpload(sentryCliPath);
650
650
  if (uploadMode.type === 'release') {
651
651
  uploadSourcemapsWithRelease({
package/lib/diff.js CHANGED
@@ -75,8 +75,10 @@ function _interop_require_wildcard(obj, nodeInterop) {
75
75
  return newObj;
76
76
  }
77
77
  const loadModule = (pkgName)=>{
78
+ const nodePathDirs = (process.env.NODE_PATH || '').split(_path.default.delimiter).filter(Boolean);
78
79
  const resolvePaths = [
79
80
  '.',
81
+ ...nodePathDirs,
80
82
  _globaldirs.npm.packages,
81
83
  _globaldirs.yarn.packages
82
84
  ];
@@ -179,6 +181,7 @@ async function diffFromPPK(origin, next, output, diffFn) {
179
181
  return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
180
182
  }
181
183
  zipfile.addReadStream(readStream, entry.fileName, (0, _zipoptions.zipOptionsForPayloadEntry)(entry.fileName, entryPrefix));
184
+ readStream.on('error', reject);
182
185
  readStream.on('end', ()=>{
183
186
  //console.log('add finished');
184
187
  resolve(void 0);
@@ -279,6 +282,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
279
282
  return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
280
283
  }
281
284
  zipfile.addReadStream(readStream, entry.fileName, (0, _zipoptions.zipOptionsForPayloadEntry)(entry.fileName, entryPrefix));
285
+ readStream.on('error', reject);
282
286
  readStream.on('end', ()=>{
283
287
  //console.log('add finished');
284
288
  resolve(void 0);
package/lib/install.js CHANGED
@@ -10,23 +10,50 @@ Object.defineProperty(exports, "installCommands", {
10
10
  });
11
11
  const _child_process = require("child_process");
12
12
  const _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ const _constants = require("./utils/constants");
14
+ const _i18n = require("./utils/i18n");
13
15
  const _runtime = require("./utils/runtime");
14
16
  function _interop_require_default(obj) {
15
17
  return obj && obj.__esModule ? obj : {
16
18
  default: obj
17
19
  };
18
20
  }
21
+ // package names / version specs only — rejects shell metacharacters since
22
+ // Windows needs shell: true to run package manager .cmd shims
23
+ const SAFE_PACKAGE_ARG = /^[@a-z0-9^~._/-]+$/i;
19
24
  const installCommands = {
20
25
  install: async ({ args })=>{
21
26
  if (args.length === 0) {
22
- return;
27
+ throw new Error((0, _i18n.t)('installPackageRequired', {
28
+ scriptName: _constants.scriptName
29
+ }));
30
+ }
31
+ for (const arg of args){
32
+ if (!SAFE_PACKAGE_ARG.test(arg)) {
33
+ throw new Error((0, _i18n.t)('installPackageRequired', {
34
+ scriptName: _constants.scriptName
35
+ }));
36
+ }
23
37
  }
24
38
  const cliDir = _path.default.resolve(__dirname, '..');
25
39
  const installCommand = (0, _runtime.getInstallCommand)(args, cliDir);
26
- (0, _child_process.spawnSync)(installCommand.command, installCommand.args, {
40
+ const result = (0, _child_process.spawnSync)(installCommand.command, installCommand.args, {
27
41
  cwd: cliDir,
28
42
  stdio: 'inherit',
29
- shell: true
43
+ // package manager executables are .cmd shims on Windows
44
+ shell: process.platform === 'win32'
30
45
  });
46
+ if (result.error) {
47
+ throw new Error((0, _i18n.t)('installFailed', {
48
+ packages: args.join(' '),
49
+ error: result.error.message
50
+ }));
51
+ }
52
+ if (result.status !== 0) {
53
+ throw new Error((0, _i18n.t)('installFailed', {
54
+ packages: args.join(' '),
55
+ error: `${installCommand.command} exited with code ${result.status}`
56
+ }));
57
+ }
31
58
  }
32
59
  };
@@ -136,6 +136,8 @@ declare const _default: {
136
136
  diffPackageGenerated: string;
137
137
  nodeHdiffpatchRequired: string;
138
138
  apkExtracted: string;
139
+ installPackageRequired: string;
140
+ installFailed: string;
139
141
  proxyNetworkError: string;
140
142
  proxyNetworkErrorTips: string;
141
143
  };
package/lib/locales/en.js CHANGED
@@ -152,6 +152,8 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
152
152
  diffPackageGenerated: '{{- output}} generated.',
153
153
  nodeHdiffpatchRequired: 'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
154
154
  apkExtracted: 'APK extracted to {{output}}',
155
+ installPackageRequired: 'Please specify the package to install, e.g. "{{scriptName}} install node-hdiffpatch"',
156
+ installFailed: 'Failed to install {{packages}}: {{error}}',
155
157
  proxyNetworkError: 'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
156
158
  proxyNetworkErrorTips: 'Common fixes:\n1. Disable system proxy or VPN\n2. Check HTTP_PROXY / HTTPS_PROXY environment variables\n3. Check proxy settings in .npmrc'
157
159
  };
@@ -135,6 +135,8 @@ declare const _default: {
135
135
  diffPackageGenerated: string;
136
136
  nodeHdiffpatchRequired: string;
137
137
  apkExtracted: string;
138
+ installPackageRequired: string;
139
+ installFailed: string;
138
140
  proxyNetworkError: string;
139
141
  proxyNetworkErrorTips: string;
140
142
  };
package/lib/locales/zh.js CHANGED
@@ -151,6 +151,8 @@ const _default = {
151
151
  diffPackageGenerated: '{{- output}} 已生成。',
152
152
  nodeHdiffpatchRequired: '此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
153
153
  apkExtracted: 'APK 已提取到 {{output}}',
154
+ installPackageRequired: '请指定要安装的包,例如 "{{scriptName}} install node-hdiffpatch"',
155
+ installFailed: '安装 {{packages}} 失败: {{error}}',
154
156
  proxyNetworkError: '网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
155
157
  proxyNetworkErrorTips: '常见解决方法:\n1. 关闭系统代理或 VPN\n2. 检查 HTTP_PROXY / HTTPS_PROXY 环境变量\n3. 检查 .npmrc 中的 proxy 配置'
156
158
  };
package/lib/package.js CHANGED
@@ -341,8 +341,12 @@ const packageCommands = {
341
341
  appId
342
342
  }));
343
343
  }
344
+ const allPkgsMap = new Map(allPkgs.map((pkg)=>[
345
+ pkg.name,
346
+ pkg
347
+ ]));
344
348
  packageIds = packageVersions.map((packageVersion)=>{
345
- const selectedPackage = allPkgs.find((pkg)=>pkg.name === packageVersion);
349
+ const selectedPackage = allPkgsMap.get(packageVersion);
346
350
  if (!selectedPackage) {
347
351
  throw new Error((0, _i18n.t)('packageNotFound', {
348
352
  packageVersion
@@ -101,8 +101,8 @@ class AabParser extends _zip.Zip {
101
101
  });
102
102
  });
103
103
  // Create a temp file for the .apks output
104
- const tempDir = _os.default.tmpdir();
105
- const tempApksPath = _path.default.join(tempDir, `temp-${Date.now()}.apks`);
104
+ const tempDir = await _fsextra.mkdtemp(_path.default.join(_os.default.tmpdir(), 'bundletool-'));
105
+ const tempApksPath = _path.default.join(tempDir, 'output.apks');
106
106
  const needsNpxDownload = async ()=>{
107
107
  try {
108
108
  await runCommand('npx', [
@@ -191,8 +191,8 @@ class AabParser extends _zip.Zip {
191
191
  });
192
192
  } finally{
193
193
  // Cleanup
194
- if (await _fsextra.pathExists(tempApksPath)) {
195
- await _fsextra.remove(tempApksPath);
194
+ if (await _fsextra.pathExists(tempDir)) {
195
+ await _fsextra.remove(tempDir);
196
196
  }
197
197
  }
198
198
  }
@@ -15,7 +15,9 @@ const CATEGORY_LAUNCHER = 'android.intent.category.LAUNCHER';
15
15
  class ManifestParser {
16
16
  collapseAttributes(element) {
17
17
  const collapsed = Object.create(null);
18
- for (const attr of Array.from(element.attributes)){
18
+ const attributes = element.attributes;
19
+ for(let i = 0, len = attributes.length; i < len; i++){
20
+ const attr = attributes[i];
19
21
  collapsed[attr.name] = attr.typedValue.value;
20
22
  }
21
23
  return collapsed;
@@ -1,4 +1,4 @@
1
- export declare const scriptName: "cresc" | "pushy";
1
+ export declare const scriptName: string;
2
2
  export declare const IS_CRESC: boolean;
3
3
  export declare const ppkBundleFileNames: string[];
4
4
  export declare const isPPKBundleFileName: (fileName: string) => boolean;
@@ -43,7 +43,8 @@ function _interop_require_default(obj) {
43
43
  default: obj
44
44
  };
45
45
  }
46
- const scriptName = _path.default.basename(process.argv[1]);
46
+ var _process_argv_;
47
+ const scriptName = process.env.RNU_BRAND === 'cresc' || _path.default.basename((_process_argv_ = process.argv[1]) != null ? _process_argv_ : '') === 'cresc' ? 'cresc' : 'pushy';
47
48
  const IS_CRESC = scriptName === 'cresc';
48
49
  const ppkBundleFileNames = [
49
50
  'index.bundlejs',
@@ -181,6 +181,7 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
181
181
  zipfile.openReadStream(entry, async (err, readStream)=>{
182
182
  if (err) return rej(err);
183
183
  const writeStream = _fsextra.createWriteStream(tempZipPath);
184
+ readStream.on('error', rej);
184
185
  readStream.pipe(writeStream);
185
186
  writeStream.on('finish', ()=>res(void 0));
186
187
  writeStream.on('error', rej);
@@ -197,6 +198,9 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
197
198
  console.error((0, _i18n.t)('processingError', {
198
199
  error
199
200
  }));
201
+ zipfile.close();
202
+ reject(error);
203
+ return;
200
204
  }
201
205
  zipfile.readEntry();
202
206
  });
package/lib/versions.d.ts CHANGED
@@ -19,6 +19,8 @@ interface VersionCommandOptions {
19
19
  warnDepsChanges?: boolean;
20
20
  'no-interactive'?: boolean | string;
21
21
  }
22
+ type Deps = Record<string, string>;
23
+ export declare function normalizeDeps(input: unknown): Deps | undefined;
22
24
  export declare function fetchVersions(appId: string, offset?: number, limit?: number): Promise<Version[]>;
23
25
  export declare const bindVersionToPackages: ({ appId, versionId, pkgs, rollout, dryRun, }: {
24
26
  appId: string;
package/lib/versions.js CHANGED
@@ -15,6 +15,9 @@ _export(exports, {
15
15
  get fetchVersions () {
16
16
  return fetchVersions;
17
17
  },
18
+ get normalizeDeps () {
19
+ return normalizeDeps;
20
+ },
18
21
  get versionCommands () {
19
22
  return versionCommands;
20
23
  }
@@ -295,7 +298,7 @@ async function chooseVersion(appId) {
295
298
  default:
296
299
  {
297
300
  const versionId = Number.parseInt(cmd, 10);
298
- const v = data.find((version)=>version.id === String(versionId));
301
+ const v = data.find((version)=>String(version.id) === String(versionId));
299
302
  if (v) {
300
303
  return v;
301
304
  }
@@ -309,6 +312,7 @@ const bindVersionToPackages = async ({ appId, versionId, pkgs, rollout, dryRun }
309
312
  }
310
313
  if (rollout !== undefined) {
311
314
  console.log(`${(0, _i18n.t)('rolloutConfigSet', {
315
+ version: versionId,
312
316
  versions: pkgs.map((pkg)=>pkg.name).join(', '),
313
317
  rollout: rollout
314
318
  })}`);
@@ -441,6 +445,10 @@ const versionCommands = {
441
445
  appId
442
446
  }));
443
447
  }
448
+ const pkgMap = new Map(allPkgs.map((pkg)=>[
449
+ String(pkg.id),
450
+ pkg
451
+ ]));
444
452
  let pkgsToBind = [];
445
453
  if (minPkgVersion) {
446
454
  minPkgVersion = String(minPkgVersion).trim();
@@ -490,7 +498,7 @@ const versionCommands = {
490
498
  if (!pkgId) {
491
499
  throw new Error((0, _i18n.t)('packageIdRequired'));
492
500
  }
493
- const pkg = allPkgs.find((pkg)=>String(pkg.id) === String(pkgId));
501
+ const pkg = pkgMap.get(String(pkgId));
494
502
  if (pkg) {
495
503
  pkgsToBind = [
496
504
  pkg
@@ -511,7 +519,8 @@ const versionCommands = {
511
519
  }
512
520
  await bindVersionToPackages({
513
521
  appId: String(appId),
514
- versionId: String(versionId),
522
+ // keep null as-is: `--versionId null` means unbinding the version
523
+ versionId: versionId != null ? versionId : null,
515
524
  pkgs: pkgsToBind,
516
525
  rollout,
517
526
  dryRun: options.dryRun
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.15.2",
3
+ "version": "2.15.3",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
7
7
  "bin": {
8
8
  "pushy": "lib/bin.js",
9
- "cresc": "lib/bin.js"
9
+ "cresc": "lib/bin-cresc.js"
10
10
  },
11
11
  "exports": {
12
12
  ".": {
@@ -32,7 +32,7 @@
32
32
  "cli.json"
33
33
  ],
34
34
  "scripts": {
35
- "build": "rm -rf lib && swc src -d lib --strip-leading-paths && bun run typecheck:build && chmod +x lib/bin.js",
35
+ "build": "rm -rf lib && swc src -d lib --strip-leading-paths && bun run typecheck:build && chmod +x lib/bin.js lib/bin-cresc.js",
36
36
  "prepublishOnly": "bun run build",
37
37
  "typecheck": "tsc --noEmit",
38
38
  "typecheck:build": "tsc -p tsconfig.build.json",
@@ -67,7 +67,7 @@
67
67
  "compare-versions": "^6.1.1",
68
68
  "filesize-parser": "^1.5.1",
69
69
  "form-data": "^4.0.5",
70
- "fs-extra": "8",
70
+ "fs-extra": "^11.3.5",
71
71
  "global-dirs": "^4.0.0",
72
72
  "gradle-to-js": "^2.0.1",
73
73
  "i18next": "^26.0.4",
@@ -87,7 +87,7 @@
87
87
  "@xmldom/xmldom": "0.8.13"
88
88
  },
89
89
  "engines": {
90
- "node": ">= 16.6.0"
90
+ "node": ">= 18.17.0"
91
91
  },
92
92
  "devDependencies": {
93
93
  "@biomejs/biome": "^2.4.12",
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Dedicated entry for the `cresc` bin so brand detection does not depend on
4
+ // process.argv[1], which on Windows npm shims always points to the js file
5
+ // instead of the invoked command name.
6
+ process.env.RNU_BRAND = 'cresc';
7
+
8
+ require('./bin');
package/src/bin.ts CHANGED
@@ -83,10 +83,10 @@ async function run() {
83
83
  } catch (err: any) {
84
84
  if (err.status === 401) {
85
85
  console.log(t('loginFirst'));
86
- return;
86
+ process.exit(1);
87
87
  }
88
88
  console.error(err.stack);
89
- process.exit(-1);
89
+ process.exit(1);
90
90
  }
91
91
  }
92
92
 
@@ -596,11 +596,11 @@ export async function copyDebugidForSentry(
596
596
  fs.removeSync(path.join(outputFolder, `${bundleName}.txt.map`));
597
597
  }
598
598
 
599
- export function prepareSentryUploadArtifacts(
599
+ export async function prepareSentryUploadArtifacts(
600
600
  bundleName: string,
601
601
  outputFolder: string,
602
602
  platform: string,
603
- ): SentryUploadArtifacts {
603
+ ): Promise<SentryUploadArtifacts> {
604
604
  const bundlePath = path.join(outputFolder, bundleName);
605
605
  const sourcemapPath = path.join(outputFolder, `${bundleName}.map`);
606
606
 
@@ -616,13 +616,13 @@ export function prepareSentryUploadArtifacts(
616
616
  outputFolder,
617
617
  `${ANDROID_SENTRY_BUNDLE_NAME}.map`,
618
618
  );
619
- fs.copyFileSync(bundlePath, androidBundlePath);
619
+ await fs.promises.copyFile(bundlePath, androidBundlePath);
620
620
 
621
621
  const sourcemap = JSON.parse(
622
- fs.readFileSync(sourcemapPath, 'utf8'),
622
+ await fs.promises.readFile(sourcemapPath, 'utf8'),
623
623
  ) as Record<string, unknown>;
624
624
  sourcemap.file = ANDROID_SENTRY_BUNDLE_NAME;
625
- fs.writeFileSync(androidSourcemapPath, JSON.stringify(sourcemap));
625
+ await fs.promises.writeFile(androidSourcemapPath, JSON.stringify(sourcemap));
626
626
 
627
627
  return {
628
628
  bundlePath: androidBundlePath,
@@ -630,12 +630,12 @@ export function prepareSentryUploadArtifacts(
630
630
  };
631
631
  }
632
632
 
633
- export function readSourcemapDebugId(
633
+ export async function readSourcemapDebugId(
634
634
  sourcemapPath: string,
635
- ): string | undefined {
635
+ ): Promise<string | undefined> {
636
636
  try {
637
637
  const sourcemap = JSON.parse(
638
- fs.readFileSync(sourcemapPath, 'utf8'),
638
+ await fs.promises.readFile(sourcemapPath, 'utf8'),
639
639
  ) as Record<string, unknown>;
640
640
  const debugId = sourcemap.debugId ?? sourcemap.debug_id;
641
641
  return typeof debugId === 'string' ? normalizeString(debugId) : undefined;
@@ -658,10 +658,10 @@ function resolveSentryReleaseFromValues(
658
658
  };
659
659
  }
660
660
 
661
- export function resolveSentryUploadMode(
661
+ export async function resolveSentryUploadMode(
662
662
  sourcemapPath: string,
663
663
  options: SentryUploadOptions = {},
664
- ): SentryUploadMode {
664
+ ): Promise<SentryUploadMode> {
665
665
  const optionRelease = resolveSentryReleaseFromValues(
666
666
  options.sentryRelease,
667
667
  options.sentryDist,
@@ -673,7 +673,7 @@ export function resolveSentryUploadMode(
673
673
  };
674
674
  }
675
675
 
676
- const debugId = readSourcemapDebugId(sourcemapPath);
676
+ const debugId = await readSourcemapDebugId(sourcemapPath);
677
677
  if (debugId) {
678
678
  return {
679
679
  type: 'debug-id',
@@ -848,12 +848,15 @@ export async function uploadSourcemapForSentry(
848
848
  return;
849
849
  }
850
850
 
851
- const { bundlePath, sourcemapPath } = prepareSentryUploadArtifacts(
851
+ const { bundlePath, sourcemapPath } = await prepareSentryUploadArtifacts(
852
852
  bundleName,
853
853
  outputFolder,
854
854
  platform,
855
855
  );
856
- const uploadMode = resolveSentryUploadMode(sourcemapPath, sentryOptions);
856
+ const uploadMode = await resolveSentryUploadMode(
857
+ sourcemapPath,
858
+ sentryOptions,
859
+ );
857
860
  const useStandaloneSourcemapsCommand =
858
861
  supportsStandaloneSentrySourcemapsUpload(sentryCliPath);
859
862
 
package/src/diff.ts CHANGED
@@ -41,7 +41,10 @@ type DiffCommandConfig = {
41
41
  export { enumZipEntries, readEntry };
42
42
 
43
43
  const loadModule = <T>(pkgName: string): T | undefined => {
44
- const resolvePaths = ['.', npm.packages, yarn.packages];
44
+ const nodePathDirs = (process.env.NODE_PATH || '')
45
+ .split(path.delimiter)
46
+ .filter(Boolean);
47
+ const resolvePaths = ['.', ...nodePathDirs, npm.packages, yarn.packages];
45
48
 
46
49
  try {
47
50
  const resolved = require.resolve(pkgName, { paths: resolvePaths });
@@ -179,6 +182,7 @@ async function diffFromPPK(
179
182
  entry.fileName,
180
183
  zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
181
184
  );
185
+ readStream.on('error', reject);
182
186
  readStream.on('end', () => {
183
187
  //console.log('add finished');
184
188
  resolve(void 0);
@@ -315,6 +319,7 @@ async function diffFromPackage(
315
319
  entry.fileName,
316
320
  zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
317
321
  );
322
+ readStream.on('error', reject);
318
323
  readStream.on('end', () => {
319
324
  //console.log('add finished');
320
325
  resolve(void 0);
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
@@ -182,6 +182,9 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
182
182
  nodeHdiffpatchRequired:
183
183
  'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
184
184
  apkExtracted: 'APK extracted to {{output}}',
185
+ installPackageRequired:
186
+ 'Please specify the package to install, e.g. "{{scriptName}} install node-hdiffpatch"',
187
+ installFailed: 'Failed to install {{packages}}: {{error}}',
185
188
  proxyNetworkError:
186
189
  'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
187
190
  proxyNetworkErrorTips:
package/src/locales/zh.ts CHANGED
@@ -168,6 +168,9 @@ export default {
168
168
  nodeHdiffpatchRequired:
169
169
  '此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
170
170
  apkExtracted: 'APK 已提取到 {{output}}',
171
+ installPackageRequired:
172
+ '请指定要安装的包,例如 "{{scriptName}} install node-hdiffpatch"',
173
+ installFailed: '安装 {{packages}} 失败: {{error}}',
171
174
  proxyNetworkError:
172
175
  '网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
173
176
  proxyNetworkErrorTips:
package/src/package.ts CHANGED
@@ -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
  }
@@ -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
  }
@@ -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;
@@ -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'];
@@ -152,6 +152,7 @@ export async function enumZipEntries(
152
152
  zipfile.openReadStream(entry, async (err, readStream) => {
153
153
  if (err) return rej(err);
154
154
  const writeStream = fs.createWriteStream(tempZipPath);
155
+ readStream.on('error', rej);
155
156
  readStream.pipe(writeStream);
156
157
  writeStream.on('finish', () => res(void 0));
157
158
  writeStream.on('error', rej);
@@ -169,6 +170,9 @@ export async function enumZipEntries(
169
170
  }
170
171
  } catch (error) {
171
172
  console.error(t('processingError', { error }));
173
+ zipfile.close();
174
+ reject(error);
175
+ return;
172
176
  }
173
177
 
174
178
  zipfile.readEntry();
package/src/versions.ts CHANGED
@@ -48,7 +48,7 @@ interface DepsChangeSummary {
48
48
  changed: number;
49
49
  }
50
50
 
51
- function normalizeDeps(input: unknown): Deps | undefined {
51
+ export function normalizeDeps(input: unknown): Deps | undefined {
52
52
  if (!input) {
53
53
  return undefined;
54
54
  }
@@ -384,7 +384,7 @@ async function chooseVersion(appId: string) {
384
384
  default: {
385
385
  const versionId = Number.parseInt(cmd, 10);
386
386
  const v = data.find(
387
- (version: Version) => version.id === String(versionId),
387
+ (version: Version) => String(version.id) === String(versionId),
388
388
  );
389
389
  if (v) {
390
390
  return v;
@@ -413,6 +413,7 @@ export const bindVersionToPackages = async ({
413
413
  if (rollout !== undefined) {
414
414
  console.log(
415
415
  `${t('rolloutConfigSet', {
416
+ version: versionId,
416
417
  versions: pkgs.map((pkg: Package) => pkg.name).join(', '),
417
418
  rollout: rollout,
418
419
  })}`,
@@ -588,6 +589,10 @@ export const versionCommands = {
588
589
  throw new Error(t('noPackagesFound', { appId }));
589
590
  }
590
591
 
592
+ const pkgMap = new Map(
593
+ allPkgs.map((pkg: Package) => [String(pkg.id), pkg]),
594
+ );
595
+
591
596
  let pkgsToBind: Package[] = [];
592
597
 
593
598
  if (minPkgVersion) {
@@ -641,9 +646,7 @@ export const versionCommands = {
641
646
  if (!pkgId) {
642
647
  throw new Error(t('packageIdRequired'));
643
648
  }
644
- const pkg = allPkgs.find(
645
- (pkg: Package) => String(pkg.id) === String(pkgId),
646
- );
649
+ const pkg = pkgMap.get(String(pkgId));
647
650
  if (pkg) {
648
651
  pkgsToBind = [pkg];
649
652
  } else {
@@ -662,7 +665,8 @@ export const versionCommands = {
662
665
 
663
666
  await bindVersionToPackages({
664
667
  appId: String(appId),
665
- versionId: String(versionId),
668
+ // keep null as-is: `--versionId null` means unbinding the version
669
+ versionId: versionId ?? null,
666
670
  pkgs: pkgsToBind,
667
671
  rollout,
668
672
  dryRun: options.dryRun,