react-native-update-cli 2.29.0 → 2.29.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.
- package/lib/account.js +2 -4
- package/lib/api.d.ts +1 -1
- package/lib/api.js +35 -73
- package/lib/app.js +13 -27
- package/lib/auto-update.d.ts +1 -1
- package/lib/auto-update.js +6 -16
- package/lib/bin.js +4 -6
- package/lib/bundle-pack.js +26 -60
- package/lib/bundle-runner.js +89 -119
- package/lib/bundle.js +18 -26
- package/lib/diff.js +43 -133
- package/lib/locales/en.d.ts +0 -10
- package/lib/locales/en.js +0 -10
- package/lib/locales/zh.d.ts +0 -10
- package/lib/locales/zh.js +0 -10
- package/lib/native-package.js +27 -99
- package/lib/package.d.ts +6 -1
- package/lib/package.js +56 -108
- package/lib/provider.js +3 -5
- package/lib/symbolicate.js +1 -16
- package/lib/utils/add-gitignore.js +0 -1
- package/lib/utils/app-info-parser/aab.d.ts +5 -22
- package/lib/utils/app-info-parser/aab.js +89 -226
- package/lib/utils/app-info-parser/apk.d.ts +12 -13
- package/lib/utils/app-info-parser/apk.js +28 -78
- package/lib/utils/app-info-parser/ipa.d.ts +2 -14
- package/lib/utils/app-info-parser/ipa.js +9 -70
- package/lib/utils/app-info-parser/resource-finder.d.ts +1 -34
- package/lib/utils/app-info-parser/resource-finder.js +95 -234
- package/lib/utils/app-info-parser/xml-parser/binary.d.ts +6 -55
- package/lib/utils/app-info-parser/xml-parser/binary.js +152 -556
- package/lib/utils/app-info-parser/zip.d.ts +6 -24
- package/lib/utils/app-info-parser/zip.js +19 -86
- package/lib/utils/check-plugin.d.ts +7 -5
- package/lib/utils/check-plugin.js +15 -25
- package/lib/utils/dep-versions.d.ts +0 -6
- package/lib/utils/dep-versions.js +2 -27
- package/lib/utils/failure-fingerprint.js +3 -4
- package/lib/utils/fs-helpers.d.ts +18 -0
- package/lib/utils/fs-helpers.js +84 -0
- package/lib/utils/git.d.ts +0 -1
- package/lib/utils/git.js +0 -8
- package/lib/utils/hash.d.ts +3 -0
- package/lib/utils/hash.js +19 -0
- package/lib/utils/hbcTransform.d.ts +9 -2
- package/lib/utils/hbcTransform.js +41 -70
- package/lib/utils/hermes-base.d.ts +1 -5
- package/lib/utils/hermes-base.js +136 -196
- package/lib/utils/hermes-literals.d.ts +5 -3
- package/lib/utils/hermes-literals.js +30 -53
- package/lib/utils/hermes-raw.d.ts +7 -0
- package/lib/utils/hermes-raw.js +26 -9
- package/lib/utils/http-helper.d.ts +0 -1
- package/lib/utils/http-helper.js +0 -20
- package/lib/utils/i18n.js +0 -2
- package/lib/utils/index.d.ts +5 -19
- package/lib/utils/index.js +95 -189
- package/lib/utils/latest-version.d.ts +19 -0
- package/lib/utils/latest-version.js +137 -0
- package/lib/utils/options.d.ts +2 -1
- package/lib/utils/options.js +5 -7
- package/lib/utils/runtime.d.ts +1 -1
- package/lib/utils/runtime.js +2 -10
- package/lib/utils/upload-request.d.ts +33 -0
- package/lib/utils/upload-request.js +120 -0
- package/lib/utils/zip-entries.d.ts +23 -0
- package/lib/utils/zip-entries.js +130 -139
- package/lib/utils/zip-options.js +29 -56
- package/lib/utils/zip-range.js +29 -69
- package/lib/utils/zip-raw-writer.js +6 -5
- package/lib/versions.d.ts +5 -0
- package/lib/versions.js +86 -153
- package/package.json +1 -9
- package/lib/utils/app-info-parser/app.d.ts +0 -4
- package/lib/utils/app-info-parser/app.js +0 -10
- package/lib/utils/app-info-parser/index.d.ts +0 -16
- package/lib/utils/app-info-parser/index.js +0 -46
- package/lib/utils/app-info-parser/utils.d.ts +0 -31
- package/lib/utils/app-info-parser/utils.js +0 -135
- package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +0 -10
- package/lib/utils/app-info-parser/xml-parser/manifest.js +0 -202
- package/lib/utils/latest-version/index.d.ts +0 -149
- package/lib/utils/latest-version/index.js +0 -326
- package/lib/utils/plugin-config.d.ts +0 -9
- package/lib/utils/plugin-config.js +0 -61
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @param {String} type // return type, can be buffer or blob, default buffer
|
|
8
|
-
*/
|
|
9
|
-
getEntries(regexps: Array<RegExp | string>, type?: 'buffer' | 'blob'): Promise<Record<string, Blob | Buffer<ArrayBufferLike>>>;
|
|
10
|
-
/**
|
|
11
|
-
* get entry by regex, return an instance of Buffer or Blob
|
|
12
|
-
* @param {Regex} regex // regex for matching file
|
|
13
|
-
* @param {String} type // return type, can be buffer or blob, default buffer
|
|
14
|
-
*/
|
|
15
|
-
getEntry(regex: RegExp | string, type?: 'buffer' | 'blob'): Promise<Blob | Buffer<ArrayBufferLike>>;
|
|
16
|
-
getEntryFromHarmonyApp(regex: RegExp): Promise<Buffer | Blob | undefined>;
|
|
17
|
-
/**
|
|
18
|
-
* Read multiple entries in a single pass over the archive (including
|
|
19
|
-
* nested .hap extraction), instead of one full scan per entry.
|
|
20
|
-
* Returns buffers in the same order as the given regexps.
|
|
21
|
-
*/
|
|
22
|
-
getEntriesFromHarmonyApp(regexps: RegExp[]): Promise<(Buffer | undefined)[]>;
|
|
23
|
-
private readEntries;
|
|
24
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Read the entries matching each pattern in a single pass over the archive
|
|
3
|
+
* (nested .hap archives included). Each entry name is tried as-is and
|
|
4
|
+
* lowercased, with NUL padding stripped. Returns buffers in pattern order.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readZipEntries(file: string, patterns: RegExp[]): Promise<(Buffer | undefined)[]>;
|
|
@@ -1,92 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
3
|
+
exports.readZipEntries = readZipEntries;
|
|
8
4
|
const zip_entries_1 = require("../zip-entries");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
getEntries(regexps, type = 'buffer') {
|
|
21
|
-
const decoded = regexps.map((regex) => (0, utils_1.decodeNullUnicode)(regex));
|
|
22
|
-
return this.readEntries(decoded, type);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* get entry by regex, return an instance of Buffer or Blob
|
|
26
|
-
* @param {Regex} regex // regex for matching file
|
|
27
|
-
* @param {String} type // return type, can be buffer or blob, default buffer
|
|
28
|
-
*/
|
|
29
|
-
getEntry(regex, type = 'buffer') {
|
|
30
|
-
const decoded = (0, utils_1.decodeNullUnicode)(regex);
|
|
31
|
-
return this.readEntries([decoded], type).then((buffers) => buffers[decoded]);
|
|
32
|
-
}
|
|
33
|
-
async getEntryFromHarmonyApp(regex) {
|
|
34
|
-
return (await this.getEntriesFromHarmonyApp([regex]))[0];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Read multiple entries in a single pass over the archive (including
|
|
38
|
-
* nested .hap extraction), instead of one full scan per entry.
|
|
39
|
-
* Returns buffers in the same order as the given regexps.
|
|
40
|
-
*/
|
|
41
|
-
async getEntriesFromHarmonyApp(regexps) {
|
|
42
|
-
const results = new Array(regexps.length);
|
|
43
|
-
try {
|
|
44
|
-
if (typeof this.file !== 'string') {
|
|
45
|
-
throw new Error('Param error: [file] must be file path in Node.');
|
|
46
|
-
}
|
|
47
|
-
await (0, zip_entries_1.enumZipEntries)(this.file, async (entry, zipFile) => {
|
|
48
|
-
for (let i = 0; i < regexps.length; i++) {
|
|
49
|
-
if (regexps[i].test(entry.fileName)) {
|
|
50
|
-
results[i] = await (0, zip_entries_1.readEntry)(entry, zipFile);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
5
|
+
/**
|
|
6
|
+
* Read the entries matching each pattern in a single pass over the archive
|
|
7
|
+
* (nested .hap archives included). Each entry name is tried as-is and
|
|
8
|
+
* lowercased, with NUL padding stripped. Returns buffers in pattern order.
|
|
9
|
+
*/
|
|
10
|
+
async function readZipEntries(file, patterns) {
|
|
11
|
+
const results = new Array(patterns.length);
|
|
12
|
+
await (0, zip_entries_1.enumZipEntries)(file, async (entry, zipFile) => {
|
|
13
|
+
if (entry.fileName.endsWith('/')) {
|
|
14
|
+
return;
|
|
54
15
|
}
|
|
55
|
-
|
|
56
|
-
|
|
16
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: strips NUL padding from entry names
|
|
17
|
+
const name = entry.fileName.replace(/\u0000/g, '');
|
|
18
|
+
const lowerName = name.toLowerCase();
|
|
19
|
+
const index = patterns.findIndex((pattern) => pattern.test(name) || pattern.test(lowerName));
|
|
20
|
+
if (index !== -1) {
|
|
21
|
+
results[index] = await (0, zip_entries_1.readEntry)(entry, zipFile);
|
|
57
22
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
async readEntries(decoded, type) {
|
|
61
|
-
if (typeof this.file !== 'string') {
|
|
62
|
-
throw new Error('Param error: [file] must be file path in Node.');
|
|
63
|
-
}
|
|
64
|
-
const buffers = {};
|
|
65
|
-
await (0, zip_entries_1.enumZipEntries)(this.file, async (entry, zipFile) => {
|
|
66
|
-
if (entry.fileName.endsWith('/')) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const entryName = (0, utils_1.decodeNullUnicode)(entry.fileName).toString();
|
|
70
|
-
const lowerEntryName = entryName.toLowerCase();
|
|
71
|
-
const matched = decoded.find((pattern) => {
|
|
72
|
-
if (typeof pattern === 'string') {
|
|
73
|
-
return pattern === entryName || pattern === lowerEntryName;
|
|
74
|
-
}
|
|
75
|
-
pattern.lastIndex = 0;
|
|
76
|
-
if (pattern.test(entryName)) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
pattern.lastIndex = 0;
|
|
80
|
-
return pattern.test(lowerEntryName);
|
|
81
|
-
});
|
|
82
|
-
if (!matched) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const buffer = await (0, zip_entries_1.readEntry)(entry, zipFile);
|
|
86
|
-
buffers[matched] =
|
|
87
|
-
type === 'blob' ? new Blob([buffer]) : buffer;
|
|
88
|
-
});
|
|
89
|
-
return buffers;
|
|
90
|
-
}
|
|
23
|
+
});
|
|
24
|
+
return results;
|
|
91
25
|
}
|
|
92
|
-
exports.Zip = Zip;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Bundle params implied by the project's plugins. Sentry (a sentry.properties
|
|
3
|
+
* under ios/ or android/) turns on its source map upload, and with it the
|
|
4
|
+
* source map itself.
|
|
5
|
+
*/
|
|
6
|
+
export declare function checkPlugins(): Promise<{
|
|
2
7
|
sentry: boolean;
|
|
3
8
|
sourcemap: boolean;
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export declare function checkPlugins(): Promise<BundleParams>;
|
|
7
|
-
export {};
|
|
9
|
+
}>;
|
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkPlugins = checkPlugins;
|
|
4
|
+
const fs_helpers_1 = require("./fs-helpers");
|
|
4
5
|
const i18n_1 = require("./i18n");
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Bundle params implied by the project's plugins. Sentry (a sentry.properties
|
|
8
|
+
* under ios/ or android/) turns on its source map upload, and with it the
|
|
9
|
+
* source map itself.
|
|
10
|
+
*/
|
|
6
11
|
async function checkPlugins() {
|
|
7
|
-
const
|
|
8
|
-
sentry
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
catch (error) {
|
|
17
|
-
return { isEnabled: false, error };
|
|
18
|
-
}
|
|
19
|
-
}));
|
|
20
|
-
results.forEach(({ isEnabled, error }, index) => {
|
|
21
|
-
const plugin = plugin_config_1.plugins[index];
|
|
22
|
-
if (error) {
|
|
23
|
-
console.warn((0, i18n_1.t)('pluginDetectionError', { name: plugin.name, error }));
|
|
24
|
-
}
|
|
25
|
-
else if (isEnabled && plugin.bundleParams) {
|
|
26
|
-
Object.assign(params, plugin.bundleParams);
|
|
27
|
-
console.log((0, i18n_1.t)('pluginDetected', { name: plugin.name }));
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return params;
|
|
12
|
+
const [ios, android] = await Promise.all([
|
|
13
|
+
(0, fs_helpers_1.pathExists)('ios/sentry.properties'),
|
|
14
|
+
(0, fs_helpers_1.pathExists)('android/sentry.properties'),
|
|
15
|
+
]);
|
|
16
|
+
const sentry = ios || android;
|
|
17
|
+
if (sentry) {
|
|
18
|
+
console.log((0, i18n_1.t)('pluginDetected', { name: 'sentry' }));
|
|
19
|
+
}
|
|
20
|
+
return { sentry, sourcemap: sentry };
|
|
31
21
|
}
|
|
@@ -7,9 +7,3 @@ export declare function getDepVersions(): Record<string, string>;
|
|
|
7
7
|
* before every command must not scale with the size of the project.
|
|
8
8
|
*/
|
|
9
9
|
export declare function getDepVersion(name: string, cwd?: string): string | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Same data as `getDepVersions()` but as a lazily populated object, for the
|
|
12
|
-
* remaining property-access call sites (`depVersions['react-native']`).
|
|
13
|
-
* Nothing is resolved until the first property access.
|
|
14
|
-
*/
|
|
15
|
-
export declare const depVersions: Record<string, string>;
|
|
@@ -8,7 +8,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.depVersions = void 0;
|
|
12
11
|
exports.getDepVersions = getDepVersions;
|
|
13
12
|
exports.getDepVersion = getDepVersion;
|
|
14
13
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -68,12 +67,9 @@ function readDepVersions(cwd) {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
// sorted keys: the object is sent to the server as-is and diffed
|
|
71
|
-
return Object.keys(versions)
|
|
70
|
+
return Object.fromEntries(Object.keys(versions)
|
|
72
71
|
.sort()
|
|
73
|
-
.
|
|
74
|
-
obj[key] = versions[key];
|
|
75
|
-
return obj;
|
|
76
|
-
}, {});
|
|
72
|
+
.map((key) => [key, versions[key]]));
|
|
77
73
|
}
|
|
78
74
|
/** Installed versions of the cwd project's dependencies, keys sorted. */
|
|
79
75
|
function getDepVersions() {
|
|
@@ -101,24 +97,3 @@ function getDepVersion(name, cwd = process.cwd()) {
|
|
|
101
97
|
}
|
|
102
98
|
return readInstalledVersion(name, resolvedCwd);
|
|
103
99
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Same data as `getDepVersions()` but as a lazily populated object, for the
|
|
106
|
-
* remaining property-access call sites (`depVersions['react-native']`).
|
|
107
|
-
* Nothing is resolved until the first property access.
|
|
108
|
-
*/
|
|
109
|
-
exports.depVersions = new Proxy({}, {
|
|
110
|
-
get: (_target, key) => typeof key === 'string' ? getDepVersions()[key] : undefined,
|
|
111
|
-
has: (_target, key) => typeof key === 'string' && key in getDepVersions(),
|
|
112
|
-
ownKeys: () => Object.keys(getDepVersions()),
|
|
113
|
-
getOwnPropertyDescriptor: (_target, key) => {
|
|
114
|
-
if (typeof key !== 'string' || !(key in getDepVersions())) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
value: getDepVersions()[key],
|
|
119
|
-
writable: false,
|
|
120
|
-
enumerable: true,
|
|
121
|
-
configurable: true,
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
});
|
|
@@ -18,10 +18,9 @@ exports.failureFingerprint = failureFingerprint;
|
|
|
18
18
|
* leaves the machine. The local console keeps the unredacted text: that is
|
|
19
19
|
* where the name is actually useful.
|
|
20
20
|
*/
|
|
21
|
-
const
|
|
22
|
-
const sha = (value) => (0, node_crypto_1.createHash)('sha256').update(value).digest('hex');
|
|
21
|
+
const hash_1 = require("./hash");
|
|
23
22
|
/** stable stand-in for one redacted value; the same input always yields it */
|
|
24
|
-
const token = (kind, value) => `${kind}#${
|
|
23
|
+
const token = (kind, value) => `${kind}#${(0, hash_1.sha256Hex)(value).slice(0, 8)}`;
|
|
25
24
|
/**
|
|
26
25
|
* Replace the parts of a detail line that can only come from the user's code:
|
|
27
26
|
* quoted string operands (property names, string literals), function names,
|
|
@@ -68,5 +67,5 @@ function failureFingerprint(detail) {
|
|
|
68
67
|
.replace(/\d+/g, 'N')
|
|
69
68
|
.replace(/\s+/g, ' ')
|
|
70
69
|
.trim();
|
|
71
|
-
return
|
|
70
|
+
return (0, hash_1.sha256Hex)(shape).slice(0, 32);
|
|
72
71
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-user cache directory for `name`: $XDG_CACHE_HOME when set (on every
|
|
3
|
+
* platform; also lets tests isolate), else the platform's cache location.
|
|
4
|
+
*/
|
|
5
|
+
export declare function userCacheDir(name: string): string;
|
|
6
|
+
/** `rm -rf`: no error when the path is already gone. */
|
|
7
|
+
export declare function remove(target: string): Promise<void>;
|
|
8
|
+
export declare function removeSync(target: string): void;
|
|
9
|
+
export declare function ensureDir(dir: string): Promise<void>;
|
|
10
|
+
export declare function ensureDirSync(dir: string): void;
|
|
11
|
+
export declare function pathExists(target: string): Promise<boolean>;
|
|
12
|
+
/** Deletes everything inside `dir`, creating it when missing. */
|
|
13
|
+
export declare function emptyDirSync(dir: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Moves `src` to `dest`, replacing it. Creates the parent of `dest`, and
|
|
16
|
+
* falls back to copy + delete when the two are on different devices.
|
|
17
|
+
*/
|
|
18
|
+
export declare function moveSync(src: string, dest: string): void;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The handful of fs-extra conveniences the CLI used, on plain node:fs.
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.userCacheDir = userCacheDir;
|
|
8
|
+
exports.remove = remove;
|
|
9
|
+
exports.removeSync = removeSync;
|
|
10
|
+
exports.ensureDir = ensureDir;
|
|
11
|
+
exports.ensureDirSync = ensureDirSync;
|
|
12
|
+
exports.pathExists = pathExists;
|
|
13
|
+
exports.emptyDirSync = emptyDirSync;
|
|
14
|
+
exports.moveSync = moveSync;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const os_1 = require("os");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
/**
|
|
19
|
+
* The per-user cache directory for `name`: $XDG_CACHE_HOME when set (on every
|
|
20
|
+
* platform; also lets tests isolate), else the platform's cache location.
|
|
21
|
+
*/
|
|
22
|
+
function userCacheDir(name) {
|
|
23
|
+
if (process.env.XDG_CACHE_HOME) {
|
|
24
|
+
return path_1.default.join(process.env.XDG_CACHE_HOME, name);
|
|
25
|
+
}
|
|
26
|
+
switch (process.platform) {
|
|
27
|
+
case 'darwin':
|
|
28
|
+
return path_1.default.join((0, os_1.homedir)(), 'Library', 'Caches', name);
|
|
29
|
+
case 'win32':
|
|
30
|
+
return path_1.default.join(process.env.LOCALAPPDATA ?? path_1.default.join((0, os_1.homedir)(), 'AppData', 'Local'), name, 'Cache');
|
|
31
|
+
default:
|
|
32
|
+
return path_1.default.join((0, os_1.homedir)(), '.cache', name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** `rm -rf`: no error when the path is already gone. */
|
|
36
|
+
function remove(target) {
|
|
37
|
+
return fs_1.default.promises.rm(target, { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
function removeSync(target) {
|
|
40
|
+
fs_1.default.rmSync(target, { recursive: true, force: true });
|
|
41
|
+
}
|
|
42
|
+
async function ensureDir(dir) {
|
|
43
|
+
await fs_1.default.promises.mkdir(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
function ensureDirSync(dir) {
|
|
46
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
function pathExists(target) {
|
|
49
|
+
return fs_1.default.promises.access(target).then(() => true, () => false);
|
|
50
|
+
}
|
|
51
|
+
/** Deletes everything inside `dir`, creating it when missing. */
|
|
52
|
+
function emptyDirSync(dir) {
|
|
53
|
+
let names;
|
|
54
|
+
try {
|
|
55
|
+
names = fs_1.default.readdirSync(dir);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
// only a missing directory is created; an unreadable one must not pass
|
|
59
|
+
// for emptied
|
|
60
|
+
if (err.code !== 'ENOENT')
|
|
61
|
+
throw err;
|
|
62
|
+
ensureDirSync(dir);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const name of names)
|
|
66
|
+
removeSync(path_1.default.join(dir, name));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Moves `src` to `dest`, replacing it. Creates the parent of `dest`, and
|
|
70
|
+
* falls back to copy + delete when the two are on different devices.
|
|
71
|
+
*/
|
|
72
|
+
function moveSync(src, dest) {
|
|
73
|
+
ensureDirSync(path_1.default.dirname(dest));
|
|
74
|
+
try {
|
|
75
|
+
fs_1.default.renameSync(src, dest);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (err.code !== 'EXDEV')
|
|
79
|
+
throw err;
|
|
80
|
+
removeSync(dest);
|
|
81
|
+
fs_1.default.cpSync(src, dest, { recursive: true });
|
|
82
|
+
removeSync(src);
|
|
83
|
+
}
|
|
84
|
+
}
|
package/lib/utils/git.d.ts
CHANGED
package/lib/utils/git.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentCommit = getCurrentCommit;
|
|
4
3
|
exports.getCommitInfo = getCommitInfo;
|
|
5
4
|
const child_process_1 = require("child_process");
|
|
6
5
|
const util_1 = require("util");
|
|
7
6
|
const execFile = (0, util_1.promisify)(child_process_1.execFile);
|
|
8
|
-
function getCurrentCommit() {
|
|
9
|
-
const result = (0, child_process_1.spawnSync)('git', ['rev-parse', 'HEAD']);
|
|
10
|
-
if (result.status !== 0) {
|
|
11
|
-
throw new Error('Not a git repository');
|
|
12
|
-
}
|
|
13
|
-
return result.stdout.toString().trim();
|
|
14
|
-
}
|
|
15
7
|
async function gitOutput(args, cwd = process.cwd()) {
|
|
16
8
|
const { stdout } = await execFile('git', args, {
|
|
17
9
|
cwd,
|
|
@@ -0,0 +1,19 @@
|
|
|
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.sha256Hex = sha256Hex;
|
|
7
|
+
exports.sha256File = sha256File;
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
function sha256Hex(data) {
|
|
11
|
+
return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
12
|
+
}
|
|
13
|
+
/** sha256 of a file, streamed (a bundle or cached base can be tens of MB) */
|
|
14
|
+
async function sha256File(file) {
|
|
15
|
+
const hash = (0, crypto_1.createHash)('sha256');
|
|
16
|
+
for await (const chunk of fs_1.default.createReadStream(file))
|
|
17
|
+
hash.update(chunk);
|
|
18
|
+
return hash.digest('hex');
|
|
19
|
+
}
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* wrapping 差分与单调性无关、恒可逆:T⁻¹(T(x)) === x 对任意输入成立
|
|
15
15
|
* (只要两侧使用同一份描述表)。
|
|
16
16
|
*/
|
|
17
|
+
export declare const HBC_MAGIC: Buffer<ArrayBuffer>;
|
|
18
|
+
export declare const HBC_HEADER_SIZE = 128;
|
|
17
19
|
/** 差分字段:条目内 byte 偏移处按小端读 u32,取 [bit, bit+bits) 位。 */
|
|
18
20
|
type DeltaField = {
|
|
19
21
|
byte: number;
|
|
@@ -70,6 +72,7 @@ export type HbcSectionRange = {
|
|
|
70
72
|
*/
|
|
71
73
|
export declare function resolveHbcSections(header: Buffer, fileLength: number): {
|
|
72
74
|
version: number;
|
|
75
|
+
layout: HbcLayout;
|
|
73
76
|
sections: Map<string, HbcSectionRange>;
|
|
74
77
|
} | null;
|
|
75
78
|
/**
|
|
@@ -79,14 +82,18 @@ export declare function resolveHbcSections(header: Buffer, fileLength: number):
|
|
|
79
82
|
* 注意:变换不改动头部计数,同一文件正/逆向解析选中的布局必然一致。
|
|
80
83
|
*/
|
|
81
84
|
export declare function transformHbc(buf: Buffer, inverse?: boolean): Buffer | null;
|
|
82
|
-
/** 返回该 buffer 结构上匹配的布局(候选中第一个校验通过者)。 */
|
|
83
|
-
export declare function pickLayout(buf: Buffer): HbcLayout | null;
|
|
84
85
|
export declare function transformHbcWithLayout(buf: Buffer, layout: HbcLayout, inverse: boolean): Buffer | null;
|
|
85
86
|
/**
|
|
86
87
|
* 原地变换:直接改写 buf,不再分配整块副本。调用方须持有 buf 的所有权
|
|
87
88
|
* (例如 patch() 刚返回的新 Buffer)。结构不匹配时返回 false 且 buf 不变。
|
|
88
89
|
*/
|
|
89
90
|
export declare function transformHbcWithLayoutInPlace(buf: Buffer, layout: HbcLayout, inverse: boolean): boolean;
|
|
91
|
+
type HbcFileHeader = {
|
|
92
|
+
header: Buffer;
|
|
93
|
+
size: number;
|
|
94
|
+
};
|
|
95
|
+
/** 读取文件头 128 字节与总长;文件过短或非 HBC 时返回 null。 */
|
|
96
|
+
export declare function readHbcFileHeader(filePath: string): Promise<HbcFileHeader | null>;
|
|
90
97
|
/**
|
|
91
98
|
* 文件版 transformHbcWithLayout:把 src 复制到 dst,再仅对含差分字段的
|
|
92
99
|
* 段(位于 [128, 最后一段末尾) 区间内)做定位读写改写。任一时刻内存中
|