react-native-update-cli 2.22.7 → 2.22.9

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.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/cli.json +5 -0
  4. package/lib/api.d.ts +7 -0
  5. package/lib/api.js +106 -38
  6. package/lib/app.js +3 -2
  7. package/lib/bin.js +16 -2
  8. package/lib/bundle-runner.d.ts +11 -4
  9. package/lib/bundle-runner.js +176 -90
  10. package/lib/bundle.d.ts +1 -0
  11. package/lib/bundle.js +2 -0
  12. package/lib/diff.d.ts +9 -0
  13. package/lib/diff.js +162 -120
  14. package/lib/locales/en.d.ts +1 -0
  15. package/lib/locales/en.js +1 -0
  16. package/lib/locales/zh.d.ts +1 -0
  17. package/lib/locales/zh.js +1 -0
  18. package/lib/native-package.d.ts +5 -1
  19. package/lib/native-package.js +145 -84
  20. package/lib/package.d.ts +7 -3
  21. package/lib/package.js +22 -12
  22. package/lib/types.d.ts +2 -0
  23. package/lib/utils/dep-versions.d.ts +7 -0
  24. package/lib/utils/dep-versions.js +66 -31
  25. package/lib/utils/hbcTransform.d.ts +21 -0
  26. package/lib/utils/hbcTransform.js +146 -5
  27. package/lib/utils/hermes-base.d.ts +21 -4
  28. package/lib/utils/hermes-base.js +146 -37
  29. package/lib/utils/http-helper.d.ts +6 -1
  30. package/lib/utils/http-helper.js +23 -11
  31. package/lib/utils/index.d.ts +30 -1
  32. package/lib/utils/index.js +98 -24
  33. package/lib/utils/latest-version/index.d.ts +11 -8
  34. package/lib/utils/latest-version/index.js +91 -25
  35. package/lib/utils/zip-entries.js +20 -15
  36. package/lib/utils/zip-options.d.ts +2 -0
  37. package/lib/utils/zip-options.js +9 -4
  38. package/lib/utils/zip-range.d.ts +47 -15
  39. package/lib/utils/zip-range.js +192 -83
  40. package/lib/utils/zip-raw-writer.d.ts +47 -0
  41. package/lib/utils/zip-raw-writer.js +204 -0
  42. package/lib/versions.js +19 -9
  43. package/package.json +10 -12
  44. package/src/api.ts +126 -46
  45. package/src/app.ts +3 -2
  46. package/src/bin.ts +17 -2
  47. package/src/bundle-runner.ts +225 -113
  48. package/src/bundle.ts +3 -0
  49. package/src/diff.ts +210 -153
  50. package/src/locales/en.ts +2 -0
  51. package/src/locales/zh.ts +2 -0
  52. package/src/native-package.ts +186 -96
  53. package/src/package.ts +26 -13
  54. package/src/types.ts +2 -0
  55. package/src/utils/dep-versions.ts +76 -33
  56. package/src/utils/hbcTransform.ts +194 -5
  57. package/src/utils/hermes-base.ts +156 -45
  58. package/src/utils/http-helper.ts +24 -13
  59. package/src/utils/index.ts +136 -26
  60. package/src/utils/latest-version/index.ts +109 -33
  61. package/src/utils/zip-entries.ts +18 -16
  62. package/src/utils/zip-options.ts +8 -3
  63. package/src/utils/zip-range.ts +244 -88
  64. package/src/utils/zip-raw-writer.ts +247 -0
  65. package/src/versions.ts +17 -7
@@ -43,6 +43,7 @@ const os_1 = __importDefault(require("os"));
43
43
  const path_1 = __importDefault(require("path"));
44
44
  const yauzl_1 = require("yauzl");
45
45
  const yazl_1 = require("yazl");
