react-native-update-cli 2.18.0 → 2.20.0
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.d.ts +1 -1
- package/lib/api.js +143 -134
- package/lib/app.d.ts +2 -2
- package/lib/app.js +60 -107
- package/lib/bin.js +38 -35
- package/lib/bundle-pack.js +57 -77
- package/lib/bundle-runner.js +249 -312
- package/lib/bundle.js +71 -89
- package/lib/diff.js +190 -240
- package/lib/exports.js +14 -37
- package/lib/index.js +16 -17
- package/lib/install.js +24 -37
- package/lib/locales/en.js +3 -11
- package/lib/locales/zh.js +3 -11
- package/lib/native-package.d.ts +17 -0
- package/lib/native-package.js +232 -0
- package/lib/package.js +180 -225
- package/lib/provider.js +85 -107
- package/lib/types.js +1 -3
- package/lib/user.d.ts +1 -1
- package/lib/user.js +26 -39
- package/lib/utils/add-gitignore.js +16 -29
- package/lib/utils/app-info-parser/aab.js +133 -157
- package/lib/utils/app-info-parser/apk.js +42 -39
- package/lib/utils/app-info-parser/app.js +5 -11
- package/lib/utils/app-info-parser/index.js +21 -31
- package/lib/utils/app-info-parser/ipa.js +35 -35
- package/lib/utils/app-info-parser/resource-finder.js +84 -71
- package/lib/utils/app-info-parser/utils.js +52 -77
- package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
- package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
- package/lib/utils/app-info-parser/zip.js +43 -51
- package/lib/utils/check-lockfile.js +28 -37
- package/lib/utils/check-plugin.js +16 -32
- package/lib/utils/command-result.js +7 -20
- package/lib/utils/constants.js +23 -63
- package/lib/utils/dep-versions.js +21 -27
- package/lib/utils/git.js +20 -64
- package/lib/utils/hbcTransform.js +133 -246
- package/lib/utils/http-helper.js +33 -44
- package/lib/utils/i18n.js +17 -26
- package/lib/utils/index.js +137 -179
- package/lib/utils/latest-version/index.js +128 -137
- package/lib/utils/options.js +13 -34
- package/lib/utils/plugin-config.js +43 -56
- package/lib/utils/runtime.js +50 -108
- package/lib/utils/zip-entries.js +70 -97
- package/lib/utils/zip-options.js +80 -181
- package/lib/versions.js +231 -265
- package/package.json +19 -21
- package/src/api.ts +47 -3
- package/src/diff.ts +12 -20
- package/src/native-package.ts +248 -0
- package/src/package.ts +29 -19
- package/src/user.ts +1 -1
- package/src/versions.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
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",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"cli.json"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "rm -rf lib &&
|
|
35
|
+
"build": "rm -rf lib && tsc -p tsconfig.build.json && chmod +x lib/bin.js lib/bin-cresc.js",
|
|
36
36
|
"prepublishOnly": "bun run build",
|
|
37
37
|
"typecheck": "tsc --noEmit",
|
|
38
38
|
"typecheck:build": "tsc -p tsconfig.build.json",
|
|
@@ -62,25 +62,25 @@
|
|
|
62
62
|
"bplist-parser": "^0.3.2",
|
|
63
63
|
"bytebuffer": "^5.0.1",
|
|
64
64
|
"cgbi-to-png": "^1.0.7",
|
|
65
|
-
"chalk": "
|
|
65
|
+
"chalk": "5",
|
|
66
66
|
"cli-arguments": "^0.2.1",
|
|
67
67
|
"compare-versions": "^6.1.1",
|
|
68
68
|
"filesize-parser": "^1.5.1",
|
|
69
|
-
"form-data": "^4.0.
|
|
70
|
-
"fs-extra": "^11.3.
|
|
69
|
+
"form-data": "^4.0.6",
|
|
70
|
+
"fs-extra": "^11.3.6",
|
|
71
71
|
"global-dirs": "^4.0.0",
|
|
72
72
|
"gradle-to-js": "^2.0.1",
|
|
73
|
-
"i18next": "^26.
|
|
73
|
+
"i18next": "^26.3.5",
|
|
74
74
|
"node-fetch": "^2.6.1",
|
|
75
|
-
"plist": "^
|
|
75
|
+
"plist": "^5.0.0",
|
|
76
76
|
"progress": "^2.0.3",
|
|
77
77
|
"properties": "^1.2.1",
|
|
78
|
-
"protobufjs": "^7.
|
|
78
|
+
"protobufjs": "^8.7.0",
|
|
79
79
|
"read": "^4.1.0",
|
|
80
80
|
"registry-auth-token": "^5.1.1",
|
|
81
|
-
"semver": "^7.
|
|
81
|
+
"semver": "^7.8.5",
|
|
82
82
|
"tty-table": "5.0",
|
|
83
|
-
"yauzl": "^3.
|
|
83
|
+
"yauzl": "^3.4.0",
|
|
84
84
|
"yazl": "3.3.1"
|
|
85
85
|
},
|
|
86
86
|
"overrides": {
|
|
@@ -90,23 +90,21 @@
|
|
|
90
90
|
"node": ">= 18.17.0"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@
|
|
94
|
-
"@
|
|
95
|
-
"@
|
|
96
|
-
"@types/bun": "^1.3.12",
|
|
93
|
+
"@babel/parser": "^8.0.0",
|
|
94
|
+
"@biomejs/biome": "^2.5.3",
|
|
95
|
+
"@types/bun": "^1.3.14",
|
|
97
96
|
"@types/filesize-parser": "^1.5.3",
|
|
98
97
|
"@types/fs-extra": "^11.0.4",
|
|
99
|
-
"@types/node": "^
|
|
98
|
+
"@types/node": "^26.1.1",
|
|
100
99
|
"@types/node-fetch": "^2.6.13",
|
|
101
100
|
"@types/progress": "^2.0.7",
|
|
102
101
|
"@types/semver": "^7.7.1",
|
|
103
|
-
"@types/yauzl": "^
|
|
104
|
-
"@types/yazl": "^
|
|
105
|
-
"node-hdiffpatch": "^2.
|
|
106
|
-
"typescript": "^
|
|
102
|
+
"@types/yauzl": "^3.4.0",
|
|
103
|
+
"@types/yazl": "^3.3.1",
|
|
104
|
+
"node-hdiffpatch": "^2.2.1",
|
|
105
|
+
"typescript": "^7.0.2"
|
|
107
106
|
},
|
|
108
107
|
"trustedDependencies": [
|
|
109
|
-
"@biomejs/biome"
|
|
110
|
-
"@swc/core"
|
|
108
|
+
"@biomejs/biome"
|
|
111
109
|
]
|
|
112
110
|
}
|
package/src/api.ts
CHANGED
|
@@ -4,10 +4,10 @@ import fs from 'fs';
|
|
|
4
4
|
import fetch from 'node-fetch';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import ProgressBar from 'progress';
|
|
7
|
-
import { getBaseUrl } from 'utils/http-helper';
|
|
8
7
|
import packageJson from '../package.json';
|
|
9
8
|
import type { Package, Session } from './types';
|
|
10
9
|
import { credentialFile, IS_CRESC, pricingPageUrl } from './utils/constants';
|
|
10
|
+
import { getBaseUrl } from './utils/http-helper';
|
|
11
11
|
import { t } from './utils/i18n';
|
|
12
12
|
import {
|
|
13
13
|
measureTcpLatency,
|
|
@@ -202,10 +202,18 @@ export const post = queryWithBody('POST');
|
|
|
202
202
|
export const put = queryWithBody('PUT');
|
|
203
203
|
export const doDelete = queryWithBody('DELETE');
|
|
204
204
|
|
|
205
|
-
export async function uploadFile(
|
|
206
|
-
|
|
205
|
+
export async function uploadFile(
|
|
206
|
+
fn: string,
|
|
207
|
+
key?: string,
|
|
208
|
+
appId?: string | number,
|
|
209
|
+
) {
|
|
210
|
+
// appId 用于服务端路由:绑定了自托管节点(rnu-node)的应用,
|
|
211
|
+
// 上传指令会指向节点或其对象存储
|
|
212
|
+
const resp = await post('/upload', {
|
|
207
213
|
ext: path.extname(fn),
|
|
214
|
+
...(appId ? { appId: Number(appId) } : {}),
|
|
208
215
|
});
|
|
216
|
+
const { url, backupUrl, formData, maxSize } = resp;
|
|
209
217
|
let realUrl = url;
|
|
210
218
|
if (backupUrl) {
|
|
211
219
|
if (global.USE_ACC_OSS) {
|
|
@@ -240,6 +248,42 @@ export async function uploadFile(fn: string, key?: string) {
|
|
|
240
248
|
total: fileSize,
|
|
241
249
|
});
|
|
242
250
|
|
|
251
|
+
// 自托管节点的 s3 直传:服务端下发预签名 PUT,字节直达用户的对象存储
|
|
252
|
+
if (resp.method === 'PUT') {
|
|
253
|
+
const fileStream = fs.createReadStream(fn);
|
|
254
|
+
fileStream.on('data', (data) => {
|
|
255
|
+
bar.tick(data.length);
|
|
256
|
+
});
|
|
257
|
+
let putRes: fetch.Response;
|
|
258
|
+
try {
|
|
259
|
+
putRes = await fetch(realUrl, {
|
|
260
|
+
method: 'PUT',
|
|
261
|
+
body: fileStream,
|
|
262
|
+
// 预签名 PUT 不接受 chunked 传输,必须显式声明长度
|
|
263
|
+
headers: {
|
|
264
|
+
'content-length': String(fileSize),
|
|
265
|
+
...(resp.headers || {}),
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (isProxyRelatedError(error)) {
|
|
270
|
+
const rawMessage =
|
|
271
|
+
error instanceof Error ? error.message : String(error);
|
|
272
|
+
throw new Error(
|
|
273
|
+
`${rawMessage}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
throw createRequestError(error, realUrl);
|
|
277
|
+
}
|
|
278
|
+
if (putRes.status > 299) {
|
|
279
|
+
throw createRequestError(
|
|
280
|
+
`${putRes.status}: ${putRes.statusText || 'Upload failed'}`,
|
|
281
|
+
realUrl,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return { hash: resp.key };
|
|
285
|
+
}
|
|
286
|
+
|
|
243
287
|
const form = new FormData();
|
|
244
288
|
|
|
245
289
|
for (const [k, v] of Object.entries(formData)) {
|
package/src/diff.ts
CHANGED
|
@@ -4,7 +4,8 @@ import os from 'os';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import type { Entry, ZipFile as YauzlZipFile } from 'yauzl';
|
|
6
6
|
import { ZipFile as YazlZipFile } from 'yazl';
|
|
7
|
-
import
|
|
7
|
+
import { resolveNativePackageEntry } from './native-package';
|
|
8
|
+
import type { CommandContext, Platform } from './types';
|
|
8
9
|
import { translateOptions } from './utils';
|
|
9
10
|
import { isPPKBundleFileName, scriptName, tempDir } from './utils/constants';
|
|
10
11
|
import {
|
|
@@ -51,13 +52,11 @@ type HdiffModule = {
|
|
|
51
52
|
type EntryMap = Record<string, { crc32: number; fileName: string }>;
|
|
52
53
|
type CrcMap = Record<number, string>;
|
|
53
54
|
type CopyMap = Record<string, string>;
|
|
54
|
-
type PackagePathTransform = (v: string) => string | undefined;
|
|
55
55
|
type DiffTarget =
|
|
56
56
|
| { kind: 'ppk' }
|
|
57
57
|
| {
|
|
58
58
|
kind: 'package';
|
|
59
|
-
|
|
60
|
-
transformPackagePath?: PackagePathTransform;
|
|
59
|
+
platform: Platform;
|
|
61
60
|
};
|
|
62
61
|
type DiffCommandConfig = {
|
|
63
62
|
diffFnName: string;
|
|
@@ -419,8 +418,7 @@ async function diffFromPackage(
|
|
|
419
418
|
next: string,
|
|
420
419
|
output: string,
|
|
421
420
|
diffFn: Diff,
|
|
422
|
-
|
|
423
|
-
transformPackagePath: (v: string) => string | undefined = (v: string) => v,
|
|
421
|
+
platform: Platform,
|
|
424
422
|
bundleOptions: BundleDiffOptions = {},
|
|
425
423
|
) {
|
|
426
424
|
const originEntries: Record<string, number> = {};
|
|
@@ -437,17 +435,18 @@ async function diffFromPackage(
|
|
|
437
435
|
|
|
438
436
|
await enumZipEntries(origin, async (entry, zipFile) => {
|
|
439
437
|
if (!/\/$/.test(entry.fileName)) {
|
|
440
|
-
const
|
|
441
|
-
if (!
|
|
438
|
+
const resolvedEntry = resolveNativePackageEntry(platform, entry.fileName);
|
|
439
|
+
if (!resolvedEntry) {
|
|
442
440
|
return;
|
|
443
441
|
}
|
|
442
|
+
const fn = resolvedEntry.diffPath;
|
|
444
443
|
|
|
445
444
|
//console.log(fn);
|
|
446
445
|
// isFile
|
|
447
446
|
originEntries[fn] = entry.crc32;
|
|
448
447
|
originMap[entry.crc32] = fn;
|
|
449
448
|
|
|
450
|
-
if (
|
|
449
|
+
if (resolvedEntry.kind === 'bundle') {
|
|
451
450
|
// This is source.
|
|
452
451
|
originSource = await readEntry(entry, zipFile);
|
|
453
452
|
}
|
|
@@ -625,11 +624,6 @@ function diffArgsCheck(
|
|
|
625
624
|
};
|
|
626
625
|
}
|
|
627
626
|
|
|
628
|
-
const transformIpaPackagePath: PackagePathTransform = (v) => {
|
|
629
|
-
const match = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
|
630
|
-
return match?.[1];
|
|
631
|
-
};
|
|
632
|
-
|
|
633
627
|
const createDiffCommand =
|
|
634
628
|
({ diffFnName, target }: DiffCommandConfig) =>
|
|
635
629
|
async ({ args, options }: CommandContext) => {
|
|
@@ -650,8 +644,7 @@ const createDiffCommand =
|
|
|
650
644
|
next,
|
|
651
645
|
realOutput,
|
|
652
646
|
diffFn,
|
|
653
|
-
target.
|
|
654
|
-
target.transformPackagePath,
|
|
647
|
+
target.platform,
|
|
655
648
|
bundleOptions,
|
|
656
649
|
);
|
|
657
650
|
}
|
|
@@ -668,22 +661,21 @@ export const diffCommands = {
|
|
|
668
661
|
diffFnName: 'hdiffFromApk',
|
|
669
662
|
target: {
|
|
670
663
|
kind: 'package',
|
|
671
|
-
|
|
664
|
+
platform: 'android',
|
|
672
665
|
},
|
|
673
666
|
}),
|
|
674
667
|
hdiffFromApp: createDiffCommand({
|
|
675
668
|
diffFnName: 'hdiffFromApp',
|
|
676
669
|
target: {
|
|
677
670
|
kind: 'package',
|
|
678
|
-
|
|
671
|
+
platform: 'harmony',
|
|
679
672
|
},
|
|
680
673
|
}),
|
|
681
674
|
hdiffFromIpa: createDiffCommand({
|
|
682
675
|
diffFnName: 'hdiffFromIpa',
|
|
683
676
|
target: {
|
|
684
677
|
kind: 'package',
|
|
685
|
-
|
|
686
|
-
transformPackagePath: transformIpaPackagePath,
|
|
678
|
+
platform: 'ios',
|
|
687
679
|
},
|
|
688
680
|
}),
|
|
689
681
|
};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import {
|
|
5
|
+
type Entry,
|
|
6
|
+
open as openZipFile,
|
|
7
|
+
type ZipFile as YauzlZipFile,
|
|
8
|
+
} from 'yauzl';
|
|
9
|
+
import { ZipFile as YazlZipFile } from 'yazl';
|
|
10
|
+
import type { Platform } from './types';
|
|
11
|
+
|
|
12
|
+
export type NativePackageEntry = {
|
|
13
|
+
diffPath: string;
|
|
14
|
+
kind: 'bundle' | 'resource';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type NativePackageRule = {
|
|
18
|
+
resolveEntry: (entryName: string) => NativePackageEntry | undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const nativePackageRules: Record<Platform, NativePackageRule> = {
|
|
22
|
+
android: {
|
|
23
|
+
resolveEntry: (entryName) => {
|
|
24
|
+
if (entryName === 'assets/index.android.bundle') {
|
|
25
|
+
return { diffPath: entryName, kind: 'bundle' };
|
|
26
|
+
}
|
|
27
|
+
if (entryName.startsWith('assets/') || entryName.startsWith('res/')) {
|
|
28
|
+
return { diffPath: entryName, kind: 'resource' };
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
ios: {
|
|
33
|
+
resolveEntry: (entryName) => {
|
|
34
|
+
const match = /^Payload\/[^/]+\.app\/(.+)$/.exec(entryName);
|
|
35
|
+
const appPath = match?.[1];
|
|
36
|
+
if (appPath === 'main.jsbundle') {
|
|
37
|
+
return { diffPath: appPath, kind: 'bundle' };
|
|
38
|
+
}
|
|
39
|
+
if (appPath?.startsWith('assets/')) {
|
|
40
|
+
return { diffPath: appPath, kind: 'resource' };
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
harmony: {
|
|
45
|
+
resolveEntry: (entryName) => {
|
|
46
|
+
if (entryName === 'resources/rawfile/bundle.harmony.js') {
|
|
47
|
+
return { diffPath: entryName, kind: 'bundle' };
|
|
48
|
+
}
|
|
49
|
+
if (entryName.startsWith('resources/rawfile/assets/')) {
|
|
50
|
+
return { diffPath: entryName, kind: 'resource' };
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolve an archive entry that can be used as a native-package diff origin.
|
|
58
|
+
* Upload extraction and diff indexing deliberately share this function so a
|
|
59
|
+
* file cannot be removed from the uploaded baseline while still being
|
|
60
|
+
* considered by the local diff implementation (or vice versa).
|
|
61
|
+
*/
|
|
62
|
+
export function resolveNativePackageEntry(
|
|
63
|
+
platform: Platform,
|
|
64
|
+
entryName: string,
|
|
65
|
+
): NativePackageEntry | undefined {
|
|
66
|
+
return nativePackageRules[platform].resolveEntry(entryName);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function copyEntryToZip(
|
|
70
|
+
sourceZip: YauzlZipFile,
|
|
71
|
+
entry: Entry,
|
|
72
|
+
outputZip: YazlZipFile,
|
|
73
|
+
): Promise<void> {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
sourceZip.openReadStream(entry, (error, readStream) => {
|
|
76
|
+
if (error) {
|
|
77
|
+
reject(error);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!readStream) {
|
|
81
|
+
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
readStream.once('error', reject);
|
|
86
|
+
readStream.once('end', () => resolve());
|
|
87
|
+
outputZip.addReadStream(readStream, entry.fileName, {
|
|
88
|
+
compress: entry.compressionMethod !== 0,
|
|
89
|
+
mtime: entry.getLastModDate(),
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function extractEntryToFile(
|
|
96
|
+
sourceZip: YauzlZipFile,
|
|
97
|
+
entry: Entry,
|
|
98
|
+
outputPath: string,
|
|
99
|
+
): Promise<void> {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
sourceZip.openReadStream(entry, (error, readStream) => {
|
|
102
|
+
if (error) {
|
|
103
|
+
reject(error);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (!readStream) {
|
|
107
|
+
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const writeStream = fs.createWriteStream(outputPath);
|
|
112
|
+
readStream.once('error', reject);
|
|
113
|
+
writeStream.once('error', reject);
|
|
114
|
+
writeStream.once('close', () => resolve());
|
|
115
|
+
readStream.pipe(writeStream);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function filterNativePackageArchive(
|
|
121
|
+
source: string,
|
|
122
|
+
output: string,
|
|
123
|
+
platform: Platform,
|
|
124
|
+
): Promise<{ bundles: number; entries: number }> {
|
|
125
|
+
await fs.ensureDir(path.dirname(output));
|
|
126
|
+
const scratchDir = await fs.mkdtemp(
|
|
127
|
+
path.join(os.tmpdir(), 'rnu-native-package-entry-'),
|
|
128
|
+
);
|
|
129
|
+
const outputZip = new YazlZipFile();
|
|
130
|
+
const writePromise = new Promise<void>((resolve, reject) => {
|
|
131
|
+
outputZip.outputStream.once('error', reject);
|
|
132
|
+
outputZip.outputStream
|
|
133
|
+
.pipe(fs.createWriteStream(output))
|
|
134
|
+
.once('error', reject)
|
|
135
|
+
.once('close', () => resolve());
|
|
136
|
+
});
|
|
137
|
+
let includedEntries = 0;
|
|
138
|
+
let includedBundles = 0;
|
|
139
|
+
let nestedArchiveIndex = 0;
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
await new Promise<void>((resolve, reject) => {
|
|
143
|
+
openZipFile(source, { lazyEntries: true }, (openError, sourceZip) => {
|
|
144
|
+
if (openError || !sourceZip) {
|
|
145
|
+
reject(openError ?? new Error(`Unable to open zip file: ${source}`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let settled = false;
|
|
150
|
+
const fail = (error: unknown) => {
|
|
151
|
+
if (settled) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
settled = true;
|
|
155
|
+
sourceZip.close();
|
|
156
|
+
reject(error);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
sourceZip.once('error', fail);
|
|
160
|
+
sourceZip.once('end', () => {
|
|
161
|
+
if (!settled) {
|
|
162
|
+
settled = true;
|
|
163
|
+
resolve();
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
sourceZip.on('entry', async (entry) => {
|
|
167
|
+
try {
|
|
168
|
+
if (entry.fileName.endsWith('/')) {
|
|
169
|
+
sourceZip.readEntry();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Harmony .app packages contain one or more nested .hap archives.
|
|
174
|
+
// Rebuild those archives recursively and keep their outer path so
|
|
175
|
+
// the slim package has the same nesting as the original package.
|
|
176
|
+
if (
|
|
177
|
+
platform === 'harmony' &&
|
|
178
|
+
entry.fileName.toLowerCase().endsWith('.hap')
|
|
179
|
+
) {
|
|
180
|
+
const index = nestedArchiveIndex++;
|
|
181
|
+
const nestedSource = path.join(scratchDir, `${index}.source.hap`);
|
|
182
|
+
const nestedOutput = path.join(scratchDir, `${index}.slim.hap`);
|
|
183
|
+
await extractEntryToFile(sourceZip, entry, nestedSource);
|
|
184
|
+
const nestedResult = await filterNativePackageArchive(
|
|
185
|
+
nestedSource,
|
|
186
|
+
nestedOutput,
|
|
187
|
+
platform,
|
|
188
|
+
);
|
|
189
|
+
if (nestedResult.entries > 0) {
|
|
190
|
+
outputZip.addFile(nestedOutput, entry.fileName, {
|
|
191
|
+
compress: entry.compressionMethod !== 0,
|
|
192
|
+
mtime: entry.getLastModDate(),
|
|
193
|
+
});
|
|
194
|
+
includedEntries += nestedResult.entries;
|
|
195
|
+
includedBundles += nestedResult.bundles;
|
|
196
|
+
}
|
|
197
|
+
sourceZip.readEntry();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const resolvedEntry = resolveNativePackageEntry(
|
|
202
|
+
platform,
|
|
203
|
+
entry.fileName,
|
|
204
|
+
);
|
|
205
|
+
if (resolvedEntry) {
|
|
206
|
+
await copyEntryToZip(sourceZip, entry, outputZip);
|
|
207
|
+
includedEntries += 1;
|
|
208
|
+
if (resolvedEntry.kind === 'bundle') {
|
|
209
|
+
includedBundles += 1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
sourceZip.readEntry();
|
|
213
|
+
} catch (error) {
|
|
214
|
+
fail(error);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
sourceZip.readEntry();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
outputZip.end();
|
|
223
|
+
await writePromise;
|
|
224
|
+
return { bundles: includedBundles, entries: includedEntries };
|
|
225
|
+
} catch (error) {
|
|
226
|
+
outputZip.end();
|
|
227
|
+
await writePromise.catch(() => {});
|
|
228
|
+
throw error;
|
|
229
|
+
} finally {
|
|
230
|
+
await fs.remove(scratchDir);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Repack a native package with only the bundle and resources required by
|
|
236
|
+
* package-origin diffs. Entry names and nested Harmony HAP structure are kept.
|
|
237
|
+
*/
|
|
238
|
+
export async function createSlimNativePackage(
|
|
239
|
+
source: string,
|
|
240
|
+
output: string,
|
|
241
|
+
platform: Platform,
|
|
242
|
+
): Promise<void> {
|
|
243
|
+
const result = await filterNativePackageArchive(source, output, platform);
|
|
244
|
+
if (result.bundles === 0) {
|
|
245
|
+
await fs.remove(output);
|
|
246
|
+
throw new Error(`Bundle entry not found in native package: ${source}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
package/src/package.ts
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import Table from 'tty-table';
|
|
5
5
|
import { doDelete, getAllPackages, post, uploadFile } from './api';
|
|
6
6
|
import { getPlatform, getSelectedApp } from './app';
|
|
7
|
+
import { createSlimNativePackage } from './native-package';
|
|
7
8
|
import type { Platform } from './types';
|
|
8
9
|
import {
|
|
9
10
|
getAabInfo,
|
|
@@ -141,26 +142,35 @@ async function uploadNativePackage(
|
|
|
141
142
|
console.log(t('usingCustomVersion', { version: versionName }));
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
? config.normalizeBuildTime(buildTime)
|
|
147
|
-
: buildTime;
|
|
148
|
-
const uploadBuildTime = normalizeUploadBuildTime(normalizedBuildTime);
|
|
149
|
-
|
|
150
|
-
const { id } = await post(`/app/${appId}/package/create`, {
|
|
151
|
-
name: versionName,
|
|
152
|
-
hash,
|
|
153
|
-
buildTime: uploadBuildTime,
|
|
154
|
-
deps: depVersions,
|
|
155
|
-
commit: await getCommitInfo(),
|
|
156
|
-
});
|
|
157
|
-
console.log(
|
|
158
|
-
t(config.successKey, {
|
|
159
|
-
id,
|
|
160
|
-
version: versionName,
|
|
161
|
-
buildTime: uploadBuildTime,
|
|
162
|
-
}),
|
|
145
|
+
const tempRoot = await fs.mkdtemp(
|
|
146
|
+
path.join(os.tmpdir(), 'rnu-native-package-upload-'),
|
|
163
147
|
);
|
|
148
|
+
const slimPackagePath = path.join(tempRoot, `package${config.extension}`);
|
|
149
|
+
try {
|
|
150
|
+
await createSlimNativePackage(filePath, slimPackagePath, config.platform);
|
|
151
|
+
const { hash } = await uploadFile(slimPackagePath, undefined, appId);
|
|
152
|
+
const normalizedBuildTime = config.normalizeBuildTime
|
|
153
|
+
? config.normalizeBuildTime(buildTime)
|
|
154
|
+
: buildTime;
|
|
155
|
+
const uploadBuildTime = normalizeUploadBuildTime(normalizedBuildTime);
|
|
156
|
+
|
|
157
|
+
const { id } = await post(`/app/${appId}/package/create`, {
|
|
158
|
+
name: versionName,
|
|
159
|
+
hash,
|
|
160
|
+
buildTime: uploadBuildTime,
|
|
161
|
+
deps: depVersions,
|
|
162
|
+
commit: await getCommitInfo(),
|
|
163
|
+
});
|
|
164
|
+
console.log(
|
|
165
|
+
t(config.successKey, {
|
|
166
|
+
id,
|
|
167
|
+
version: versionName,
|
|
168
|
+
buildTime: uploadBuildTime,
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
} finally {
|
|
172
|
+
await fs.remove(tempRoot);
|
|
173
|
+
}
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
export async function listPackage(appId: string) {
|
package/src/user.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
|
-
import type { CommandContext } from 'types';
|
|
3
2
|
import { closeSession, get, post, replaceSession, saveSession } from './api';
|
|
3
|
+
import type { CommandContext } from './types';
|
|
4
4
|
import { question } from './utils';
|
|
5
5
|
import { t } from './utils/i18n';
|
|
6
6
|
|
package/src/versions.ts
CHANGED
|
@@ -475,7 +475,7 @@ export const versionCommands = {
|
|
|
475
475
|
const nonInteractive =
|
|
476
476
|
getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
|
|
477
477
|
|
|
478
|
-
const { hash } = await uploadFile(fn);
|
|
478
|
+
const { hash } = await uploadFile(fn, undefined, appId);
|
|
479
479
|
|
|
480
480
|
const versionName =
|
|
481
481
|
name ||
|