react-native-update-cli 2.24.1 → 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.
@@ -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);
@@ -15,3 +15,14 @@
15
15
  * original file untouched.
16
16
  */
17
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;
@@ -4,7 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.slimSourceMap = slimSourceMap;
7
+ exports.packSourceMap = packSourceMap;
8
+ exports.unpackSourceMap = unpackSourceMap;
7
9
  const path_1 = __importDefault(require("path"));
10
+ const zlib_1 = __importDefault(require("zlib"));
8
11
  /**
9
12
  * Shrink a source map before archiving it with a version, without losing the
10
13
  * ability to locate any frame:
@@ -68,3 +71,22 @@ function relativizeSource(source, rootPrefix) {
68
71
  function isDependencySource(source) {
69
72
  return (source.startsWith('node_modules/') || source.includes('/node_modules/'));
70
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
@@ -385,19 +385,17 @@ exports.versionCommands = {
385
385
  if (!sourcemapPath) {
386
386
  console.log(chalk_1.default.yellow((0, i18n_1.t)('sourceMapMissingWarning')));
387
387
  }
388
- // Archive a slimmed copy: relative paths, no dependency sourcesContent
389
- // (see slimSourceMap). Frames keep symbolicating everywhere; only inline
390
- // snippets of node_modules code are dropped, and the map shrinks by the
391
- // bulk of its bytes. If the file is not a plain map, upload it untouched.
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.
392
393
  let uploadSourcemapPath = sourcemapPath;
393
- let slimTempDir;
394
+ let packTempDir;
394
395
  if (sourcemapPath) {
395
- const slimmed = (0, slim_sourcemap_1.slimSourceMap)(fs_1.default.readFileSync(sourcemapPath, 'utf8'), process.cwd());
396
- if (slimmed !== null) {
397
- slimTempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-sourcemap-'));
398
- uploadSourcemapPath = path_1.default.join(slimTempDir, path_1.default.basename(sourcemapPath));
399
- fs_1.default.writeFileSync(uploadSourcemapPath, slimmed);
400
- }
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()));
401
399
  }
402
400
  // Hashing/caching the bundle and asking git for the commit are independent
403
401
  // of the upload, so they overlap with it instead of running afterwards.
@@ -418,8 +416,8 @@ exports.versionCommands = {
418
416
  })
419
417
  : Promise.resolve(undefined),
420
418
  ]);
421
- if (slimTempDir) {
422
- fs_1.default.rmSync(slimTempDir, { recursive: true, force: true });
419
+ if (packTempDir) {
420
+ fs_1.default.rmSync(packTempDir, { recursive: true, force: true });
423
421
  }
424
422
  const sourceMapKey = sourceMapUpload?.hash;
425
423
  if (sourcemapPath && !sourceMapKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.24.1",
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",
@@ -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]);
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import zlib from 'zlib';
2
3
 
3
4
  interface SourceMapV3 {
4
5
  sources?: unknown;
@@ -81,3 +82,24 @@ function isDependencySource(source: string): boolean {
81
82
  source.startsWith('node_modules/') || source.includes('/node_modules/')
82
83
  );
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
@@ -20,7 +20,7 @@ import {
20
20
  } from './utils/hermes-base';
21
21
  import { t } from './utils/i18n';
22
22
  import { getBooleanOption, getStringListOption } from './utils/options';
23
- import { slimSourceMap } from './utils/slim-sourcemap';
23
+ import { packSourceMap } from './utils/slim-sourcemap';
24
24
  import {
25
25
  bundleLocationFields,
26
26
  readZipEntryWithLocation,
@@ -546,25 +546,23 @@ export const versionCommands = {
546
546
  if (!sourcemapPath) {
547
547
  console.log(chalk.yellow(t('sourceMapMissingWarning')));
548
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.
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.
553
554
  let uploadSourcemapPath = sourcemapPath;
554
- let slimTempDir: string | undefined;
555
+ let packTempDir: string | undefined;
555
556
  if (sourcemapPath) {
556
- const slimmed = slimSourceMap(
557
- fs.readFileSync(sourcemapPath, 'utf8'),
558
- process.cwd(),
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()),
559
565
  );
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
566
  }
569
567
 
570
568
  // Hashing/caching the bundle and asking git for the commit are independent
@@ -588,8 +586,8 @@ export const versionCommands = {
588
586
  )
589
587
  : Promise.resolve(undefined),
590
588
  ]);
591
- if (slimTempDir) {
592
- fs.rmSync(slimTempDir, { recursive: true, force: true });
589
+ if (packTempDir) {
590
+ fs.rmSync(packTempDir, { recursive: true, force: true });
593
591
  }
594
592
  const sourceMapKey = sourceMapUpload?.hash;
595
593
  if (sourcemapPath && !sourceMapKey) {