react-native-update-cli 2.23.1 → 2.24.1

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/src/locales/zh.ts CHANGED
@@ -33,6 +33,9 @@ export default {
33
33
  '尚未选择应用。请先运行 `pushy selectApp --platform {{platform}}` 来选择应用',
34
34
  appUploadSuccess:
35
35
  '已成功上传app原生包(id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
36
+ autoUpdatePermission:
37
+ 'CLI 自动更新已跳过:全局包目录不可写。请修复包管理器的全局目录权限后运行:{{- command}}',
38
+ autoUpdateSuccess: 'CLI 已在后台自动更新:{{from}} -> {{to}}',
36
39
  apkUploadSuccess:
37
40
  '已成功上传apk原生包(id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
38
41
  boundTo: ', 已绑定:{{name}} ({{id}})',
@@ -560,6 +560,8 @@ export interface VersionCheck {
560
560
  done: Promise<void>;
561
561
  /** wait for the check, but never longer than `graceMs` */
562
562
  settle: (graceMs: number) => Promise<void>;
563
+ /** launch a detached self-update after the foreground command is done */
564
+ startAutoUpdate: () => void;
563
565
  /**
564
566
  * Print the "newer version available" hints if the check has completed by
565
567
  * now; a no-op while it is still pending, when nothing is newer, and after
@@ -597,6 +599,27 @@ export async function printVersionCommand({
597
599
  console.log(
598
600
  `react-native-update-cli: ${pkg.version}${latestTag(latestCliVersion)}`,
599
601
  );
602
+ try {
603
+ const { consumeAutoUpdateNotice } =
604
+ require('../auto-update') as typeof import('../auto-update');
605
+ const notice = consumeAutoUpdateNotice(pkg.version);
606
+ if (notice?.kind === 'updated') {
607
+ console.log(
608
+ t('autoUpdateSuccess', {
609
+ from: notice.currentVersion,
610
+ to: notice.targetVersion,
611
+ }),
612
+ );
613
+ } else if (notice?.kind === 'permission') {
614
+ console.warn(
615
+ t('autoUpdatePermission', {
616
+ command: notice.command,
617
+ }),
618
+ );
619
+ }
620
+ } catch {
621
+ // A corrupt/unwritable updater cache cannot affect normal commands.
622
+ }
600
623
  if (rnuVersion) {
601
624
  console.log(
602
625
  `react-native-update: ${rnuVersion}${latestTag(latestRnuVersion)}`,
@@ -654,7 +677,22 @@ export async function printVersionCommand({
654
677
  return Promise.race([check, grace]).then(() => clearTimeout(timer));
655
678
  };
656
679
 
657
- return { done: check, settle, printHints };
680
+ let autoUpdateStarted = false;
681
+ const startAutoUpdate = () => {
682
+ if (autoUpdateStarted || !isNewer(latest?.[0], pkg.version)) {
683
+ return;
684
+ }
685
+ autoUpdateStarted = true;
686
+ try {
687
+ const { launchAutoUpdate } =
688
+ require('../auto-update') as typeof import('../auto-update');
689
+ launchAutoUpdate(pkg.version, latest?.[0]);
690
+ } catch {
691
+ // Self-update is strictly opportunistic and never affects the command.
692
+ }
693
+ };
694
+
695
+ return { done: check, settle, startAutoUpdate, printHints };
658
696
  }
659
697
 
660
698
  export { checkPlugins };
@@ -0,0 +1,83 @@
1
+ import path from 'path';
2
+
3
+ interface SourceMapV3 {
4
+ sources?: unknown;
5
+ sourcesContent?: unknown;
6
+ sections?: unknown;
7
+ [key: string]: unknown;
8
+ }
9
+
10
+ /**
11
+ * Shrink a source map before archiving it with a version, without losing the
12
+ * ability to locate any frame:
13
+ *
14
+ * - absolute source paths under the project root become relative (build
15
+ * machine paths do not belong in an uploaded artifact);
16
+ * - `sourcesContent` of node_modules sources is dropped. Mappings and the
17
+ * source paths stay, so frames inside dependencies still symbolicate to
18
+ * `node_modules/...:line:column` — only the inline code snippet for those
19
+ * frames is lost, and dependency sources are recoverable from the lockfile
20
+ * anyway. On an RN app this is the bulk of the map's bytes.
21
+ *
22
+ * Returns null when the content is not a usable plain source map (invalid
23
+ * JSON, or an indexed map with `sections`); the caller then uploads the
24
+ * original file untouched.
25
+ */
26
+ export function slimSourceMap(
27
+ content: string,
28
+ projectRoot: string,
29
+ ): string | null {
30
+ let map: SourceMapV3;
31
+ try {
32
+ map = JSON.parse(content) as SourceMapV3;
33
+ } catch {
34
+ return null;
35
+ }
36
+ if (!map || typeof map !== 'object' || Array.isArray(map)) {
37
+ return null;
38
+ }
39
+ if (map.sections !== undefined) {
40
+ return null;
41
+ }
42
+ if (!Array.isArray(map.sources)) {
43
+ return null;
44
+ }
45
+ const rootPrefix = normalizeSlashes(path.resolve(projectRoot));
46
+ const sources = (map.sources as unknown[]).map((source) =>
47
+ typeof source === 'string' ? relativizeSource(source, rootPrefix) : source,
48
+ );
49
+ map.sources = sources;
50
+ if (Array.isArray(map.sourcesContent)) {
51
+ map.sourcesContent = (map.sourcesContent as unknown[]).map(
52
+ (item, index) => {
53
+ const source = sources[index];
54
+ if (typeof source === 'string' && isDependencySource(source)) {
55
+ return null;
56
+ }
57
+ return item;
58
+ },
59
+ );
60
+ }
61
+ return JSON.stringify(map);
62
+ }
63
+
64
+ function normalizeSlashes(value: string): string {
65
+ return value.replace(/\\/g, '/');
66
+ }
67
+
68
+ function relativizeSource(source: string, rootPrefix: string): string {
69
+ const normalized = normalizeSlashes(source);
70
+ if (normalized === rootPrefix) {
71
+ return '';
72
+ }
73
+ if (normalized.startsWith(`${rootPrefix}/`)) {
74
+ return normalized.slice(rootPrefix.length + 1);
75
+ }
76
+ return normalized;
77
+ }
78
+
79
+ function isDependencySource(source: string): boolean {
80
+ return (
81
+ source.startsWith('node_modules/') || source.includes('/node_modules/')
82
+ );
83
+ }
package/src/versions.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import { compare, satisfies } from 'compare-versions';
3
3
  import fs from 'fs';
4
+ import os from 'os';
5
+ import path from 'path';
4
6
  import { doDelete, get, getAllPackages, post, put, uploadFile } from './api';
5
7
  import { getPlatform, resolveAppId } from './app';
6
8
  import { choosePackage } from './package';
@@ -18,6 +20,7 @@ import {
18
20
  } from './utils/hermes-base';
19
21
  import { t } from './utils/i18n';
20
22
  import { getBooleanOption, getStringListOption } from './utils/options';
23
+ import { slimSourceMap } from './utils/slim-sourcemap';
21
24
  import {
22
25
  bundleLocationFields,
23
26
  readZipEntryWithLocation,
@@ -543,6 +546,26 @@ export const versionCommands = {
543
546
  if (!sourcemapPath) {
544
547
  console.log(chalk.yellow(t('sourceMapMissingWarning')));
545
548
  }
549
+ // Archive a slimmed copy: relative paths, no dependency sourcesContent
550
+ // (see slimSourceMap). Frames keep symbolicating everywhere; only inline
551
+ // snippets of node_modules code are dropped, and the map shrinks by the
552
+ // bulk of its bytes. If the file is not a plain map, upload it untouched.
553
+ let uploadSourcemapPath = sourcemapPath;
554
+ let slimTempDir: string | undefined;
555
+ if (sourcemapPath) {
556
+ const slimmed = slimSourceMap(
557
+ fs.readFileSync(sourcemapPath, 'utf8'),
558
+ process.cwd(),
559
+ );
560
+ if (slimmed !== null) {
561
+ slimTempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-sourcemap-'));
562
+ uploadSourcemapPath = path.join(
563
+ slimTempDir,
564
+ path.basename(sourcemapPath),
565
+ );
566
+ fs.writeFileSync(uploadSourcemapPath, slimmed);
567
+ }
568
+ }
546
569
 
547
570
  // Hashing/caching the bundle and asking git for the commit are independent
548
571
  // of the upload, so they overlap with it instead of running afterwards.
@@ -556,8 +579,8 @@ export const versionCommands = {
556
579
  uploadFile(fn, undefined, appId),
557
580
  describePpkBundle(fn, options.hermesBase),
558
581
  getCommitInfo(),
559
- sourcemapPath
560
- ? uploadFile(sourcemapPath, undefined, appId).catch(
582
+ uploadSourcemapPath
583
+ ? uploadFile(uploadSourcemapPath, undefined, appId).catch(
561
584
  (error: unknown) => {
562
585
  sourceMapUploadError = error;
563
586
  return undefined;
@@ -565,6 +588,9 @@ export const versionCommands = {
565
588
  )
566
589
  : Promise.resolve(undefined),
567
590
  ]);
591
+ if (slimTempDir) {
592
+ fs.rmSync(slimTempDir, { recursive: true, force: true });
593
+ }
568
594
  const sourceMapKey = sourceMapUpload?.hash;
569
595
  if (sourcemapPath && !sourceMapKey) {
570
596
  console.log(