react-native-update-cli 2.20.4 → 2.21.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/api.js +8 -1
- package/lib/diff.js +31 -17
- 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/package.js +5 -4
- package/lib/provider.js +2 -0
- package/lib/user.js +4 -0
- package/lib/utils/app-info-parser/aab.js +9 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +19 -14
- package/lib/versions.js +24 -10
- package/package.json +1 -1
- package/src/api.ts +7 -1
- package/src/diff.ts +43 -17
- package/src/locales/en.ts +4 -0
- package/src/locales/zh.ts +3 -0
- package/src/package.ts +6 -6
- package/src/provider.ts +2 -0
- package/src/user.ts +4 -0
- package/src/utils/app-info-parser/aab.ts +9 -1
- package/src/utils/index.ts +14 -9
- package/src/versions.ts +31 -13
package/lib/api.js
CHANGED
|
@@ -60,7 +60,14 @@ const saveSession = () => {
|
|
|
60
60
|
if (session !== savedSession) {
|
|
61
61
|
const current = session;
|
|
62
62
|
const data = JSON.stringify(current, null, 4);
|
|
63
|
-
fs_1.default.writeFileSync(constants_1.credentialFile, data, 'utf8');
|
|
63
|
+
fs_1.default.writeFileSync(constants_1.credentialFile, data, { encoding: 'utf8', mode: 0o600 });
|
|
64
|
+
try {
|
|
65
|
+
// mode above only applies on creation; tighten pre-existing files too
|
|
66
|
+
fs_1.default.chmodSync(constants_1.credentialFile, 0o600);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// best-effort (e.g. exotic filesystems); the token is still saved
|
|
70
|
+
}
|
|
64
71
|
savedSession = current;
|
|
65
72
|
}
|
|
66
73
|
};
|
package/lib/diff.js
CHANGED
|
@@ -74,7 +74,10 @@ function createOutputZip(output) {
|
|
|
74
74
|
const zipfile = new yazl_1.ZipFile();
|
|
75
75
|
const writePromise = new Promise((resolve, reject) => {
|
|
76
76
|
zipfile.outputStream.on('error', reject);
|
|
77
|
-
|
|
77
|
+
const writeStream = fs.createWriteStream(output);
|
|
78
|
+
// without this, a full disk / read-only target left the promise pending
|
|
79
|
+
writeStream.on('error', reject);
|
|
80
|
+
zipfile.outputStream.pipe(writeStream).on('close', () => {
|
|
78
81
|
resolve(void 0);
|
|
79
82
|
});
|
|
80
83
|
});
|
|
@@ -149,17 +152,12 @@ async function buildStreamBundlePatch(originSource, newSource, options, workRoot
|
|
|
149
152
|
const pair = originBuffer && newBuffer
|
|
150
153
|
? (0, hbcTransform_1.tryTransformPair)(originBuffer, newBuffer)
|
|
151
154
|
: null;
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
: rawOldFile;
|
|
155
|
-
const newFile = pair
|
|
156
|
-
? path_1.default.join(tempRoot, 'new-transformed.bin')
|
|
157
|
-
: rawNewFile;
|
|
158
|
-
const patchFile = path_1.default.join(tempRoot, 'patch.bin');
|
|
155
|
+
const transformedOldFile = path_1.default.join(tempRoot, 'old-transformed.bin');
|
|
156
|
+
const transformedNewFile = path_1.default.join(tempRoot, 'new-transformed.bin');
|
|
159
157
|
if (pair) {
|
|
160
158
|
await Promise.all([
|
|
161
|
-
fs.writeFile(
|
|
162
|
-
fs.writeFile(
|
|
159
|
+
fs.writeFile(transformedOldFile, pair.tOld),
|
|
160
|
+
fs.writeFile(transformedNewFile, pair.tNew),
|
|
163
161
|
]);
|
|
164
162
|
}
|
|
165
163
|
reportDiffPhase(options, {
|
|
@@ -167,9 +165,25 @@ async function buildStreamBundlePatch(originSource, newSource, options, workRoot
|
|
|
167
165
|
durationMs: extractionDurationMs + performance.now() - phaseStartedAt,
|
|
168
166
|
inputBytes,
|
|
169
167
|
});
|
|
168
|
+
// 与内存路径同一约束:变换候选连同元数据开销必须比 baseline 更小才采用,
|
|
169
|
+
// 因此变换命中时两个候选都要生成再比较。
|
|
170
170
|
phaseStartedAt = performance.now();
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
const rawPatchFile = path_1.default.join(tempRoot, 'patch-raw.bin');
|
|
172
|
+
await diffStreamFn(rawOldFile, rawNewFile, rawPatchFile);
|
|
173
|
+
let patchFile = rawPatchFile;
|
|
174
|
+
let patchBytes = (await fs.stat(rawPatchFile)).size;
|
|
175
|
+
let chosenPair = null;
|
|
176
|
+
if (pair) {
|
|
177
|
+
const transformedPatchFile = path_1.default.join(tempRoot, 'patch-transformed.bin');
|
|
178
|
+
await diffStreamFn(transformedOldFile, transformedNewFile, transformedPatchFile);
|
|
179
|
+
const transformedPatchBytes = (await fs.stat(transformedPatchFile)).size;
|
|
180
|
+
const metaOverhead = Buffer.byteLength(JSON.stringify(pair.meta));
|
|
181
|
+
if (transformedPatchBytes + metaOverhead < patchBytes) {
|
|
182
|
+
patchFile = transformedPatchFile;
|
|
183
|
+
patchBytes = transformedPatchBytes;
|
|
184
|
+
chosenPair = pair;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
173
187
|
reportDiffPhase(options, {
|
|
174
188
|
phase: 'diff',
|
|
175
189
|
durationMs: performance.now() - phaseStartedAt,
|
|
@@ -178,13 +192,13 @@ async function buildStreamBundlePatch(originSource, newSource, options, workRoot
|
|
|
178
192
|
});
|
|
179
193
|
// 变换路径必须验证 T⁻¹ 和元数据;未声明自校验的自定义 diff 也保留
|
|
180
194
|
// round-trip。node-hdiffpatch native 普通路径已经在返回前完整验证。
|
|
181
|
-
if (
|
|
195
|
+
if (chosenPair || !options.streamOutputVerified) {
|
|
182
196
|
phaseStartedAt = performance.now();
|
|
183
197
|
const restoredFile = path_1.default.join(tempRoot, 'restored.bin');
|
|
184
|
-
await patchStreamFn(
|
|
185
|
-
if (
|
|
198
|
+
await patchStreamFn(chosenPair ? transformedOldFile : rawOldFile, patchFile, restoredFile);
|
|
199
|
+
if (chosenPair) {
|
|
186
200
|
const restoredRaw = await fs.readFile(restoredFile);
|
|
187
|
-
const restored = (0, hbcTransform_1.transformHbcWithLayout)(restoredRaw,
|
|
201
|
+
const restored = (0, hbcTransform_1.transformHbcWithLayout)(restoredRaw, chosenPair.layout, true);
|
|
188
202
|
if (!restored ||
|
|
189
203
|
!newBuffer ||
|
|
190
204
|
Buffer.compare(restored, newBuffer) !== 0) {
|
|
@@ -212,7 +226,7 @@ async function buildStreamBundlePatch(originSource, newSource, options, workRoot
|
|
|
212
226
|
}
|
|
213
227
|
return {
|
|
214
228
|
patch: { kind: 'file', path: patchFile },
|
|
215
|
-
...(
|
|
229
|
+
...(chosenPair ? { hbcTransform: chosenPair.meta } : {}),
|
|
216
230
|
};
|
|
217
231
|
}
|
|
218
232
|
/**
|
package/lib/locales/en.d.ts
CHANGED
|
@@ -58,6 +58,8 @@ declare const _default: {
|
|
|
58
58
|
nativeVersion: string;
|
|
59
59
|
nativeVersionNotFoundGte: string;
|
|
60
60
|
nativeVersionNotFoundLte: string;
|
|
61
|
+
nativeVersionNotFoundBetween: string;
|
|
62
|
+
conflictingPackageSelectors: string;
|
|
61
63
|
nativeVersionNotFoundMatch: string;
|
|
62
64
|
nativePackageIdNotFound: string;
|
|
63
65
|
noPackagesFound: string;
|
package/lib/locales/en.js
CHANGED
|
@@ -66,6 +66,8 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
66
66
|
nativeVersion: 'Native Version',
|
|
67
67
|
nativeVersionNotFoundGte: 'No native version found >= {{version}}',
|
|
68
68
|
nativeVersionNotFoundLte: 'No native version found <= {{version}}',
|
|
69
|
+
nativeVersionNotFoundBetween: 'No native version found between {{min}} and {{max}}',
|
|
70
|
+
conflictingPackageSelectors: 'Only one of packageId / packageVersion / packageVersionRange / minPackageVersion+maxPackageVersion can be used at a time',
|
|
69
71
|
nativeVersionNotFoundMatch: 'No matching native version found: {{version}}',
|
|
70
72
|
nativePackageIdNotFound: 'No native package id found: {{id}}',
|
|
71
73
|
noPackagesFound: 'No packages found. (appId: {{appId}})',
|
package/lib/locales/zh.d.ts
CHANGED
|
@@ -58,6 +58,8 @@ declare const _default: {
|
|
|
58
58
|
nativeVersion: string;
|
|
59
59
|
nativeVersionNotFoundGte: string;
|
|
60
60
|
nativeVersionNotFoundLte: string;
|
|
61
|
+
nativeVersionNotFoundBetween: string;
|
|
62
|
+
conflictingPackageSelectors: string;
|
|
61
63
|
nativeVersionNotFoundMatch: string;
|
|
62
64
|
nativePackageIdNotFound: string;
|
|
63
65
|
noPackagesFound: string;
|
package/lib/locales/zh.js
CHANGED
|
@@ -66,6 +66,8 @@ exports.default = {
|
|
|
66
66
|
nativeVersion: '原生版本',
|
|
67
67
|
nativeVersionNotFoundGte: '未查询到 >= {{version}} 的原生版本',
|
|
68
68
|
nativeVersionNotFoundLte: '未查询到 <= {{version}} 的原生版本',
|
|
69
|
+
nativeVersionNotFoundBetween: '未查询到 {{min}} 至 {{max}} 之间的原生版本',
|
|
70
|
+
conflictingPackageSelectors: 'packageId / packageVersion / packageVersionRange / minPackageVersion+maxPackageVersion 只能使用其中一组,不能混用',
|
|
69
71
|
nativeVersionNotFoundMatch: '未查询到匹配原生版本:{{version}}',
|
|
70
72
|
nativePackageIdNotFound: '未查询到原生包 id: {{id}}',
|
|
71
73
|
noPackagesFound: '未查询到任何原生包(appId: {{appId}})',
|
package/lib/package.js
CHANGED
|
@@ -212,7 +212,10 @@ exports.packageCommands = {
|
|
|
212
212
|
},
|
|
213
213
|
uploadAab: async ({ args, options, }) => {
|
|
214
214
|
const source = ensureFileByExt(args[0], '.aab', 'usageUploadAab');
|
|
215
|
-
|
|
215
|
+
// private temp dir: unpredictable path, safe against symlink squatting in
|
|
216
|
+
// the shared tmpdir and against concurrent uploads of same-named AABs
|
|
217
|
+
const tempRoot = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-aab-upload-'));
|
|
218
|
+
const output = path_1.default.join(tempRoot, 'universal.apk');
|
|
216
219
|
const includeAllSplits = parseBooleanOption(options.includeAllSplits);
|
|
217
220
|
const splits = parseCsvOption(options.splits);
|
|
218
221
|
const parser = new aab_1.AabParser(source);
|
|
@@ -227,9 +230,7 @@ exports.packageCommands = {
|
|
|
227
230
|
});
|
|
228
231
|
}
|
|
229
232
|
finally {
|
|
230
|
-
|
|
231
|
-
await fs.remove(output);
|
|
232
|
-
}
|
|
233
|
+
await fs.remove(tempRoot);
|
|
233
234
|
}
|
|
234
235
|
},
|
|
235
236
|
uploadApp: async ({ args, options, }) => {
|
package/lib/provider.js
CHANGED
|
@@ -108,6 +108,8 @@ class CLIProviderImpl {
|
|
|
108
108
|
maxPackageVersion: options.maxPackageVersion,
|
|
109
109
|
packageVersionRange: options.packageVersionRange,
|
|
110
110
|
platform: options.platform,
|
|
111
|
+
appId: options.appId,
|
|
112
|
+
config: options.config,
|
|
111
113
|
'no-interactive': true,
|
|
112
114
|
rollout: options.rollout === undefined
|
|
113
115
|
? undefined
|
package/lib/user.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.userCommands = void 0;
|
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const api_1 = require("./api");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
|
+
const add_gitignore_1 = require("./utils/add-gitignore");
|
|
10
11
|
const i18n_1 = require("./utils/i18n");
|
|
11
12
|
function md5(str) {
|
|
12
13
|
return crypto_1.default.createHash('md5').update(str).digest('hex');
|
|
@@ -21,6 +22,9 @@ exports.userCommands = {
|
|
|
21
22
|
});
|
|
22
23
|
(0, api_1.replaceSession)({ token });
|
|
23
24
|
await (0, api_1.saveSession)();
|
|
25
|
+
// make sure the token file is ignored before the user's next commit,
|
|
26
|
+
// not only when they first run `bundle`
|
|
27
|
+
(0, add_gitignore_1.addGitIgnore)();
|
|
24
28
|
console.log((0, i18n_1.t)('welcomeMessage', { name: info.name }));
|
|
25
29
|
},
|
|
26
30
|
logout: async (_context) => {
|
|
@@ -108,7 +108,14 @@ class AabParser extends zip_1.Zip {
|
|
|
108
108
|
...modulesArgs,
|
|
109
109
|
]);
|
|
110
110
|
}
|
|
111
|
-
catch (
|
|
111
|
+
catch (e) {
|
|
112
|
+
// Only fall back when bundletool itself is missing from PATH (spawn
|
|
113
|
+
// ENOENT). Any other failure (corrupt AAB, Java issues, bad args,
|
|
114
|
+
// non-zero exit) must surface as-is instead of being masked by an
|
|
115
|
+
// online npx install.
|
|
116
|
+
if (e?.code !== 'ENOENT') {
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
112
119
|
// Fallback to npx node-bundletool if bundletool is not in PATH
|
|
113
120
|
// We use -y to avoid interactive prompt for installation
|
|
114
121
|
if (await needsNpxDownload()) {
|
|
@@ -154,6 +161,7 @@ class AabParser extends zip_1.Zip {
|
|
|
154
161
|
zipfile.close();
|
|
155
162
|
resolve();
|
|
156
163
|
});
|
|
164
|
+
readStream.on('error', reject);
|
|
157
165
|
writeStream.on('error', reject);
|
|
158
166
|
});
|
|
159
167
|
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { checkPlugins } from './check-plugin';
|
|
|
2
2
|
export declare function isNonInteractive(): boolean;
|
|
3
3
|
export declare function question(query: string, password?: boolean): Promise<string>;
|
|
4
4
|
export declare function translateOptions<T extends Record<string, unknown>>(options: T, map?: Record<string, string>): T & Record<string, unknown>;
|
|
5
|
+
export declare const ApkBundleFileName: RegExp;
|
|
5
6
|
export declare function getApkInfo(fn: string): Promise<{
|
|
6
7
|
versionName: string;
|
|
7
8
|
buildTime: number;
|
|
@@ -12,6 +13,7 @@ export declare function getAppInfo(fn: string): Promise<{
|
|
|
12
13
|
buildTime: number;
|
|
13
14
|
bundleHash: string;
|
|
14
15
|
}>;
|
|
16
|
+
export declare const IpaBundleFileName: RegExp;
|
|
15
17
|
export declare function getIpaInfo(fn: string): Promise<{
|
|
16
18
|
versionName: string;
|
|
17
19
|
buildTime: string;
|
package/lib/utils/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.checkPlugins = void 0;
|
|
6
|
+
exports.checkPlugins = exports.IpaBundleFileName = exports.ApkBundleFileName = void 0;
|
|
7
7
|
exports.isNonInteractive = isNonInteractive;
|
|
8
8
|
exports.question = question;
|
|
9
9
|
exports.translateOptions = translateOptions;
|
|
@@ -84,16 +84,19 @@ async function sha256(data) {
|
|
|
84
84
|
: Buffer.from(await data.arrayBuffer());
|
|
85
85
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
// Anchored exact paths: unanchored/unescaped patterns also matched entries
|
|
88
|
+
// like index.android.bundle.map or .backup, and a later match would silently
|
|
89
|
+
// overwrite the real bundle, registering a wrong bundleHash.
|
|
90
|
+
exports.ApkBundleFileName = /^assets\/index\.android\.bundle$/;
|
|
91
|
+
const ApkUpdateJsonName = /^res\/raw\/update\.json$/;
|
|
89
92
|
async function getApkInfo(fn) {
|
|
90
93
|
const appInfoParser = new app_info_parser_1.default(fn);
|
|
91
94
|
// read both entries in a single scan over the archive
|
|
92
95
|
const entries = await appInfoParser.parser.getEntries([
|
|
93
|
-
ApkBundleFileName,
|
|
96
|
+
exports.ApkBundleFileName,
|
|
94
97
|
ApkUpdateJsonName,
|
|
95
98
|
]);
|
|
96
|
-
const bundleFile = entries[String(ApkBundleFileName)];
|
|
99
|
+
const bundleFile = entries[String(exports.ApkBundleFileName)];
|
|
97
100
|
if (!bundleFile) {
|
|
98
101
|
throw new Error((0, i18n_1.t)('bundleNotFound', {
|
|
99
102
|
packageType: 'apk',
|
|
@@ -134,9 +137,9 @@ async function getAppInfo(fn) {
|
|
|
134
137
|
const appInfoParser = new app_info_parser_1.default(fn);
|
|
135
138
|
// single scan (and single nested .hap extraction) for all three entries
|
|
136
139
|
const [bundleFile, updateJsonFile, metaJsonFile] = await appInfoParser.parser.getEntriesFromHarmonyApp([
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
/^resources\/rawfile\/bundle\.harmony\.js$/,
|
|
141
|
+
/^resources\/rawfile\/update\.json$/,
|
|
142
|
+
/^resources\/rawfile\/meta\.json$/,
|
|
140
143
|
]);
|
|
141
144
|
if (!bundleFile) {
|
|
142
145
|
throw new Error((0, i18n_1.t)('bundleNotFound', {
|
|
@@ -167,21 +170,23 @@ async function getAppInfo(fn) {
|
|
|
167
170
|
...appCredential,
|
|
168
171
|
};
|
|
169
172
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
// lowercase because the zip reader also matches against the lowercased entry
|
|
174
|
+
// name (real IPAs use "Payload/")
|
|
175
|
+
exports.IpaBundleFileName = /^payload\/[^/]+\.app\/main\.jsbundle$/;
|
|
176
|
+
const IpaUpdateJsonName = /^payload\/[^/]+\.app\/assets\/update\.json$/;
|
|
177
|
+
const IpaBuildTimeName = /^payload\/[^/]+\.app\/pushy_build_time\.txt$/;
|
|
173
178
|
// Not in root bundle when use `use_frameworks`
|
|
174
|
-
const IpaBuildTimeFrameworkName =
|
|
179
|
+
const IpaBuildTimeFrameworkName = /^payload\/[^/]+\.app\/frameworks\/react_native_update\.framework\/pushy_build_time\.txt$/;
|
|
175
180
|
async function getIpaInfo(fn) {
|
|
176
181
|
const appInfoParser = new app_info_parser_1.default(fn);
|
|
177
182
|
// read all four entries in a single scan over the archive
|
|
178
183
|
const entries = await appInfoParser.parser.getEntries([
|
|
179
|
-
IpaBundleFileName,
|
|
184
|
+
exports.IpaBundleFileName,
|
|
180
185
|
IpaUpdateJsonName,
|
|
181
186
|
IpaBuildTimeName,
|
|
182
187
|
IpaBuildTimeFrameworkName,
|
|
183
188
|
]);
|
|
184
|
-
const bundleFile = entries[String(IpaBundleFileName)];
|
|
189
|
+
const bundleFile = entries[String(exports.IpaBundleFileName)];
|
|
185
190
|
if (!bundleFile) {
|
|
186
191
|
throw new Error((0, i18n_1.t)('bundleNotFound', {
|
|
187
192
|
packageType: 'ipa',
|
package/lib/versions.js
CHANGED
|
@@ -427,19 +427,33 @@ exports.versionCommands = {
|
|
|
427
427
|
}
|
|
428
428
|
const pkgMap = new Map(allPkgs.map((pkg) => [String(pkg.id), pkg]));
|
|
429
429
|
let pkgsToBind = [];
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
430
|
+
const selectorGroups = [
|
|
431
|
+
pkgId,
|
|
432
|
+
pkgVersion,
|
|
433
|
+
packageVersionRange,
|
|
434
|
+
minPkgVersion || maxPkgVersion,
|
|
435
|
+
].filter(Boolean);
|
|
436
|
+
if (selectorGroups.length > 1) {
|
|
437
|
+
throw new Error((0, i18n_1.t)('conflictingPackageSelectors'));
|
|
438
|
+
}
|
|
439
|
+
if (minPkgVersion || maxPkgVersion) {
|
|
440
|
+
minPkgVersion = minPkgVersion && String(minPkgVersion).trim();
|
|
441
|
+
maxPkgVersion = maxPkgVersion && String(maxPkgVersion).trim();
|
|
439
442
|
pkgsToBind = allPkgs.filter((pkg) => {
|
|
440
|
-
|
|
443
|
+
const aboveMin = !minPkgVersion || (0, compare_versions_1.compare)(pkg.name, minPkgVersion, '>=');
|
|
444
|
+
const belowMax = !maxPkgVersion || (0, compare_versions_1.compare)(pkg.name, maxPkgVersion, '<=');
|
|
445
|
+
return aboveMin && belowMax;
|
|
441
446
|
});
|
|
442
447
|
if (pkgsToBind.length === 0) {
|
|
448
|
+
if (minPkgVersion && maxPkgVersion) {
|
|
449
|
+
throw new Error((0, i18n_1.t)('nativeVersionNotFoundBetween', {
|
|
450
|
+
min: minPkgVersion,
|
|
451
|
+
max: maxPkgVersion,
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
454
|
+
if (minPkgVersion) {
|
|
455
|
+
throw new Error((0, i18n_1.t)('nativeVersionNotFoundGte', { version: minPkgVersion }));
|
|
456
|
+
}
|
|
443
457
|
throw new Error((0, i18n_1.t)('nativeVersionNotFoundLte', { version: maxPkgVersion }));
|
|
444
458
|
}
|
|
445
459
|
}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -64,7 +64,13 @@ export const saveSession = () => {
|
|
|
64
64
|
if (session !== savedSession) {
|
|
65
65
|
const current = session;
|
|
66
66
|
const data = JSON.stringify(current, null, 4);
|
|
67
|
-
fs.writeFileSync(credentialFile, data, 'utf8');
|
|
67
|
+
fs.writeFileSync(credentialFile, data, { encoding: 'utf8', mode: 0o600 });
|
|
68
|
+
try {
|
|
69
|
+
// mode above only applies on creation; tighten pre-existing files too
|
|
70
|
+
fs.chmodSync(credentialFile, 0o600);
|
|
71
|
+
} catch {
|
|
72
|
+
// best-effort (e.g. exotic filesystems); the token is still saved
|
|
73
|
+
}
|
|
68
74
|
savedSession = current;
|
|
69
75
|
}
|
|
70
76
|
};
|
package/src/diff.ts
CHANGED
|
@@ -113,7 +113,10 @@ function createOutputZip(output: string) {
|
|
|
113
113
|
const zipfile = new YazlZipFile();
|
|
114
114
|
const writePromise = new Promise<void>((resolve, reject) => {
|
|
115
115
|
zipfile.outputStream.on('error', reject);
|
|
116
|
-
|
|
116
|
+
const writeStream = fs.createWriteStream(output);
|
|
117
|
+
// without this, a full disk / read-only target left the promise pending
|
|
118
|
+
writeStream.on('error', reject);
|
|
119
|
+
zipfile.outputStream.pipe(writeStream).on('close', () => {
|
|
117
120
|
resolve(void 0);
|
|
118
121
|
});
|
|
119
122
|
});
|
|
@@ -248,18 +251,13 @@ async function buildStreamBundlePatch(
|
|
|
248
251
|
originBuffer && newBuffer
|
|
249
252
|
? tryTransformPair(originBuffer, newBuffer)
|
|
250
253
|
: null;
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
: rawOldFile;
|
|
254
|
-
const newFile = pair
|
|
255
|
-
? path.join(tempRoot, 'new-transformed.bin')
|
|
256
|
-
: rawNewFile;
|
|
257
|
-
const patchFile = path.join(tempRoot, 'patch.bin');
|
|
254
|
+
const transformedOldFile = path.join(tempRoot, 'old-transformed.bin');
|
|
255
|
+
const transformedNewFile = path.join(tempRoot, 'new-transformed.bin');
|
|
258
256
|
|
|
259
257
|
if (pair) {
|
|
260
258
|
await Promise.all([
|
|
261
|
-
fs.writeFile(
|
|
262
|
-
fs.writeFile(
|
|
259
|
+
fs.writeFile(transformedOldFile, pair.tOld),
|
|
260
|
+
fs.writeFile(transformedNewFile, pair.tNew),
|
|
263
261
|
]);
|
|
264
262
|
}
|
|
265
263
|
reportDiffPhase(options, {
|
|
@@ -268,9 +266,29 @@ async function buildStreamBundlePatch(
|
|
|
268
266
|
inputBytes,
|
|
269
267
|
});
|
|
270
268
|
|
|
269
|
+
// 与内存路径同一约束:变换候选连同元数据开销必须比 baseline 更小才采用,
|
|
270
|
+
// 因此变换命中时两个候选都要生成再比较。
|
|
271
271
|
phaseStartedAt = performance.now();
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
const rawPatchFile = path.join(tempRoot, 'patch-raw.bin');
|
|
273
|
+
await diffStreamFn(rawOldFile, rawNewFile, rawPatchFile);
|
|
274
|
+
let patchFile = rawPatchFile;
|
|
275
|
+
let patchBytes = (await fs.stat(rawPatchFile)).size;
|
|
276
|
+
let chosenPair: typeof pair = null;
|
|
277
|
+
if (pair) {
|
|
278
|
+
const transformedPatchFile = path.join(tempRoot, 'patch-transformed.bin');
|
|
279
|
+
await diffStreamFn(
|
|
280
|
+
transformedOldFile,
|
|
281
|
+
transformedNewFile,
|
|
282
|
+
transformedPatchFile,
|
|
283
|
+
);
|
|
284
|
+
const transformedPatchBytes = (await fs.stat(transformedPatchFile)).size;
|
|
285
|
+
const metaOverhead = Buffer.byteLength(JSON.stringify(pair.meta));
|
|
286
|
+
if (transformedPatchBytes + metaOverhead < patchBytes) {
|
|
287
|
+
patchFile = transformedPatchFile;
|
|
288
|
+
patchBytes = transformedPatchBytes;
|
|
289
|
+
chosenPair = pair;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
274
292
|
reportDiffPhase(options, {
|
|
275
293
|
phase: 'diff',
|
|
276
294
|
durationMs: performance.now() - phaseStartedAt,
|
|
@@ -280,13 +298,21 @@ async function buildStreamBundlePatch(
|
|
|
280
298
|
|
|
281
299
|
// 变换路径必须验证 T⁻¹ 和元数据;未声明自校验的自定义 diff 也保留
|
|
282
300
|
// round-trip。node-hdiffpatch native 普通路径已经在返回前完整验证。
|
|
283
|
-
if (
|
|
301
|
+
if (chosenPair || !options.streamOutputVerified) {
|
|
284
302
|
phaseStartedAt = performance.now();
|
|
285
303
|
const restoredFile = path.join(tempRoot, 'restored.bin');
|
|
286
|
-
await patchStreamFn(
|
|
287
|
-
|
|
304
|
+
await patchStreamFn(
|
|
305
|
+
chosenPair ? transformedOldFile : rawOldFile,
|
|
306
|
+
patchFile,
|
|
307
|
+
restoredFile,
|
|
308
|
+
);
|
|
309
|
+
if (chosenPair) {
|
|
288
310
|
const restoredRaw = await fs.readFile(restoredFile);
|
|
289
|
-
const restored = transformHbcWithLayout(
|
|
311
|
+
const restored = transformHbcWithLayout(
|
|
312
|
+
restoredRaw,
|
|
313
|
+
chosenPair.layout,
|
|
314
|
+
true,
|
|
315
|
+
);
|
|
290
316
|
if (
|
|
291
317
|
!restored ||
|
|
292
318
|
!newBuffer ||
|
|
@@ -315,7 +341,7 @@ async function buildStreamBundlePatch(
|
|
|
315
341
|
|
|
316
342
|
return {
|
|
317
343
|
patch: { kind: 'file', path: patchFile },
|
|
318
|
-
...(
|
|
344
|
+
...(chosenPair ? { hbcTransform: chosenPair.meta } : {}),
|
|
319
345
|
};
|
|
320
346
|
}
|
|
321
347
|
|
package/src/locales/en.ts
CHANGED
|
@@ -87,6 +87,10 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
87
87
|
nativeVersion: 'Native Version',
|
|
88
88
|
nativeVersionNotFoundGte: 'No native version found >= {{version}}',
|
|
89
89
|
nativeVersionNotFoundLte: 'No native version found <= {{version}}',
|
|
90
|
+
nativeVersionNotFoundBetween:
|
|
91
|
+
'No native version found between {{min}} and {{max}}',
|
|
92
|
+
conflictingPackageSelectors:
|
|
93
|
+
'Only one of packageId / packageVersion / packageVersionRange / minPackageVersion+maxPackageVersion can be used at a time',
|
|
90
94
|
nativeVersionNotFoundMatch: 'No matching native version found: {{version}}',
|
|
91
95
|
nativePackageIdNotFound: 'No native package id found: {{id}}',
|
|
92
96
|
noPackagesFound: 'No packages found. (appId: {{appId}})',
|
package/src/locales/zh.ts
CHANGED
|
@@ -81,6 +81,9 @@ export default {
|
|
|
81
81
|
nativeVersion: '原生版本',
|
|
82
82
|
nativeVersionNotFoundGte: '未查询到 >= {{version}} 的原生版本',
|
|
83
83
|
nativeVersionNotFoundLte: '未查询到 <= {{version}} 的原生版本',
|
|
84
|
+
nativeVersionNotFoundBetween: '未查询到 {{min}} 至 {{max}} 之间的原生版本',
|
|
85
|
+
conflictingPackageSelectors:
|
|
86
|
+
'packageId / packageVersion / packageVersionRange / minPackageVersion+maxPackageVersion 只能使用其中一组,不能混用',
|
|
84
87
|
nativeVersionNotFoundMatch: '未查询到匹配原生版本:{{version}}',
|
|
85
88
|
nativePackageIdNotFound: '未查询到原生包 id: {{id}}',
|
|
86
89
|
noPackagesFound: '未查询到任何原生包(appId: {{appId}})',
|
package/src/package.ts
CHANGED
|
@@ -270,10 +270,12 @@ export const packageCommands = {
|
|
|
270
270
|
}) => {
|
|
271
271
|
const source = ensureFileByExt(args[0], '.aab', 'usageUploadAab');
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
273
|
+
// private temp dir: unpredictable path, safe against symlink squatting in
|
|
274
|
+
// the shared tmpdir and against concurrent uploads of same-named AABs
|
|
275
|
+
const tempRoot = await fs.mkdtemp(
|
|
276
|
+
path.join(os.tmpdir(), 'rnu-aab-upload-'),
|
|
276
277
|
);
|
|
278
|
+
const output = path.join(tempRoot, 'universal.apk');
|
|
277
279
|
|
|
278
280
|
const includeAllSplits = parseBooleanOption(options.includeAllSplits);
|
|
279
281
|
const splits = parseCsvOption(options.splits);
|
|
@@ -289,9 +291,7 @@ export const packageCommands = {
|
|
|
289
291
|
options,
|
|
290
292
|
});
|
|
291
293
|
} finally {
|
|
292
|
-
|
|
293
|
-
await fs.remove(output);
|
|
294
|
-
}
|
|
294
|
+
await fs.remove(tempRoot);
|
|
295
295
|
}
|
|
296
296
|
},
|
|
297
297
|
uploadApp: async ({
|
package/src/provider.ts
CHANGED
|
@@ -118,6 +118,8 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
118
118
|
maxPackageVersion: options.maxPackageVersion,
|
|
119
119
|
packageVersionRange: options.packageVersionRange,
|
|
120
120
|
platform: options.platform,
|
|
121
|
+
appId: options.appId,
|
|
122
|
+
config: options.config,
|
|
121
123
|
'no-interactive': true,
|
|
122
124
|
rollout:
|
|
123
125
|
options.rollout === undefined
|
package/src/user.ts
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from 'crypto';
|
|
|
2
2
|
import { closeSession, get, post, replaceSession, saveSession } from './api';
|
|
3
3
|
import type { CommandContext } from './types';
|
|
4
4
|
import { question } from './utils';
|
|
5
|
+
import { addGitIgnore } from './utils/add-gitignore';
|
|
5
6
|
import { t } from './utils/i18n';
|
|
6
7
|
|
|
7
8
|
function md5(str: string) {
|
|
@@ -18,6 +19,9 @@ export const userCommands = {
|
|
|
18
19
|
});
|
|
19
20
|
replaceSession({ token });
|
|
20
21
|
await saveSession();
|
|
22
|
+
// make sure the token file is ignored before the user's next commit,
|
|
23
|
+
// not only when they first run `bundle`
|
|
24
|
+
addGitIgnore();
|
|
21
25
|
console.log(t('welcomeMessage', { name: info.name }));
|
|
22
26
|
},
|
|
23
27
|
logout: async (_context: CommandContext) => {
|
|
@@ -88,7 +88,14 @@ export class AabParser extends Zip {
|
|
|
88
88
|
'--overwrite',
|
|
89
89
|
...modulesArgs,
|
|
90
90
|
]);
|
|
91
|
-
} catch (
|
|
91
|
+
} catch (e) {
|
|
92
|
+
// Only fall back when bundletool itself is missing from PATH (spawn
|
|
93
|
+
// ENOENT). Any other failure (corrupt AAB, Java issues, bad args,
|
|
94
|
+
// non-zero exit) must surface as-is instead of being masked by an
|
|
95
|
+
// online npx install.
|
|
96
|
+
if ((e as NodeJS.ErrnoException)?.code !== 'ENOENT') {
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
92
99
|
// Fallback to npx node-bundletool if bundletool is not in PATH
|
|
93
100
|
// We use -y to avoid interactive prompt for installation
|
|
94
101
|
if (await needsNpxDownload()) {
|
|
@@ -140,6 +147,7 @@ export class AabParser extends Zip {
|
|
|
140
147
|
zipfile.close();
|
|
141
148
|
resolve();
|
|
142
149
|
});
|
|
150
|
+
readStream.on('error', reject);
|
|
143
151
|
writeStream.on('error', reject);
|
|
144
152
|
});
|
|
145
153
|
} else {
|
package/src/utils/index.ts
CHANGED
|
@@ -153,8 +153,11 @@ async function sha256(data: Buffer | Blob): Promise<string> {
|
|
|
153
153
|
return createHash('sha256').update(buffer).digest('hex');
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
// Anchored exact paths: unanchored/unescaped patterns also matched entries
|
|
157
|
+
// like index.android.bundle.map or .backup, and a later match would silently
|
|
158
|
+
// overwrite the real bundle, registering a wrong bundleHash.
|
|
159
|
+
export const ApkBundleFileName = /^assets\/index\.android\.bundle$/;
|
|
160
|
+
const ApkUpdateJsonName = /^res\/raw\/update\.json$/;
|
|
158
161
|
|
|
159
162
|
export async function getApkInfo(fn: string) {
|
|
160
163
|
const appInfoParser = new AppInfoParser(fn);
|
|
@@ -208,9 +211,9 @@ export async function getAppInfo(fn: string) {
|
|
|
208
211
|
// single scan (and single nested .hap extraction) for all three entries
|
|
209
212
|
const [bundleFile, updateJsonFile, metaJsonFile] =
|
|
210
213
|
await appInfoParser.parser.getEntriesFromHarmonyApp([
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
/^resources\/rawfile\/bundle\.harmony\.js$/,
|
|
215
|
+
/^resources\/rawfile\/update\.json$/,
|
|
216
|
+
/^resources\/rawfile\/meta\.json$/,
|
|
214
217
|
]);
|
|
215
218
|
if (!bundleFile) {
|
|
216
219
|
throw new Error(
|
|
@@ -244,12 +247,14 @@ export async function getAppInfo(fn: string) {
|
|
|
244
247
|
};
|
|
245
248
|
}
|
|
246
249
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
+
// lowercase because the zip reader also matches against the lowercased entry
|
|
251
|
+
// name (real IPAs use "Payload/")
|
|
252
|
+
export const IpaBundleFileName = /^payload\/[^/]+\.app\/main\.jsbundle$/;
|
|
253
|
+
const IpaUpdateJsonName = /^payload\/[^/]+\.app\/assets\/update\.json$/;
|
|
254
|
+
const IpaBuildTimeName = /^payload\/[^/]+\.app\/pushy_build_time\.txt$/;
|
|
250
255
|
// Not in root bundle when use `use_frameworks`
|
|
251
256
|
const IpaBuildTimeFrameworkName =
|
|
252
|
-
|
|
257
|
+
/^payload\/[^/]+\.app\/frameworks\/react_native_update\.framework\/pushy_build_time\.txt$/;
|
|
253
258
|
|
|
254
259
|
export async function getIpaInfo(fn: string) {
|
|
255
260
|
const appInfoParser = new AppInfoParser(fn);
|
package/src/versions.ts
CHANGED
|
@@ -606,22 +606,40 @@ export const versionCommands = {
|
|
|
606
606
|
|
|
607
607
|
let pkgsToBind: Package[] = [];
|
|
608
608
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
609
|
+
const selectorGroups = [
|
|
610
|
+
pkgId,
|
|
611
|
+
pkgVersion,
|
|
612
|
+
packageVersionRange,
|
|
613
|
+
minPkgVersion || maxPkgVersion,
|
|
614
|
+
].filter(Boolean);
|
|
615
|
+
if (selectorGroups.length > 1) {
|
|
616
|
+
throw new Error(t('conflictingPackageSelectors'));
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (minPkgVersion || maxPkgVersion) {
|
|
620
|
+
minPkgVersion = minPkgVersion && String(minPkgVersion).trim();
|
|
621
|
+
maxPkgVersion = maxPkgVersion && String(maxPkgVersion).trim();
|
|
621
622
|
pkgsToBind = allPkgs.filter((pkg: Package) => {
|
|
622
|
-
|
|
623
|
+
const aboveMin =
|
|
624
|
+
!minPkgVersion || compare(pkg.name, minPkgVersion, '>=');
|
|
625
|
+
const belowMax =
|
|
626
|
+
!maxPkgVersion || compare(pkg.name, maxPkgVersion, '<=');
|
|
627
|
+
return aboveMin && belowMax;
|
|
623
628
|
});
|
|
624
629
|
if (pkgsToBind.length === 0) {
|
|
630
|
+
if (minPkgVersion && maxPkgVersion) {
|
|
631
|
+
throw new Error(
|
|
632
|
+
t('nativeVersionNotFoundBetween', {
|
|
633
|
+
min: minPkgVersion,
|
|
634
|
+
max: maxPkgVersion,
|
|
635
|
+
}),
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
if (minPkgVersion) {
|
|
639
|
+
throw new Error(
|
|
640
|
+
t('nativeVersionNotFoundGte', { version: minPkgVersion }),
|
|
641
|
+
);
|
|
642
|
+
}
|
|
625
643
|
throw new Error(
|
|
626
644
|
t('nativeVersionNotFoundLte', { version: maxPkgVersion }),
|
|
627
645
|
);
|