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/README.md +17 -0
- package/README.zh-CN.md +8 -0
- package/lib/auto-update.d.ts +30 -0
- package/lib/auto-update.js +502 -0
- package/lib/bin.js +3 -0
- package/lib/bundle-runner.js +14 -4
- package/lib/locales/en.d.ts +2 -0
- package/lib/locales/en.js +2 -0
- package/lib/locales/zh.d.ts +2 -0
- package/lib/locales/zh.js +2 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +33 -1
- 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/auto-update.ts +647 -0
- package/src/bin.ts +3 -0
- package/src/bundle-runner.ts +16 -7
- package/src/locales/en.ts +4 -0
- package/src/locales/zh.ts +3 -0
- package/src/utils/index.ts +39 -1
- package/src/utils/slim-sourcemap.ts +83 -0
- package/src/versions.ts +28 -2
package/lib/utils/index.js
CHANGED
|
@@ -460,6 +460,24 @@ async function printVersionCommand({ wait = true, } = {}) {
|
|
|
460
460
|
}
|
|
461
461
|
const [latestCliVersion, latestRnuVersion] = latest ?? [];
|
|
462
462
|
console.log(`react-native-update-cli: ${package_json_1.default.version}${latestTag(latestCliVersion)}`);
|
|
463
|
+
try {
|
|
464
|
+
const { consumeAutoUpdateNotice } = require('../auto-update');
|
|
465
|
+
const notice = consumeAutoUpdateNotice(package_json_1.default.version);
|
|
466
|
+
if (notice?.kind === 'updated') {
|
|
467
|
+
console.log((0, i18n_1.t)('autoUpdateSuccess', {
|
|
468
|
+
from: notice.currentVersion,
|
|
469
|
+
to: notice.targetVersion,
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
472
|
+
else if (notice?.kind === 'permission') {
|
|
473
|
+
console.warn((0, i18n_1.t)('autoUpdatePermission', {
|
|
474
|
+
command: notice.command,
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
// A corrupt/unwritable updater cache cannot affect normal commands.
|
|
480
|
+
}
|
|
463
481
|
if (rnuVersion) {
|
|
464
482
|
console.log(`react-native-update: ${rnuVersion}${latestTag(latestRnuVersion)}`);
|
|
465
483
|
if (constants_1.IS_CRESC) {
|
|
@@ -506,5 +524,19 @@ async function printVersionCommand({ wait = true, } = {}) {
|
|
|
506
524
|
});
|
|
507
525
|
return Promise.race([check, grace]).then(() => clearTimeout(timer));
|
|
508
526
|
};
|
|
509
|
-
|
|
527
|
+
let autoUpdateStarted = false;
|
|
528
|
+
const startAutoUpdate = () => {
|
|
529
|
+
if (autoUpdateStarted || !isNewer(latest?.[0], package_json_1.default.version)) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
autoUpdateStarted = true;
|
|
533
|
+
try {
|
|
534
|
+
const { launchAutoUpdate } = require('../auto-update');
|
|
535
|
+
launchAutoUpdate(package_json_1.default.version, latest?.[0]);
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
// Self-update is strictly opportunistic and never affects the command.
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
return { done: check, settle, startAutoUpdate, printHints };
|
|
510
542
|
}
|
|
@@ -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