react-native-update-cli 2.19.0 → 2.20.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 +4 -1
- package/lib/diff.js +219 -67
- package/lib/native-package.d.ts +17 -0
- package/lib/native-package.js +232 -0
- package/lib/package.js +26 -17
- package/lib/utils/zip-entries.d.ts +1 -0
- package/lib/utils/zip-entries.js +18 -0
- package/package.json +3 -2
- package/src/api.ts +4 -1
- package/src/diff.ts +325 -88
- package/src/native-package.ts +248 -0
- package/src/package.ts +29 -19
- package/src/utils/zip-entries.ts +22 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.resolveNativePackageEntry = resolveNativePackageEntry;
|
|
40
|
+
exports.createSlimNativePackage = createSlimNativePackage;
|
|
41
|
+
const fs = __importStar(require("fs-extra"));
|
|
42
|
+
const os_1 = __importDefault(require("os"));
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const yauzl_1 = require("yauzl");
|
|
45
|
+
const yazl_1 = require("yazl");
|
|
46
|
+
const nativePackageRules = {
|
|
47
|
+
android: {
|
|
48
|
+
resolveEntry: (entryName) => {
|
|
49
|
+
if (entryName === 'assets/index.android.bundle') {
|
|
50
|
+
return { diffPath: entryName, kind: 'bundle' };
|
|
51
|
+
}
|
|
52
|
+
if (entryName.startsWith('assets/') || entryName.startsWith('res/')) {
|
|
53
|
+
return { diffPath: entryName, kind: 'resource' };
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
ios: {
|
|
58
|
+
resolveEntry: (entryName) => {
|
|
59
|
+
const match = /^Payload\/[^/]+\.app\/(.+)$/.exec(entryName);
|
|
60
|
+
const appPath = match?.[1];
|
|
61
|
+
if (appPath === 'main.jsbundle') {
|
|
62
|
+
return { diffPath: appPath, kind: 'bundle' };
|
|
63
|
+
}
|
|
64
|
+
if (appPath?.startsWith('assets/')) {
|
|
65
|
+
return { diffPath: appPath, kind: 'resource' };
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
harmony: {
|
|
70
|
+
resolveEntry: (entryName) => {
|
|
71
|
+
if (entryName === 'resources/rawfile/bundle.harmony.js') {
|
|
72
|
+
return { diffPath: entryName, kind: 'bundle' };
|
|
73
|
+
}
|
|
74
|
+
if (entryName.startsWith('resources/rawfile/assets/')) {
|
|
75
|
+
return { diffPath: entryName, kind: 'resource' };
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Resolve an archive entry that can be used as a native-package diff origin.
|
|
82
|
+
* Upload extraction and diff indexing deliberately share this function so a
|
|
83
|
+
* file cannot be removed from the uploaded baseline while still being
|
|
84
|
+
* considered by the local diff implementation (or vice versa).
|
|
85
|
+
*/
|
|
86
|
+
function resolveNativePackageEntry(platform, entryName) {
|
|
87
|
+
return nativePackageRules[platform].resolveEntry(entryName);
|
|
88
|
+
}
|
|
89
|
+
function copyEntryToZip(sourceZip, entry, outputZip) {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
sourceZip.openReadStream(entry, (error, readStream) => {
|
|
92
|
+
if (error) {
|
|
93
|
+
reject(error);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!readStream) {
|
|
97
|
+
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
readStream.once('error', reject);
|
|
101
|
+
readStream.once('end', () => resolve());
|
|
102
|
+
outputZip.addReadStream(readStream, entry.fileName, {
|
|
103
|
+
compress: entry.compressionMethod !== 0,
|
|
104
|
+
mtime: entry.getLastModDate(),
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function extractEntryToFile(sourceZip, entry, outputPath) {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
sourceZip.openReadStream(entry, (error, readStream) => {
|
|
112
|
+
if (error) {
|
|
113
|
+
reject(error);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!readStream) {
|
|
117
|
+
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const writeStream = fs.createWriteStream(outputPath);
|
|
121
|
+
readStream.once('error', reject);
|
|
122
|
+
writeStream.once('error', reject);
|
|
123
|
+
writeStream.once('close', () => resolve());
|
|
124
|
+
readStream.pipe(writeStream);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async function filterNativePackageArchive(source, output, platform) {
|
|
129
|
+
await fs.ensureDir(path_1.default.dirname(output));
|
|
130
|
+
const scratchDir = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-native-package-entry-'));
|
|
131
|
+
const outputZip = new yazl_1.ZipFile();
|
|
132
|
+
const writePromise = new Promise((resolve, reject) => {
|
|
133
|
+
outputZip.outputStream.once('error', reject);
|
|
134
|
+
outputZip.outputStream
|
|
135
|
+
.pipe(fs.createWriteStream(output))
|
|
136
|
+
.once('error', reject)
|
|
137
|
+
.once('close', () => resolve());
|
|
138
|
+
});
|
|
139
|
+
let includedEntries = 0;
|
|
140
|
+
let includedBundles = 0;
|
|
141
|
+
let nestedArchiveIndex = 0;
|
|
142
|
+
try {
|
|
143
|
+
await new Promise((resolve, reject) => {
|
|
144
|
+
(0, yauzl_1.open)(source, { lazyEntries: true }, (openError, sourceZip) => {
|
|
145
|
+
if (openError || !sourceZip) {
|
|
146
|
+
reject(openError ?? new Error(`Unable to open zip file: ${source}`));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
let settled = false;
|
|
150
|
+
const fail = (error) => {
|
|
151
|
+
if (settled) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
settled = true;
|
|
155
|
+
sourceZip.close();
|
|
156
|
+
reject(error);
|
|
157
|
+
};
|
|
158
|
+
sourceZip.once('error', fail);
|
|
159
|
+
sourceZip.once('end', () => {
|
|
160
|
+
if (!settled) {
|
|
161
|
+
settled = true;
|
|
162
|
+
resolve();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
sourceZip.on('entry', async (entry) => {
|
|
166
|
+
try {
|
|
167
|
+
if (entry.fileName.endsWith('/')) {
|
|
168
|
+
sourceZip.readEntry();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// Harmony .app packages contain one or more nested .hap archives.
|
|
172
|
+
// Rebuild those archives recursively and keep their outer path so
|
|
173
|
+
// the slim package has the same nesting as the original package.
|
|
174
|
+
if (platform === 'harmony' &&
|
|
175
|
+
entry.fileName.toLowerCase().endsWith('.hap')) {
|
|
176
|
+
const index = nestedArchiveIndex++;
|
|
177
|
+
const nestedSource = path_1.default.join(scratchDir, `${index}.source.hap`);
|
|
178
|
+
const nestedOutput = path_1.default.join(scratchDir, `${index}.slim.hap`);
|
|
179
|
+
await extractEntryToFile(sourceZip, entry, nestedSource);
|
|
180
|
+
const nestedResult = await filterNativePackageArchive(nestedSource, nestedOutput, platform);
|
|
181
|
+
if (nestedResult.entries > 0) {
|
|
182
|
+
outputZip.addFile(nestedOutput, entry.fileName, {
|
|
183
|
+
compress: entry.compressionMethod !== 0,
|
|
184
|
+
mtime: entry.getLastModDate(),
|
|
185
|
+
});
|
|
186
|
+
includedEntries += nestedResult.entries;
|
|
187
|
+
includedBundles += nestedResult.bundles;
|
|
188
|
+
}
|
|
189
|
+
sourceZip.readEntry();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const resolvedEntry = resolveNativePackageEntry(platform, entry.fileName);
|
|
193
|
+
if (resolvedEntry) {
|
|
194
|
+
await copyEntryToZip(sourceZip, entry, outputZip);
|
|
195
|
+
includedEntries += 1;
|
|
196
|
+
if (resolvedEntry.kind === 'bundle') {
|
|
197
|
+
includedBundles += 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
sourceZip.readEntry();
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
fail(error);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
sourceZip.readEntry();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
outputZip.end();
|
|
210
|
+
await writePromise;
|
|
211
|
+
return { bundles: includedBundles, entries: includedEntries };
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
outputZip.end();
|
|
215
|
+
await writePromise.catch(() => { });
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
finally {
|
|
219
|
+
await fs.remove(scratchDir);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Repack a native package with only the bundle and resources required by
|
|
224
|
+
* package-origin diffs. Entry names and nested Harmony HAP structure are kept.
|
|
225
|
+
*/
|
|
226
|
+
async function createSlimNativePackage(source, output, platform) {
|
|
227
|
+
const result = await filterNativePackageArchive(source, output, platform);
|
|
228
|
+
if (result.bundles === 0) {
|
|
229
|
+
await fs.remove(output);
|
|
230
|
+
throw new Error(`Bundle entry not found in native package: ${source}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
package/lib/package.js
CHANGED
|
@@ -46,6 +46,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
46
46
|
const tty_table_1 = __importDefault(require("tty-table"));
|
|
47
47
|
const api_1 = require("./api");
|
|
48
48
|
const app_1 = require("./app");
|
|
49
|
+
const native_package_1 = require("./native-package");
|
|
49
50
|
const utils_1 = require("./utils");
|
|
50
51
|
const aab_1 = require("./utils/app-info-parser/aab");
|
|
51
52
|
const dep_versions_1 = require("./utils/dep-versions");
|
|
@@ -114,23 +115,31 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
114
115
|
if (customVersion !== undefined) {
|
|
115
116
|
console.log((0, i18n_1.t)('usingCustomVersion', { version: versionName }));
|
|
116
117
|
}
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
118
|
+
const tempRoot = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-native-package-upload-'));
|
|
119
|
+
const slimPackagePath = path_1.default.join(tempRoot, `package${config.extension}`);
|
|
120
|
+
try {
|
|
121
|
+
await (0, native_package_1.createSlimNativePackage)(filePath, slimPackagePath, config.platform);
|
|
122
|
+
const { hash } = await (0, api_1.uploadFile)(slimPackagePath, undefined, appId);
|
|
123
|
+
const normalizedBuildTime = config.normalizeBuildTime
|
|
124
|
+
? config.normalizeBuildTime(buildTime)
|
|
125
|
+
: buildTime;
|
|
126
|
+
const uploadBuildTime = normalizeUploadBuildTime(normalizedBuildTime);
|
|
127
|
+
const { id } = await (0, api_1.post)(`/app/${appId}/package/create`, {
|
|
128
|
+
name: versionName,
|
|
129
|
+
hash,
|
|
130
|
+
buildTime: uploadBuildTime,
|
|
131
|
+
deps: dep_versions_1.depVersions,
|
|
132
|
+
commit: await (0, git_1.getCommitInfo)(),
|
|
133
|
+
});
|
|
134
|
+
console.log((0, i18n_1.t)(config.successKey, {
|
|
135
|
+
id,
|
|
136
|
+
version: versionName,
|
|
137
|
+
buildTime: uploadBuildTime,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
await fs.remove(tempRoot);
|
|
142
|
+
}
|
|
134
143
|
}
|
|
135
144
|
async function listPackage(appId) {
|
|
136
145
|
const allPkgs = (await (0, api_1.getAllPackages)(appId)) || [];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Entry, type ZipFile as YauzlZipFile } from 'yauzl';
|
|
2
2
|
export declare function readEntry(entry: Entry, zipFile: YauzlZipFile): Promise<Buffer>;
|
|
3
|
+
export declare function writeEntry(entry: Entry, zipFile: YauzlZipFile, outputPath: string): Promise<void>;
|
|
3
4
|
export declare function readEntryPrefix(entry: Entry, zipFile: YauzlZipFile, maxBytes: number): Promise<Buffer>;
|
|
4
5
|
export declare function enumZipEntries(zipFn: string, callback: (entry: Entry, zipFile: YauzlZipFile, nestedPath?: string) => Promise<any> | undefined, nestedPath?: string): Promise<unknown>;
|
package/lib/utils/zip-entries.js
CHANGED
|
@@ -37,11 +37,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.readEntry = readEntry;
|
|
40
|
+
exports.writeEntry = writeEntry;
|
|
40
41
|
exports.readEntryPrefix = readEntryPrefix;
|
|
41
42
|
exports.enumZipEntries = enumZipEntries;
|
|
42
43
|
const fs = __importStar(require("fs-extra"));
|
|
43
44
|
const os_1 = __importDefault(require("os"));
|
|
44
45
|
const path_1 = __importDefault(require("path"));
|
|
46
|
+
const promises_1 = require("stream/promises");
|
|
45
47
|
const yauzl_1 = require("yauzl");
|
|
46
48
|
const i18n_1 = require("./i18n");
|
|
47
49
|
function readEntry(entry, zipFile) {
|
|
@@ -66,6 +68,22 @@ function readEntry(entry, zipFile) {
|
|
|
66
68
|
});
|
|
67
69
|
});
|
|
68
70
|
}
|
|
71
|
+
function writeEntry(entry, zipFile, outputPath) {
|
|
72
|
+
fs.ensureDirSync(path_1.default.dirname(outputPath));
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
zipFile.openReadStream(entry, (err, stream) => {
|
|
75
|
+
if (err) {
|
|
76
|
+
reject(err);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!stream) {
|
|
80
|
+
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
(0, promises_1.pipeline)(stream, fs.createWriteStream(outputPath)).then(resolve, reject);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
69
87
|
function readEntryPrefix(entry, zipFile, maxBytes) {
|
|
70
88
|
if (maxBytes <= 0) {
|
|
71
89
|
return Promise.resolve(Buffer.alloc(0));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.1",
|
|
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",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"lint": "bun run typecheck && biome check .",
|
|
40
40
|
"lint:fix": "bun run typecheck && biome check --write .",
|
|
41
41
|
"test": "bun test",
|
|
42
|
-
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov"
|
|
42
|
+
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov",
|
|
43
|
+
"benchmark:diff-stream": "bun scripts/benchmark-diff-stream.ts"
|
|
43
44
|
},
|
|
44
45
|
"repository": {
|
|
45
46
|
"type": "git",
|
package/src/api.ts
CHANGED
|
@@ -260,7 +260,10 @@ export async function uploadFile(
|
|
|
260
260
|
method: 'PUT',
|
|
261
261
|
body: fileStream,
|
|
262
262
|
// 预签名 PUT 不接受 chunked 传输,必须显式声明长度
|
|
263
|
-
headers: {
|
|
263
|
+
headers: {
|
|
264
|
+
'content-length': String(fileSize),
|
|
265
|
+
...(resp.headers || {}),
|
|
266
|
+
},
|
|
264
267
|
});
|
|
265
268
|
} catch (error) {
|
|
266
269
|
if (isProxyRelatedError(error)) {
|