46
+ const zip_raw_writer_1 = require("./utils/zip-raw-writer");
46
47
  const nativePackageRules = {
47
48
  android: {
48
49
  resolveEntry: (entryName) => {
@@ -86,23 +87,94 @@ const nativePackageRules = {
86
87
  function resolveNativePackageEntry(platform, entryName) {
87
88
  return nativePackageRules[platform].resolveEntry(entryName);
88
89
  }
89
- function copyEntryToZip(sourceZip, entry, outputZip) {
90
+ /**
91
+ * Copies each entry's stored bytes, CRC and sizes verbatim (yauzl hands out
92
+ * the raw file data with `decodeFileData: false`), so slimming a package is
93
+ * bound by disk I/O rather than by deflating every asset again.
94
+ */
95
+ class RawCopySink {
96
+ writer;
97
+ constructor(output) {
98
+ this.writer = new zip_raw_writer_1.RawZipWriter(output);
99
+ }
100
+ copyEntry(sourceZip, entry) {
101
+ return new Promise((resolve, reject) => {
102
+ sourceZip.openReadStream(entry, { decodeFileData: false }, (error, readStream) => {
103
+ if (error || !readStream) {
104
+ reject(error ?? new Error(`Unable to read zip entry: ${entry.fileName}`));
105
+ return;
106
+ }
107
+ this.writer.addRawEntry(entry, readStream).then(resolve, reject);
108
+ });
109
+ });
110
+ }
111
+ addFile(filePath, fileName, like) {
112
+ // a nested slim archive is a zip of deflated entries: storing it as-is
113
+ // loses nothing and skips another pass over its bytes
114
+ return this.writer.addStoredFile(filePath, fileName, like);
115
+ }
116
+ end() {
117
+ return this.writer.end();
118
+ }
119
+ abort() {
120
+ return this.writer.abort();
121
+ }
122
+ }
123
+ /** Re-deflates every kept entry through yazl; only for sources that need zip64. */
124
+ class RepackSink {
125
+ output;
126
+ outputZip = new yazl_1.ZipFile();
127
+ writePromise;
128
+ constructor(output) {
129
+ this.output = output;
130
+ this.writePromise = new Promise((resolve, reject) => {
131
+ this.outputZip.outputStream.once('error', reject);
132
+ this.outputZip.outputStream
133
+ .pipe(fs.createWriteStream(output))
134
+ .once('error', reject)
135
+ .once('close', () => resolve());
136
+ });
137
+ }
138
+ copyEntry(sourceZip, entry) {
139
+ return new Promise((resolve, reject) => {
140
+ sourceZip.openReadStream(entry, (error, readStream) => {
141
+ if (error || !readStream) {
142
+ reject(error ?? new Error(`Unable to read zip entry: ${entry.fileName}`));
143
+ return;
144
+ }
145
+ readStream.once('error', reject);
146
+ readStream.once('end', () => resolve());
147
+ this.outputZip.addReadStream(readStream, entry.fileName, {
148
+ compress: entry.compressionMethod !== 0,
149
+ mtime: entry.getLastModDate(),
150
+ });
151
+ });
152
+ });
153
+ }
154
+ async addFile(filePath, fileName, like) {
155
+ this.outputZip.addFile(filePath, fileName, {
156
+ compress: like.compressionMethod !== 0,
157
+ mtime: like.getLastModDate(),
158
+ });
159
+ }
160
+ async end() {
161
+ this.outputZip.end();
162
+ await this.writePromise;
163
+ }
164
+ async abort() {
165
+ this.outputZip.end();
166
+ await this.writePromise.catch(() => { });
167
+ await fs.remove(this.output).catch(() => { });
168
+ }
169
+ }
170
+ function openZip(source) {
90
171
  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}`));
172
+ (0, yauzl_1.open)(source, { lazyEntries: true }, (error, zipFile) => {
173
+ if (error || !zipFile) {
174
+ reject(error ?? new Error(`Unable to open zip file: ${source}`));
98
175
  return;
99
176
  }
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
- });
177
+ resolve(zipFile);
106
178
  });
107
179
  });
108
180
  }
@@ -125,94 +197,83 @@ function extractEntryToFile(sourceZip, entry, outputPath) {
125
197
  });
126
198
  });
127
199
  }
128
- async function filterNativePackageArchive(source, output, platform) {
200
+ async function filterNativePackageArchive(source, output, platform, options) {
129
201
  await fs.ensureDir(path_1.default.dirname(output));
130
202
  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
- });
203
+ const sourceZip = await openZip(source);
204
+ // a subset of the source never outgrows it, so the source's own size and
205
+ // entry count decide whether plain (non-zip64) headers are enough
206
+ const rawCopy = !options.repack &&
207
+ (0, zip_raw_writer_1.fitsRawZip)((await fs.stat(source)).size, sourceZip.entryCount);
208
+ const sink = rawCopy
209
+ ? new RawCopySink(output)
210
+ : new RepackSink(output);
139
211
  let includedEntries = 0;
140
212
  let includedBundles = 0;
141
213
  let nestedArchiveIndex = 0;
142
214
  try {
143
215
  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}`));
216
+ let settled = false;
217
+ const fail = (error) => {
218
+ if (settled) {
147
219
  return;
148
220
  }
149
- let settled = false;
150
- const fail = (error) => {
151
- if (settled) {
152
- return;
153
- }
221
+ settled = true;
222
+ sourceZip.close();
223
+ reject(error);
224
+ };
225
+ sourceZip.once('error', fail);
226
+ sourceZip.once('end', () => {
227
+ if (!settled) {
154
228
  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();
229
+ resolve();
230
+ }
231
+ });
232
+ sourceZip.on('entry', async (entry) => {
233
+ try {
234
+ if (entry.fileName.endsWith('/')) {
235
+ sourceZip.readEntry();
236
+ return;
163
237
  }
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
- }
238
+ // Harmony .app packages contain one or more nested .hap archives.
239
+ // Rebuild those archives recursively and keep their outer path so
240
+ // the slim package has the same nesting as the original package.
241
+ if (platform === 'harmony' &&
242
+ entry.fileName.toLowerCase().endsWith('.hap')) {
243
+ const index = nestedArchiveIndex++;
244
+ const nestedSource = path_1.default.join(scratchDir, `${index}.source.hap`);
245
+ const nestedOutput = path_1.default.join(scratchDir, `${index}.slim.hap`);
246
+ await extractEntryToFile(sourceZip, entry, nestedSource);
247
+ const nestedResult = await filterNativePackageArchive(nestedSource, nestedOutput, platform, options);
248
+ if (nestedResult.entries > 0) {
249
+ await sink.addFile(nestedOutput, entry.fileName, entry);
250
+ includedEntries += nestedResult.entries;
251
+ includedBundles += nestedResult.bundles;
199
252
  }
200
253
  sourceZip.readEntry();
254
+ return;
201
255
  }
202
- catch (error) {
203
- fail(error);
256
+ const resolvedEntry = resolveNativePackageEntry(platform, entry.fileName);
257
+ if (resolvedEntry) {
258
+ await sink.copyEntry(sourceZip, entry);
259
+ includedEntries += 1;
260
+ if (resolvedEntry.kind === 'bundle') {
261
+ includedBundles += 1;
262
+ }
204
263
  }
205
- });
206
- sourceZip.readEntry();
264
+ sourceZip.readEntry();
265
+ }
266
+ catch (error) {
267
+ fail(error);
268
+ }
207
269
  });
270
+ sourceZip.readEntry();
208
271
  });
