react-native-update-cli 2.24.0 → 2.24.2

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.
@@ -539,12 +539,22 @@ async function compilePlain(hermesCommand, out, input = out) {
539
539
  async function composeSourceMaps(packagerMap, hermesMap, sourcemapOutput) {
540
540
  let composerPath;
541
541
  try {
542
- // resolve through the project so hoisted node_modules (monorepos) work
543
- composerPath = require.resolve('react-native/scripts/compose-source-maps.js', { paths: [process.cwd()] });
542
+ // resolve through the project so hoisted node_modules (monorepos) work.
543
+ // Extensionless first: RN >= 0.87 maps "./scripts/*" to "./scripts/*.js"
544
+ // in its exports, so the ".js" specifier resolves to ".js.js" and
545
+ // fails; CJS resolution adds the extension itself on older RN.
546
+ composerPath = require.resolve('react-native/scripts/compose-source-maps', {
547
+ paths: [process.cwd()],
548
+ });
544
549
  }
545
550
  catch {
546
- console.warn((0, i18n_1.t)('composeSourceMapsNotFound'));
547
- return false;
551
+ try {
552
+ composerPath = require.resolve('react-native/scripts/compose-source-maps.js', { paths: [process.cwd()] });
553
+ }
554
+ catch {
555
+ console.warn((0, i18n_1.t)('composeSourceMapsNotFound'));
556
+ return false;
557
+ }
548
558
  }
549
559
  console.log((0, i18n_1.t)('composingSourceMap'));
550
560
  assertSuccessfulSyncProcess(await runProcess((0, runtime_1.getJavaScriptRuntime)(), [composerPath, packagerMap, hermesMap, '-o', sourcemapOutput], false), composerPath);
@@ -11,6 +11,7 @@ const source_map_1 = require("source-map");
11
11
  const api_1 = require("./api");
12
12
  const app_1 = require("./app");
13
13
  const i18n_1 = require("./utils/i18n");
14
+ const slim_sourcemap_1 = require("./utils/slim-sourcemap");
14
15
  const versions_1 = require("./versions");
15
16
  // A frame location inside a shipped bundle: `<bundle>:<line>:<column>`. Covers
16
17
  // `index.bundlejs`, `index.android.bundle`, `main.jsbundle`, `bundle.harmony.js`
@@ -97,7 +98,9 @@ exports.symbolicateCommands = {
97
98
  if (!response.ok) {
98
99
  throw new Error(`Failed to download source map: HTTP ${response.status}`);
99
100
  }
100
- const rawMap = JSON.parse(await response.text());
101
+ // Maps archived by recent CLI versions are gzipped; older ones are plain
102
+ // JSON, and unpackSourceMap accepts both.
103
+ const rawMap = JSON.parse((0, slim_sourcemap_1.unpackSourceMap)(Buffer.from(await response.arrayBuffer())));
101
104
  const consumer = new source_map_1.SourceMapConsumer(rawMap);
102
105
  const stack = await readStack(args[0]);
103
106
  const { text, mapped } = symbolicateStack(stack, consumer);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Shrink a source map before archiving it with a version, without losing the
3
+ * ability to locate any frame:
4
+ *
5
+ * - absolute source paths under the project root become relative (build
6
+ * machine paths do not belong in an uploaded artifact);
7
+ * - `sourcesContent` of node_modules sources is dropped. Mappings and the
8
+ * source paths stay, so frames inside dependencies still symbolicate to
9
+ * `node_modules/...:line:column` — only the inline code snippet for those
10
+ * frames is lost, and dependency sources are recoverable from the lockfile
11
+ * anyway. On an RN app this is the bulk of the map's bytes.
12
+ *
13
+ * Returns null when the content is not a usable plain source map (invalid
14
+ * JSON, or an indexed map with `sections`); the caller then uploads the
15
+ * original file untouched.
16
+ */
17
+ export declare function slimSourceMap(content: string, projectRoot: string): string | null;
18
+ /**
19
+ * Build the bytes actually archived with a version: the slimmed map (when it
20
+ * is a plain map we understand), gzipped. Source maps are JSON and compress
21
+ * about 5x, which is the difference between a multi-megabyte upload on every
22
+ * publish and a small one. Readers detect the gzip magic bytes rather than
23
+ * trusting a file name, so plain maps archived by older CLI versions keep
24
+ * working unchanged.
25
+ */
26
+ export declare function packSourceMap(content: string, projectRoot: string): Buffer;
27
+ /** Decode an archived source map: gzip when the magic bytes say so. */
28
+ export declare function unpackSourceMap(data: Buffer): string;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.slimSourceMap = slimSourceMap;
7
+ exports.packSourceMap = packSourceMap;
8
+ exports.unpackSourceMap = unpackSourceMap;
9
+ const path_1 = __importDefault(require("path"));
10
+ const zlib_1 = __importDefault(require("zlib"));
11
+ /**
12
+ * Shrink a source map before archiving it with a version, without losing the
13
+ * ability to locate any frame:
14
+ *
15
+ * - absolute source paths under the project root become relative (build
16
+ * machine paths do not belong in an uploaded artifact);
17
+ * - `sourcesContent` of node_modules sources is dropped. Mappings and the
18
+ * source paths stay, so frames inside dependencies still symbolicate to
19
+ * `node_modules/...:line:column` — only the inline code snippet for those
20
+ * frames is lost, and dependency sources are recoverable from the lockfile
21
+ * anyway. On an RN app this is the bulk of the map's bytes.
22
+ *
23
+ * Returns null when the content is not a usable plain source map (invalid
24
+ * JSON, or an indexed map with `sections`); the caller then uploads the
25
+ * original file untouched.
26
+ */
27
+ function slimSourceMap(content, projectRoot) {
28
+ let map;
29
+ try {
30
+ map = JSON.parse(content);
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ if (!map || typeof map !== 'object' || Array.isArray(map)) {
36
+ return null;
37
+ }
38
+ if (map.sections !== undefined) {
39
+ return null;
40
+ }
41
+ if (!Array.isArray(map.sources)) {
42
+ return null;
43
+ }
44
+ const rootPrefix = normalizeSlashes(path_1.default.resolve(projectRoot));
45
+ const sources = map.sources.map((source) => typeof source === 'string' ? relativizeSource(source, rootPrefix) : source);
46
+ map.sources = sources;
47
+ if (Array.isArray(map.sourcesContent)) {
48
+ map.sourcesContent = map.sourcesContent.map((item, index) => {
49
+ const source = sources[index];
50
+ if (typeof source === 'string' && isDependencySource(source)) {
51
+ return null;
52
+ }
53
+ return item;
54
+ });
55
+ }
56
+ return JSON.stringify(map);
57
+ }
58
+ function normalizeSlashes(value) {
59
+ return value.replace(/\\/g, '/');
60
+ }
61
+ function relativizeSource(source, rootPrefix) {
62
+ const normalized = normalizeSlashes(source);
63
+ if (normalized === rootPrefix) {
64
+ return '';
65
+ }
66
+ if (normalized.startsWith(`${rootPrefix}/`)) {
67
+ return normalized.slice(rootPrefix.length + 1);
68
+ }
69
+ return normalized;
70
+ }
71
+ function isDependencySource(source) {
72
+ return (source.startsWith('node_modules/') || source.includes('/node_modules/'));
73
+ }
74
+ /**
75
+ * Build the bytes actually archived with a version: the slimmed map (when it
76
+ * is a plain map we understand), gzipped. Source maps are JSON and compress
77
+ * about 5x, which is the difference between a multi-megabyte upload on every
78
+ * publish and a small one. Readers detect the gzip magic bytes rather than
79
+ * trusting a file name, so plain maps archived by older CLI versions keep
80
+ * working unchanged.
81
+ */
82
+ function packSourceMap(content, projectRoot) {
83
+ const slimmed = slimSourceMap(content, projectRoot);
84
+ return zlib_1.default.gzipSync(Buffer.from(slimmed ?? content, 'utf8'));
85
+ }
86
+ /** Decode an archived source map: gzip when the magic bytes say so. */
87
+ function unpackSourceMap(data) {
88
+ if (data.length >= 2 && data[0] === 0x1f && data[1] === 0x8b) {
89
+ return zlib_1.default.gunzipSync(data).toString('utf8');
90
+ }
91
+ return data.toString('utf8');
92
+ }
package/lib/versions.js CHANGED
@@ -9,6 +9,8 @@ exports.fetchVersions = fetchVersions;
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
10
  const compare_versions_1 = require("compare-versions");
11
11
  const fs_1 = __importDefault(require("fs"));
12
+ const os_1 = __importDefault(require("os"));
13
+ const path_1 = __importDefault(require("path"));
12
14
  const api_1 = require("./api");
13
15
  const app_1 = require("./app");
14
16
  const package_1 = require("./package");
@@ -19,6 +21,7 @@ const hbcTransform_1 = require("./utils/hbcTransform");
19
21
  const hermes_base_1 = require("./utils/hermes-base");
20
22
  const i18n_1 = require("./utils/i18n");
21
23
  const options_1 = require("./utils/options");
24
+ const slim_sourcemap_1 = require("./utils/slim-sourcemap");
22
25
  const zip_range_1 = require("./utils/zip-range");
23
26
  function normalizeDeps(input) {
24
27
  if (!input) {
@@ -382,6 +385,18 @@ exports.versionCommands = {
382
385
  if (!sourcemapPath) {
383
386
  console.log(chalk_1.default.yellow((0, i18n_1.t)('sourceMapMissingWarning')));
384
387
  }
388
+ // Archive a slimmed, gzipped copy (see packSourceMap): relative paths, no
389
+ // dependency sourcesContent, ~5x smaller on the wire. Frames keep
390
+ // symbolicating everywhere; only inline snippets of node_modules code are
391
+ // dropped. The temp file keeps the .map extension because /upload routes
392
+ // by extension; readers detect gzip by magic bytes.
393
+ let uploadSourcemapPath = sourcemapPath;
394
+ let packTempDir;
395
+ if (sourcemapPath) {
396
+ packTempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-sourcemap-'));
397
+ uploadSourcemapPath = path_1.default.join(packTempDir, path_1.default.basename(sourcemapPath));
398
+ fs_1.default.writeFileSync(uploadSourcemapPath, (0, slim_sourcemap_1.packSourceMap)(fs_1.default.readFileSync(sourcemapPath, 'utf8'), process.cwd()));
399
+ }
385
400
  // Hashing/caching the bundle and asking git for the commit are independent
386
401
  // of the upload, so they overlap with it instead of running afterwards.
387
402
  // describePpkBundle never rejects (best effort); a failed upload still
@@ -394,13 +409,16 @@ exports.versionCommands = {
394
409
  (0, api_1.uploadFile)(fn, undefined, appId),
395
410
  describePpkBundle(fn, options.hermesBase),
396
411
  (0, git_1.getCommitInfo)(),
397
- sourcemapPath
398
- ? (0, api_1.uploadFile)(sourcemapPath, undefined, appId).catch((error) => {
412
+ uploadSourcemapPath
413
+ ? (0, api_1.uploadFile)(uploadSourcemapPath, undefined, appId).catch((error) => {
399
414
  sourceMapUploadError = error;
400
415
  return undefined;
401
416
  })
402
417
  : Promise.resolve(undefined),
403
418
  ]);
419
+ if (packTempDir) {
420
+ fs_1.default.rmSync(packTempDir, { recursive: true, force: true });
421
+ }
404
422
  const sourceMapKey = sourceMapUpload?.hash;
405
423
  if (sourcemapPath && !sourceMapKey) {
406
424
  console.log(chalk_1.default.yellow((0, i18n_1.t)('sourceMapUploadFailedWarning', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.24.0",
3
+ "version": "2.24.2",
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",
@@ -766,14 +766,23 @@ async function composeSourceMaps(
766
766
  ): Promise<boolean> {
767
767
  let composerPath: string;
768
768
  try {
769
- // resolve through the project so hoisted node_modules (monorepos) work
770
- composerPath = require.resolve(
771
- 'react-native/scripts/compose-source-maps.js',
772
- { paths: [process.cwd()] },
773
- );
769
+ // resolve through the project so hoisted node_modules (monorepos) work.
770
+ // Extensionless first: RN >= 0.87 maps "./scripts/*" to "./scripts/*.js"
771
+ // in its exports, so the ".js" specifier resolves to ".js.js" and
772
+ // fails; CJS resolution adds the extension itself on older RN.
773
+ composerPath = require.resolve('react-native/scripts/compose-source-maps', {
774
+ paths: [process.cwd()],
775
+ });
774
776
  } catch {
775
- console.warn(t('composeSourceMapsNotFound'));
776
- return false;
777
+ try {
778
+ composerPath = require.resolve(
779
+ 'react-native/scripts/compose-source-maps.js',
780
+ { paths: [process.cwd()] },
781
+ );
782
+ } catch {
783
+ console.warn(t('composeSourceMapsNotFound'));
784
+ return false;
785
+ }
777
786
  }
778
787
  console.log(t('composingSourceMap'));
779
788
  assertSuccessfulSyncProcess(
@@ -5,6 +5,7 @@ import { get } from './api';
5
5
  import { getPlatform, getSelectedApp } from './app';
6
6
  import type { Platform, Version } from './types';
7
7
  import { t } from './utils/i18n';
8
+ import { unpackSourceMap } from './utils/slim-sourcemap';
8
9
  import { fetchVersions } from './versions';
9
10
 
10
11
  // A frame location inside a shipped bundle: `<bundle>:<line>:<column>`. Covers
@@ -137,7 +138,11 @@ export const symbolicateCommands = {
137
138
  if (!response.ok) {
138
139
  throw new Error(`Failed to download source map: HTTP ${response.status}`);
139
140
  }
140
- const rawMap = JSON.parse(await response.text());
141
+ // Maps archived by recent CLI versions are gzipped; older ones are plain
142
+ // JSON, and unpackSourceMap accepts both.
143
+ const rawMap = JSON.parse(
144
+ unpackSourceMap(Buffer.from(await response.arrayBuffer())),
145
+ );
141
146
  const consumer = new SourceMapConsumer(rawMap);
142
147
 
143
148
  const stack = await readStack(args[0]);
@@ -0,0 +1,105 @@
1
+ import path from 'path';
2
+ import zlib from 'zlib';
3
+
4
+ interface SourceMapV3 {
5
+ sources?: unknown;
6
+ sourcesContent?: unknown;
7
+ sections?: unknown;
8
+ [key: string]: unknown;
9
+ }
10
+
11
+ /**
12
+ * Shrink a source map before archiving it with a version, without losing the
13
+ * ability to locate any frame:
14
+ *
15
+ * - absolute source paths under the project root become relative (build
16
+ * machine paths do not belong in an uploaded artifact);
17
+ * - `sourcesContent` of node_modules sources is dropped. Mappings and the
18
+ * source paths stay, so frames inside dependencies still symbolicate to
19
+ * `node_modules/...:line:column` — only the inline code snippet for those
20
+ * frames is lost, and dependency sources are recoverable from the lockfile
21
+ * anyway. On an RN app this is the bulk of the map's bytes.
22
+ *
23
+ * Returns null when the content is not a usable plain source map (invalid
24
+ * JSON, or an indexed map with `sections`); the caller then uploads the
25
+ * original file untouched.
26
+ */
27
+ export function slimSourceMap(
28
+ content: string,
29
+ projectRoot: string,
30
+ ): string | null {
31
+ let map: SourceMapV3;
32
+ try {
33
+ map = JSON.parse(content) as SourceMapV3;
34
+ } catch {
35
+ return null;
36
+ }
37
+ if (!map || typeof map !== 'object' || Array.isArray(map)) {
38
+ return null;
39
+ }
40
+ if (map.sections !== undefined) {
41
+ return null;
42
+ }
43
+ if (!Array.isArray(map.sources)) {
44
+ return null;
45
+ }
46
+ const rootPrefix = normalizeSlashes(path.resolve(projectRoot));
47
+ const sources = (map.sources as unknown[]).map((source) =>
48
+ typeof source === 'string' ? relativizeSource(source, rootPrefix) : source,
49
+ );
50
+ map.sources = sources;
51
+ if (Array.isArray(map.sourcesContent)) {
52
+ map.sourcesContent = (map.sourcesContent as unknown[]).map(
53
+ (item, index) => {
54
+ const source = sources[index];
55
+ if (typeof source === 'string' && isDependencySource(source)) {
56
+ return null;
57
+ }
58
+ return item;
59
+ },
60
+ );
61
+ }
62
+ return JSON.stringify(map);
63
+ }
64
+
65
+ function normalizeSlashes(value: string): string {
66
+ return value.replace(/\\/g, '/');
67
+ }
68
+
69
+ function relativizeSource(source: string, rootPrefix: string): string {
70
+ const normalized = normalizeSlashes(source);
71
+ if (normalized === rootPrefix) {
72
+ return '';
73
+ }
74
+ if (normalized.startsWith(`${rootPrefix}/`)) {
75
+ return normalized.slice(rootPrefix.length + 1);
76
+ }
77
+ return normalized;
78
+ }
79
+
80
+ function isDependencySource(source: string): boolean {
81
+ return (
82
+ source.startsWith('node_modules/') || source.includes('/node_modules/')
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Build the bytes actually archived with a version: the slimmed map (when it
88
+ * is a plain map we understand), gzipped. Source maps are JSON and compress
89
+ * about 5x, which is the difference between a multi-megabyte upload on every
90
+ * publish and a small one. Readers detect the gzip magic bytes rather than
91
+ * trusting a file name, so plain maps archived by older CLI versions keep
92
+ * working unchanged.
93
+ */
94
+ export function packSourceMap(content: string, projectRoot: string): Buffer {
95
+ const slimmed = slimSourceMap(content, projectRoot);
96
+ return zlib.gzipSync(Buffer.from(slimmed ?? content, 'utf8'));
97
+ }
98
+
99
+ /** Decode an archived source map: gzip when the magic bytes say so. */
100
+ export function unpackSourceMap(data: Buffer): string {
101
+ if (data.length >= 2 && data[0] === 0x1f && data[1] === 0x8b) {
102
+ return zlib.gunzipSync(data).toString('utf8');
103
+ }
104
+ return data.toString('utf8');
105
+ }
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 { packSourceMap } from './utils/slim-sourcemap';
21
24
  import {
22
25
  bundleLocationFields,
23
26
  readZipEntryWithLocation,
@@ -543,6 +546,24 @@ export const versionCommands = {
543
546
  if (!sourcemapPath) {
544
547
  console.log(chalk.yellow(t('sourceMapMissingWarning')));
545
548
  }
549
+ // Archive a slimmed, gzipped copy (see packSourceMap): relative paths, no
550
+ // dependency sourcesContent, ~5x smaller on the wire. Frames keep
551
+ // symbolicating everywhere; only inline snippets of node_modules code are
552
+ // dropped. The temp file keeps the .map extension because /upload routes
553
+ // by extension; readers detect gzip by magic bytes.
554
+ let uploadSourcemapPath = sourcemapPath;
555
+ let packTempDir: string | undefined;
556
+ if (sourcemapPath) {
557
+ packTempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-sourcemap-'));
558
+ uploadSourcemapPath = path.join(
559
+ packTempDir,
560
+ path.basename(sourcemapPath),
561
+ );
562
+ fs.writeFileSync(
563
+ uploadSourcemapPath,
564
+ packSourceMap(fs.readFileSync(sourcemapPath, 'utf8'), process.cwd()),
565
+ );
566
+ }
546
567
 
547
568
  // Hashing/caching the bundle and asking git for the commit are independent
548
569
  // of the upload, so they overlap with it instead of running afterwards.
@@ -556,8 +577,8 @@ export const versionCommands = {
556
577
  uploadFile(fn, undefined, appId),
557
578
  describePpkBundle(fn, options.hermesBase),
558
579
  getCommitInfo(),
559
- sourcemapPath
560
- ? uploadFile(sourcemapPath, undefined, appId).catch(
580
+ uploadSourcemapPath
581
+ ? uploadFile(uploadSourcemapPath, undefined, appId).catch(
561
582
  (error: unknown) => {
562
583
  sourceMapUploadError = error;
563
584
  return undefined;
@@ -565,6 +586,9 @@ export const versionCommands = {
565
586
  )
566
587
  : Promise.resolve(undefined),
567
588
  ]);
589
+ if (packTempDir) {
590
+ fs.rmSync(packTempDir, { recursive: true, force: true });
591
+ }
568
592
  const sourceMapKey = sourceMapUpload?.hash;
569
593
  if (sourcemapPath && !sourceMapKey) {
570
594
  console.log(