react-native-update-cli 2.24.0 → 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/lib/bundle-runner.js +14 -4
- package/lib/utils/slim-sourcemap.d.ts +17 -0
- package/lib/utils/slim-sourcemap.js +70 -0
- package/lib/versions.js +22 -2
- package/package.json +1 -1
- package/src/bundle-runner.ts +16 -7
- package/src/utils/slim-sourcemap.ts +83 -0
- package/src/versions.ts +28 -2
package/lib/bundle-runner.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
547
|
-
|
|
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);
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
/**
|
|
9
|
+
* Shrink a source map before archiving it with a version, without losing the
|
|
10
|
+
* ability to locate any frame:
|
|
11
|
+
*
|
|
12
|
+
* - absolute source paths under the project root become relative (build
|
|
13
|
+
* machine paths do not belong in an uploaded artifact);
|
|
14
|
+
* - `sourcesContent` of node_modules sources is dropped. Mappings and the
|
|
15
|
+
* source paths stay, so frames inside dependencies still symbolicate to
|
|
16
|
+
* `node_modules/...:line:column` — only the inline code snippet for those
|
|
17
|
+
* frames is lost, and dependency sources are recoverable from the lockfile
|
|
18
|
+
* anyway. On an RN app this is the bulk of the map's bytes.
|
|
19
|
+
*
|
|
20
|
+
* Returns null when the content is not a usable plain source map (invalid
|
|
21
|
+
* JSON, or an indexed map with `sections`); the caller then uploads the
|
|
22
|
+
* original file untouched.
|
|
23
|
+
*/
|
|
24
|
+
function slimSourceMap(content, projectRoot) {
|
|
25
|
+
let map;
|
|
26
|
+
try {
|
|
27
|
+
map = JSON.parse(content);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (map.sections !== undefined) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (!Array.isArray(map.sources)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const rootPrefix = normalizeSlashes(path_1.default.resolve(projectRoot));
|
|
42
|
+
const sources = map.sources.map((source) => typeof source === 'string' ? relativizeSource(source, rootPrefix) : source);
|
|
43
|
+
map.sources = sources;
|
|
44
|
+
if (Array.isArray(map.sourcesContent)) {
|
|
45
|
+
map.sourcesContent = map.sourcesContent.map((item, index) => {
|
|
46
|
+
const source = sources[index];
|
|
47
|
+
if (typeof source === 'string' && isDependencySource(source)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return item;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return JSON.stringify(map);
|
|
54
|
+
}
|
|
55
|
+
function normalizeSlashes(value) {
|
|
56
|
+
return value.replace(/\\/g, '/');
|
|
57
|
+
}
|
|
58
|
+
function relativizeSource(source, rootPrefix) {
|
|
59
|
+
const normalized = normalizeSlashes(source);
|
|
60
|
+
if (normalized === rootPrefix) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
if (normalized.startsWith(`${rootPrefix}/`)) {
|
|
64
|
+
return normalized.slice(rootPrefix.length + 1);
|
|
65
|
+
}
|
|
66
|
+
return normalized;
|
|
67
|
+
}
|
|
68
|
+
function isDependencySource(source) {
|
|
69
|
+
return (source.startsWith('node_modules/') || source.includes('/node_modules/'));
|
|
70
|
+
}
|
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,20 @@ 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 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.
|
|
392
|
+
let uploadSourcemapPath = sourcemapPath;
|
|
393
|
+
let slimTempDir;
|
|
394
|
+
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
|
+
}
|
|
401
|
+
}
|
|
385
402
|
// Hashing/caching the bundle and asking git for the commit are independent
|
|
386
403
|
// of the upload, so they overlap with it instead of running afterwards.
|
|
387
404
|
// describePpkBundle never rejects (best effort); a failed upload still
|
|
@@ -394,13 +411,16 @@ exports.versionCommands = {
|
|
|
394
411
|
(0, api_1.uploadFile)(fn, undefined, appId),
|
|
395
412
|
describePpkBundle(fn, options.hermesBase),
|
|
396
413
|
(0, git_1.getCommitInfo)(),
|
|
397
|
-
|
|
398
|
-
? (0, api_1.uploadFile)(
|
|
414
|
+
uploadSourcemapPath
|
|
415
|
+
? (0, api_1.uploadFile)(uploadSourcemapPath, undefined, appId).catch((error) => {
|
|
399
416
|
sourceMapUploadError = error;
|
|
400
417
|
return undefined;
|
|
401
418
|
})
|
|
402
419
|
: Promise.resolve(undefined),
|
|
403
420
|
]);
|
|
421
|
+
if (slimTempDir) {
|
|
422
|
+
fs_1.default.rmSync(slimTempDir, { recursive: true, force: true });
|
|
423
|
+
}
|
|
404
424
|
const sourceMapKey = sourceMapUpload?.hash;
|
|
405
425
|
if (sourcemapPath && !sourceMapKey) {
|
|
406
426
|
console.log(chalk_1.default.yellow((0, i18n_1.t)('sourceMapUploadFailedWarning', {
|
package/package.json
CHANGED
package/src/bundle-runner.ts
CHANGED
|
@@ -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
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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
|
-
|
|
776
|
-
|
|
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(
|
|
@@ -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
|
-
|
|
560
|
-
? uploadFile(
|
|
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(
|