209
- outputZip.end();
210
- await writePromise;
272
+ await sink.end();
211
273
  return { bundles: includedBundles, entries: includedEntries };
212
274
  }
213
275
  catch (error) {
214
- outputZip.end();
215
- await writePromise.catch(() => { });
276
+ await sink.abort();
216
277
  throw error;
217
278
  }
218
279
  finally {
@@ -223,8 +284,8 @@ async function filterNativePackageArchive(source, output, platform) {
223
284
  * Repack a native package with only the bundle and resources required by
224
285
  * package-origin diffs. Entry names and nested Harmony HAP structure are kept.
225
286
  */
226
- async function createSlimNativePackage(source, output, platform) {
227
- const result = await filterNativePackageArchive(source, output, platform);
287
+ async function createSlimNativePackage(source, output, platform, options = {}) {
288
+ const result = await filterNativePackageArchive(source, output, platform, options);
228
289
  if (result.bundles === 0) {
229
290
  await fs.remove(output);
230
291
  throw new Error(`Bundle entry not found in native package: ${source}`);
package/lib/package.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Platform } from './types';
1
+ import type { Package, Platform } from './types';
2
2
  type PackageCommandOptions = Record<string, unknown> & {
3
3
  appId?: string;
4
4
  appKey?: string;
@@ -12,8 +12,12 @@ type PackageCommandOptions = Record<string, unknown> & {
12
12
  output?: string;
13
13
  };
14
14
  export declare function normalizeUploadBuildTime(value: unknown): string;
15
- export declare function listPackage(appId: string): Promise<import("./types").Package[]>;
16
- export declare function choosePackage(appId: string): Promise<import("./types").Package>;
15
+ /**
16
+ * Print the app's native packages. Pass `packages` when the caller already
17
+ * fetched them (every page of the list), to skip fetching them again.
18
+ */
19
+ export declare function listPackage(appId: string, packages?: Package[]): Promise<Package[]>;
20
+ export declare function choosePackage(appId: string, packages?: Package[]): Promise<Package>;
17
21
  export declare const packageCommands: {
18
22
  uploadIpa: ({ args, options, }: {
19
23
  args: string[];
package/lib/package.js CHANGED
@@ -43,18 +43,21 @@ exports.choosePackage = choosePackage;
43
43
  const fs = __importStar(require("fs-extra"));
44
44
  const os_1 = __importDefault(require("os"));
45
45
  const path_1 = __importDefault(require("path"));
46
- const tty_table_1 = __importDefault(require("tty-table"));
47
46
  const api_1 = require("./api");
48
47
  const app_1 = require("./app");
49
48
  const native_package_1 = require("./native-package");
50
49
  const utils_1 = require("./utils");
51
- const aab_1 = require("./utils/app-info-parser/aab");
52
50
  const dep_versions_1 = require("./utils/dep-versions");
53
51
  const git_1 = require("./utils/git");
54
52
  const hermes_base_1 = require("./utils/hermes-base");
55
53
  const i18n_1 = require("./utils/i18n");
56
54
  const options_1 = require("./utils/options");
57
55
  const zip_range_1 = require("./utils/zip-range");
56
+ // the AAB parser drags in protobufjs; load it only for the aab commands
57
+ function createAabParser(source) {
58
+ const { AabParser } = require('./utils/app-info-parser/aab');
59
+ return new AabParser(source);
60
+ }
58
61
  function normalizeUploadBuildTime(value) {
59
62
  return String(value);
60
63
  }
@@ -132,8 +135,9 @@ async function uploadNativePackage(filePath, options, config) {
132
135
  : (0, zip_range_1.bundleLocationFields)(await (0, zip_range_1.locateZipEntry)(slimPackagePath, (0, hermes_base_1.bundleEntryMatcher)(config.extension.slice(1))).catch(() => null));
133
136
  if (bundleFile) {
134
137
  // keep the embedded bundle locally so a later `bundle` can use it as
135
- // hermes base without downloading it back (see hermes-base.ts)
136
- await (0, hermes_base_1.cachePut)(bundleFile).catch(() => { });
138
+ // hermes base without downloading it back (see hermes-base.ts); getInfo
139
+ // already hashed the bundle, so pass that hash instead of hashing twice
140
+ await (0, hermes_base_1.cachePut)(bundleFile, undefined, bundleHash).catch(() => { });
137
141
  }
138
142
  const normalizedBuildTime = config.normalizeBuildTime
139
143
  ? config.normalizeBuildTime(buildTime)
@@ -148,7 +152,7 @@ async function uploadNativePackage(filePath, options, config) {
148
152
  // Old servers strip unknown fields, so this is forward-compatible.
149
153
  ...(bundleHash ? { bundleHash } : {}),
150
154
  ...bundleLocation,
151
- deps: dep_versions_1.depVersions,
155
+ deps: (0, dep_versions_1.getDepVersions)(),
152
156
  commit: await (0, git_1.getCommitInfo)(),
153
157
  });
154
158
  console.log((0, i18n_1.t)(config.successKey, {
@@ -161,8 +165,12 @@ async function uploadNativePackage(filePath, options, config) {
161
165
  await fs.remove(tempRoot);
162
166
  }
163
167
  }
164
- async function listPackage(appId) {
165
- const allPkgs = (await (0, api_1.getAllPackages)(appId)) || [];
168
+ /**
169
+ * Print the app's native packages. Pass `packages` when the caller already
170
+ * fetched them (every page of the list), to skip fetching them again.
171
+ */
172
+ async function listPackage(appId, packages) {
173
+ const allPkgs = packages ?? (await (0, api_1.getAllPackages)(appId)) ?? [];
166
174
  const header = [
167
175
  { value: (0, i18n_1.t)('nativePackageId') },
168
176
  { value: (0, i18n_1.t)('nativeVersion') },
@@ -188,12 +196,14 @@ async function listPackage(appId) {
188
196
  output += versionInfo;
189
197
  rows.push([pkg.id, output]);
190
198
  }
191
- console.log((0, tty_table_1.default)(header, rows).render());
199
+ // tty-table is ~25 ms to load; only pay for it when a table is rendered
200
+ const Table = (0, utils_1.loadTtyTable)();
201
+ console.log(Table(header, rows).render());
192
202
  console.log((0, i18n_1.t)('totalPackages', { count: allPkgs.length }));
193
203
  return allPkgs;
194
204
  }
195
- async function choosePackage(appId) {
196
- const list = await listPackage(appId);
205
+ async function choosePackage(appId, packages) {
206
+ const list = await listPackage(appId, packages);
197
207
  const packageMap = new Map(list?.map((v) => [v.id.toString(), v]));
198
208
  while (true) {
199
209
  const id = await (0, utils_1.question)((0, i18n_1.t)('enterNativePackageId'));
@@ -234,7 +244,7 @@ exports.packageCommands = {
234
244
  const output = path_1.default.join(tempRoot, 'universal.apk');
235
245
  const includeAllSplits = parseBooleanOption(options.includeAllSplits);
236
246
  const splits = parseCsvOption(options.splits);
237
- const parser = new aab_1.AabParser(source);
247
+ const parser = createAabParser(source);
238
248
  try {
239
249
  await parser.extractApk(output, {
240
250
  includeAllSplits,
@@ -295,7 +305,7 @@ exports.packageCommands = {
295
305
  path_1.default.join(path_1.default.dirname(source), `${path_1.default.basename(source, path_1.default.extname(source))}.apk`);
296
306
  const includeAllSplits = parseBooleanOption(options.includeAllSplits);
297
307
  const splits = parseCsvOption(options.splits);
298
- const parser = new aab_1.AabParser(source);
308
+ const parser = createAabParser(source);
299
309
  await parser.extractApk(output, {
300
310
  includeAllSplits,
301
311
  splits,
package/lib/types.d.ts CHANGED
@@ -51,6 +51,8 @@ export interface BundleOptions {
51
51
  hermesBase?: string;
52
52
  /** run the disassembly equivalence check after a base compile (default true) */
53
53
  verifyHermesBase?: boolean;
54
+ /** pass --reset-cache to Metro (default true); false reuses its transform cache */
55
+ resetCache?: boolean;
54
56
  sentryRelease?: string;
55
57
  sentryDist?: string;
56
58
  }
@@ -1 +1,8 @@
1
+ /** Installed versions of the cwd project's dependencies, keys sorted. */
2
+ export declare function getDepVersions(): Record<string, string>;
3
+ /**
4
+ * Same data as `getDepVersions()` but as a lazily populated object, for the
5
+ * remaining property-access call sites (`depVersions['react-native']`).
6
+ * Nothing is resolved until the first property access.
7
+ */
1
8
  export declare const depVersions: Record<string, string>;
@@ -1,37 +1,72 @@
1
1
  "use strict";
2
+ // Installed versions of every dependency/devDependency of the project in cwd.
3
+ // Resolving them means reading one package.json per dependency, so this is
4
+ // done lazily (on first use) and memoized rather than at import time, which
5
+ // used to cost every command ~3-30 ms before it even parsed its arguments.
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.depVersions = void 0;
4
- let currentPackage = null;
5
- try {
6
- currentPackage = require(`${process.cwd()}/package.json`);
7
- }
8
- catch (_e) {
9
- // console.warn('No package.json file were found');
10
- }
11
- const _depVersions = {};
12
- if (currentPackage) {
13
- const depKeys = currentPackage.dependencies
14
- ? Object.keys(currentPackage.dependencies)
15
- : [];
16
- const devDepKeys = currentPackage.devDependencies
17
- ? Object.keys(currentPackage.devDependencies)
18
- : [];
19
- const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
20
- for (const dep of dedupedDeps) {
21
- try {
22
- const packageJsonPath = require.resolve(`${dep}/package.json`, {
23
- paths: [process.cwd()],
24
- });
25
- const version = require(packageJsonPath).version;
26
- _depVersions[dep] = version;
8
+ exports.getDepVersions = getDepVersions;
9
+ let cached;
10
+ function readDepVersions() {
11
+ let currentPackage = null;
12
+ try {
13
+ currentPackage = require(`${process.cwd()}/package.json`);
14
+ }
15
+ catch (_e) {
16
+ // console.warn('No package.json file were found');
17
+ }
18
+ const versions = {};
19
+ if (currentPackage) {
20
+ const depKeys = currentPackage.dependencies
21
+ ? Object.keys(currentPackage.dependencies)
22
+ : [];
23
+ const devDepKeys = currentPackage.devDependencies
24
+ ? Object.keys(currentPackage.devDependencies)
25
+ : [];
26
+ const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
27
+ for (const dep of dedupedDeps) {
28
+ try {
29
+ const packageJsonPath = require.resolve(`${dep}/package.json`, {
30
+ paths: [process.cwd()],
31
+ });
32
+ versions[dep] = require(packageJsonPath).version;
33
+ }
34
+ catch (_e) { }
27
35
  }
28
- catch (_e) { }
29
36
  }
37
+ // sorted keys: the object is sent to the server as-is and diffed
38
+ return Object.keys(versions)
39
+ .sort()
40
+ .reduce((obj, key) => {
41
+ obj[key] = versions[key];
42
+ return obj;
43
+ }, {});
30
44
  }
31
- exports.depVersions = Object.keys(_depVersions)
32
- .sort() // Sort the keys alphabetically
33
- .reduce((obj, key) => {
34
- obj[key] = _depVersions[key]; // Rebuild the object with sorted keys
35
- return obj;
36
- }, {});
37
- // console.log({ depVersions });
45
+ /** Installed versions of the cwd project's dependencies, keys sorted. */
46
+ function getDepVersions() {
47
+ if (!cached) {
48
+ cached = readDepVersions();
49
+ }
50
+ return cached;
51
+ }
52
+ /**
53
+ * Same data as `getDepVersions()` but as a lazily populated object, for the
54
+ * remaining property-access call sites (`depVersions['react-native']`).
55
+ * Nothing is resolved until the first property access.
56
+ */
57
+ exports.depVersions = new Proxy({}, {
58
+ get: (_target, key) => typeof key === 'string' ? getDepVersions()[key] : undefined,
59
+ has: (_target, key) => typeof key === 'string' && key in getDepVersions(),
60
+ ownKeys: () => Object.keys(getDepVersions()),
61
+ getOwnPropertyDescriptor: (_target, key) => {
62
+ if (typeof key !== 'string' || !(key in getDepVersions())) {
63
+ return undefined;
64
+ }
65
+ return {
66
+ value: getDepVersions()[key],
67
+ writable: false,
68
+ enumerable: true,
69
+ configurable: true,
70
+ };
71
+ },
72
+ });
@@ -67,6 +67,18 @@ export declare function transformHbc(buf: Buffer, inverse?: boolean): Buffer | n
67
67
  /** 返回该 buffer 结构上匹配的布局(候选中第一个校验通过者)。 */
68
68
  export declare function pickLayout(buf: Buffer): HbcLayout | null;
69
69
  export declare function transformHbcWithLayout(buf: Buffer, layout: HbcLayout, inverse: boolean): Buffer | null;
70
+ /**
71
+ * 原地变换:直接改写 buf,不再分配整块副本。调用方须持有 buf 的所有权
72
+ * (例如 patch() 刚返回的新 Buffer)。结构不匹配时返回 false 且 buf 不变。
73
+ */
74
+ export declare function transformHbcWithLayoutInPlace(buf: Buffer, layout: HbcLayout, inverse: boolean): boolean;
75
+ /**
76
+ * 文件版 transformHbcWithLayout:把 src 复制到 dst,再仅对含差分字段的
77
+ * 段(位于 [128, 最后一段末尾) 区间内)做定位读写改写。任一时刻内存中
78
+ * 只有一个段的内容,不会持有整个 bundle。输出与内存版逐字节一致。
79
+ * 结构不匹配时返回 false 并清理 dst。
80
+ */
81
+ export declare function transformHbcFile(src: string, dst: string, layout: HbcLayout, inverse: boolean): Promise<boolean>;
70
82
  export declare const HBC_TRANSFORM_VERSION = 1;
71
83
  export type HbcTransformMeta = {
72
84
  v: number;
@@ -83,4 +95,13 @@ export declare function tryTransformPair(oldBuf: Buffer, newBuf: Buffer): {
83
95
  layout: HbcLayout;
84
96
  meta: HbcTransformMeta;
85
97
  } | null;
98
+ /**
99
+ * tryTransformPair 的文件版:只读两侧头部即可选定布局,变换结果直接写到
100
+ * tOldPath / tNewPath,全程不把 bundle 读进内存。无可用布局时返回 null
101
+ * (不产生输出文件)。
102
+ */
103
+ export declare function tryTransformPairFiles(oldPath: string, newPath: string, tOldPath: string, tNewPath: string): Promise<{
104
+ layout: HbcLayout;
105
+ meta: HbcTransformMeta;
106
+ } | null>;
86
107
  export {};