react-native-update-cli 2.29.0 → 2.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/account.js +2 -4
  2. package/lib/api.d.ts +1 -1
  3. package/lib/api.js +35 -73
  4. package/lib/app.js +13 -27
  5. package/lib/auto-update.d.ts +1 -1
  6. package/lib/auto-update.js +6 -16
  7. package/lib/bin.js +4 -6
  8. package/lib/bundle-pack.js +26 -60
  9. package/lib/bundle-runner.js +89 -119
  10. package/lib/bundle.js +18 -26
  11. package/lib/diff.js +43 -133
  12. package/lib/locales/en.d.ts +0 -10
  13. package/lib/locales/en.js +0 -10
  14. package/lib/locales/zh.d.ts +0 -10
  15. package/lib/locales/zh.js +0 -10
  16. package/lib/native-package.js +27 -99
  17. package/lib/package.d.ts +6 -1
  18. package/lib/package.js +56 -108
  19. package/lib/provider.js +3 -5
  20. package/lib/symbolicate.js +1 -16
  21. package/lib/utils/add-gitignore.js +0 -1
  22. package/lib/utils/app-info-parser/aab.d.ts +5 -22
  23. package/lib/utils/app-info-parser/aab.js +89 -226
  24. package/lib/utils/app-info-parser/apk.d.ts +12 -13
  25. package/lib/utils/app-info-parser/apk.js +28 -78
  26. package/lib/utils/app-info-parser/ipa.d.ts +2 -14
  27. package/lib/utils/app-info-parser/ipa.js +9 -70
  28. package/lib/utils/app-info-parser/resource-finder.d.ts +1 -34
  29. package/lib/utils/app-info-parser/resource-finder.js +95 -234
  30. package/lib/utils/app-info-parser/xml-parser/binary.d.ts +6 -55
  31. package/lib/utils/app-info-parser/xml-parser/binary.js +152 -556
  32. package/lib/utils/app-info-parser/zip.d.ts +6 -24
  33. package/lib/utils/app-info-parser/zip.js +19 -86
  34. package/lib/utils/check-plugin.d.ts +7 -5
  35. package/lib/utils/check-plugin.js +15 -25
  36. package/lib/utils/dep-versions.d.ts +0 -6
  37. package/lib/utils/dep-versions.js +2 -27
  38. package/lib/utils/failure-fingerprint.js +3 -4
  39. package/lib/utils/fs-helpers.d.ts +18 -0
  40. package/lib/utils/fs-helpers.js +84 -0
  41. package/lib/utils/git.d.ts +0 -1
  42. package/lib/utils/git.js +0 -8
  43. package/lib/utils/hash.d.ts +3 -0
  44. package/lib/utils/hash.js +19 -0
  45. package/lib/utils/hbcTransform.d.ts +9 -2
  46. package/lib/utils/hbcTransform.js +41 -70
  47. package/lib/utils/hermes-base.d.ts +1 -5
  48. package/lib/utils/hermes-base.js +136 -196
  49. package/lib/utils/hermes-literals.d.ts +5 -3
  50. package/lib/utils/hermes-literals.js +30 -53
  51. package/lib/utils/hermes-raw.d.ts +7 -0
  52. package/lib/utils/hermes-raw.js +26 -9
  53. package/lib/utils/http-helper.d.ts +0 -1
  54. package/lib/utils/http-helper.js +0 -20
  55. package/lib/utils/i18n.js +0 -2
  56. package/lib/utils/index.d.ts +5 -19
  57. package/lib/utils/index.js +95 -189
  58. package/lib/utils/latest-version.d.ts +19 -0
  59. package/lib/utils/latest-version.js +137 -0
  60. package/lib/utils/options.d.ts +2 -1
  61. package/lib/utils/options.js +5 -7
  62. package/lib/utils/runtime.d.ts +1 -1
  63. package/lib/utils/runtime.js +2 -10
  64. package/lib/utils/upload-request.d.ts +33 -0
  65. package/lib/utils/upload-request.js +120 -0
  66. package/lib/utils/zip-entries.d.ts +23 -0
  67. package/lib/utils/zip-entries.js +130 -139
  68. package/lib/utils/zip-options.js +29 -56
  69. package/lib/utils/zip-range.js +29 -69
  70. package/lib/utils/zip-raw-writer.js +6 -5
  71. package/lib/versions.d.ts +5 -0
  72. package/lib/versions.js +86 -153
  73. package/package.json +1 -9
  74. package/lib/utils/app-info-parser/app.d.ts +0 -4
  75. package/lib/utils/app-info-parser/app.js +0 -10
  76. package/lib/utils/app-info-parser/index.d.ts +0 -16
  77. package/lib/utils/app-info-parser/index.js +0 -46
  78. package/lib/utils/app-info-parser/utils.d.ts +0 -31
  79. package/lib/utils/app-info-parser/utils.js +0 -135
  80. package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +0 -10
  81. package/lib/utils/app-info-parser/xml-parser/manifest.js +0 -202
  82. package/lib/utils/latest-version/index.d.ts +0 -149
  83. package/lib/utils/latest-version/index.js +0 -326
  84. package/lib/utils/plugin-config.d.ts +0 -9
  85. package/lib/utils/plugin-config.js +0 -61
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // Hermes re-sorts its string table by identifier frequency on every compile, so
5
5
  // any source change renumbers most string IDs and the bytecode diff explodes
6
- // (see hermes-base-bytecode-方案.md). Compiling with the previous HBC of the
6
+ // (see docs/hermes-base-verification.md). Compiling with the previous HBC of the
7
7
  // same app as `-base-bytecode` keeps old IDs stable and shrinks patches 5-30×.
8
8
  // This module resolves that base: gating by hermesc build, HBC version probe,
9
9
  // server lookup, a sha256-named local cache, download + verification, and the
@@ -49,8 +49,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.LITERAL_SEPARATOR = exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUNDLE_ENTRY_NAMES = exports.MIN_HERMES_COMPILER_COMMITLY_DATE = exports.MIN_HERMES_COMPILER_BUILD = exports.HERMES_BASE_DETAIL_MAX_CHARS = exports.PLAIN_JS_BYTECODE_VERSION = exports.HbcVersionMismatchError = exports.BundleHashMismatchError = exports.PermanentBaseError = void 0;
50
50
  exports.reportedBytecodeVersion = reportedBytecodeVersion;
51
51
  exports.classifyHermesCommand = classifyHermesCommand;
52
- exports.sha256Hex = sha256Hex;
53
- exports.sha256File = sha256File;
54
52
  exports.readFileHbcVersion = readFileHbcVersion;
55
53
  exports.probeHbcVersion = probeHbcVersion;
56
54
  exports.bundleEntryMatcher = bundleEntryMatcher;
@@ -75,14 +73,15 @@ exports.compareHermesBytecode = compareHermesBytecode;
75
73
  exports.verifyHermesBaseEquivalence = verifyHermesBaseEquivalence;
76
74
  const node_string_decoder_1 = require("node:string_decoder");
77
75
  const child_process_1 = require("child_process");
78
- const crypto_1 = require("crypto");
79
- const fs_extra_1 = __importDefault(require("fs-extra"));
76
+ const fs_1 = __importDefault(require("fs"));
80
77
  const os_1 = __importDefault(require("os"));
81
78
  const path_1 = __importDefault(require("path"));
82
79
  const stream_1 = require("stream");
83
80
  const promises_1 = require("stream/promises");
84
81
  const constants_1 = require("./constants");
85
82
  const failure_fingerprint_1 = require("./failure-fingerprint");
83
+ const fs_helpers_1 = require("./fs-helpers");
84
+ const hash_1 = require("./hash");
86
85
  const hbcTransform_1 = require("./hbcTransform");
87
86
  const hermes_cached_object_1 = require("./hermes-cached-object");
88
87
  const hermes_literals_1 = require("./hermes-literals");
@@ -130,8 +129,6 @@ function reportedBytecodeVersion(bundle) {
130
129
  const describeBytecodeVersion = (version) => version === exports.PLAIN_JS_BYTECODE_VERSION
131
130
  ? 'plain JS'
132
131
  : `HBC ${version ?? 'n/a'}`;
133
- /** bytes `getHbcVersion` needs to read the version */
134
- const HBC_HEAD_BYTES = 128;
135
132
  /** time allowed for a response to start (headers) */
136
133
  const FETCH_HEADERS_TIMEOUT_MS = 30_000;
137
134
  /** a download that receives nothing for this long is abandoned */
@@ -162,7 +159,7 @@ function classifyHermesCommand(hermesCommand) {
162
159
  const packageRoot = normalized.slice(0, match.index + match[0].length);
163
160
  let version = '';
164
161
  try {
165
- version = String(JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(packageRoot, 'package.json'), 'utf8')).version ?? '');
162
+ version = String(JSON.parse(fs_1.default.readFileSync(path_1.default.join(packageRoot, 'package.json'), 'utf8')).version ?? '');
166
163
  }
167
164
  catch {
168
165
  return {
@@ -172,47 +169,35 @@ function classifyHermesCommand(hermesCommand) {
172
169
  };
173
170
  }
174
171
  const build = /^(\d{9})\./.exec(version);
172
+ const commitly = /^0\.(\d+)\.\d+-commitly-(\d{8})/.exec(version);
173
+ const stable = /^0\.(\d+)\.\d+$/.exec(version);
174
+ let ok;
175
175
  if (build) {
176
- const ok = Number(build[1]) >= exports.MIN_HERMES_COMPILER_BUILD;
177
- return {
178
- allowed: ok,
179
- kind: 'hermes-compiler',
180
- version,
181
- reason: ok
182
- ? undefined
183
- : `hermes-compiler ${version} predates the delta-mode fix`,
184
- };
176
+ ok = Number(build[1]) >= exports.MIN_HERMES_COMPILER_BUILD;
185
177
  }
186
- const commitly = /^0\.(\d+)\.\d+-commitly-(\d{8})/.exec(version);
187
- if (commitly) {
188
- const ok = Number(commitly[1]) >= 14 &&
189
- Number(commitly[2]) >= exports.MIN_HERMES_COMPILER_COMMITLY_DATE;
190
- return {
191
- allowed: ok,
192
- kind: 'hermes-compiler',
193
- version,
194
- reason: ok
195
- ? undefined
196
- : `hermes-compiler ${version} predates the delta-mode fix`,
197
- };
178
+ else if (commitly) {
179
+ ok =
180
+ Number(commitly[1]) >= 14 &&
181
+ Number(commitly[2]) >= exports.MIN_HERMES_COMPILER_COMMITLY_DATE;
198
182
  }
199
- const stable = /^0\.(\d+)\.\d+$/.exec(version);
200
- if (stable) {
201
- const ok = Number(stable[1]) >= 14;
183
+ else if (stable) {
184
+ ok = Number(stable[1]) >= 14;
185
+ }
186
+ else {
202
187
  return {
203
- allowed: ok,
188
+ allowed: false,
204
189
  kind: 'hermes-compiler',
205
190
  version,
206
- reason: ok
207
- ? undefined
208
- : `hermes-compiler ${version} predates the delta-mode fix`,
191
+ reason: `unrecognized hermes-compiler version ${version}`,
209
192
  };
210
193
  }
211
194
  return {
212
- allowed: false,
195
+ allowed: ok,
213
196
  kind: 'hermes-compiler',
214
197
  version,
215
- reason: `unrecognized hermes-compiler version ${version}`,
198
+ reason: ok
199
+ ? undefined
200
+ : `hermes-compiler ${version} predates the delta-mode fix`,
216
201
  };
217
202
  }
218
203
  return {
@@ -224,37 +209,17 @@ function classifyHermesCommand(hermesCommand) {
224
209
  // ---------------------------------------------------------------------------
225
210
  // HBC helpers
226
211
  // ---------------------------------------------------------------------------
227
- function sha256Hex(data) {
228
- return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
229
- }
230
- /** sha256 of a file, streamed (a cached base can be tens of MB) */
231
- async function sha256File(file) {
232
- const hash = (0, crypto_1.createHash)('sha256');
233
- for await (const chunk of fs_extra_1.default.createReadStream(file))
234
- hash.update(chunk);
235
- return hash.digest('hex');
236
- }
237
212
  /** HBC version from the first bytes of a file, without reading the rest */
238
213
  async function readFileHbcVersion(file) {
239
- const header = Buffer.alloc(128);
240
- const fd = await fs_extra_1.default.open(file, 'r');
241
- try {
242
- const { bytesRead } = await fs_extra_1.default.read(fd, header, 0, 128, 0);
243
- return (0, hbcTransform_1.getHbcVersion)(header.subarray(0, bytesRead));
244
- }
245
- catch {
246
- return null;
247
- }
248
- finally {
249
- await fs_extra_1.default.close(fd);
250
- }
214
+ const info = await (0, hbcTransform_1.readHbcFileHeader)(file);
215
+ return info && (0, hbcTransform_1.getHbcVersion)(info.header);
251
216
  }
252
217
  const PROBE_CACHE_FILE = 'hbc-versions.json';
253
218
  const PROBE_CACHE_ENTRIES = 16;
254
219
  /** identity of a hermesc binary for the probe cache: path + size + mtime */
255
220
  function probeCacheKey(hermesCommand) {
256
221
  try {
257
- const stat = fs_extra_1.default.statSync(hermesCommand);
222
+ const stat = fs_1.default.statSync(hermesCommand);
258
223
  return `${path_1.default.resolve(hermesCommand)}|${stat.size}|${Math.floor(stat.mtimeMs)}`;
259
224
  }
260
225
  catch {
@@ -263,7 +228,7 @@ function probeCacheKey(hermesCommand) {
263
228
  }
264
229
  function readProbeCache() {
265
230
  try {
266
- const parsed = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), 'utf8'));
231
+ const parsed = JSON.parse(fs_1.default.readFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), 'utf8'));
267
232
  return parsed && typeof parsed === 'object' ? parsed : {};
268
233
  }
269
234
  catch {
@@ -275,8 +240,8 @@ function writeProbeCache(entries) {
275
240
  const keys = Object.keys(entries);
276
241
  // keep the most recently inserted entries only
277
242
  const trimmed = Object.fromEntries(keys.slice(-PROBE_CACHE_ENTRIES).map((key) => [key, entries[key]]));
278
- fs_extra_1.default.ensureDirSync(cacheDir());
279
- fs_extra_1.default.writeFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), JSON.stringify(trimmed));
243
+ (0, fs_helpers_1.ensureDirSync)(cacheDir());
244
+ fs_1.default.writeFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), JSON.stringify(trimmed));
280
245
  }
281
246
  catch {
282
247
  // the cache is a convenience; probing again next time is fine
@@ -303,34 +268,27 @@ function probeHbcVersion(hermesCommand) {
303
268
  }
304
269
  /** Compile an empty file to learn which HBC version this hermesc emits. */
305
270
  function compileProbe(hermesCommand) {
306
- const dir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-hermes-probe-'));
271
+ const dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-hermes-probe-'));
307
272
  try {
308
273
  const input = path_1.default.join(dir, 'probe.js');
309
274
  const output = path_1.default.join(dir, 'probe.hbc');
310
- fs_extra_1.default.writeFileSync(input, '');
275
+ fs_1.default.writeFileSync(input, '');
311
276
  const result = (0, child_process_1.spawnSync)(hermesCommand, ['-emit-binary', '-out', output, input, '-O', '-w'], {
312
277
  stdio: 'ignore',
313
278
  timeout: (0, hermes_timeout_1.hermesTimeout)(process.env.PUSHY_HERMES_PROBE_TIMEOUT_MS, 30_000),
314
279
  killSignal: 'SIGKILL',
315
280
  });
316
- if (result.status !== 0 || !fs_extra_1.default.existsSync(output)) {
281
+ if (result.status !== 0 || !fs_1.default.existsSync(output)) {
317
282
  return null;
318
283
  }
319
- const header = Buffer.alloc(128);
320
- const fd = fs_extra_1.default.openSync(output, 'r');
321
- try {
322
- fs_extra_1.default.readSync(fd, header, 0, 128, 0);
323
- }
324
- finally {
325
- fs_extra_1.default.closeSync(fd);
326
- }
327
- return (0, hbcTransform_1.getHbcVersion)(header);
284
+ // the probe output is a few hundred bytes
285
+ return (0, hbcTransform_1.getHbcVersion)(fs_1.default.readFileSync(output));
328
286
  }
329
287
  catch {
330
288
  return null;
331
289
  }
332
290
  finally {
333
- fs_extra_1.default.removeSync(dir);
291
+ (0, fs_helpers_1.removeSync)(dir);
334
292
  }
335
293
  }
336
294
  exports.BUNDLE_ENTRY_NAMES = [
@@ -362,38 +320,30 @@ async function extractBundleFromArchive(filePath) {
362
320
  ext === '.jsbundle' ||
363
321
  ext === '.bundlejs' ||
364
322
  ext === '.js') {
365
- return fs_extra_1.default.readFile(filePath);
323
+ return fs_1.default.promises.readFile(filePath);
366
324
  }
367
325
  if (ext === '.ppk' || ext === '.apk' || ext === '.ipa') {
368
- return readFirstZipEntry(filePath, bundleEntryMatcher(ext.slice(1)));
326
+ return (0, zip_entries_1.readFirstEntry)(filePath, bundleEntryMatcher(ext.slice(1)));
369
327
  }
370
328
  if (ext === '.app') {
371
- // harmony .app wraps .hap archives; reuse the existing parser
372
- const { default: AppInfoParser } = await Promise.resolve().then(() => __importStar(require('./app-info-parser')));
373
- const parser = new AppInfoParser(filePath);
374
- const [bundle] = await parser.parser.getEntriesFromHarmonyApp([
329
+ // harmony .app wraps .hap archives; readZipEntries walks into them
330
+ const { readZipEntries } = await Promise.resolve().then(() => __importStar(require('./app-info-parser/zip')));
331
+ const [bundle] = await readZipEntries(filePath, [
375
332
  /^resources\/rawfile\/bundle\.harmony\.js$/,
376
333
  ]);
377
334
  return bundle ?? null;
378
335
  }
379
336
  // unknown extension: try as zip, then as raw file
380
- const fromZip = await readFirstZipEntry(filePath, (name) => exports.BUNDLE_ENTRY_NAMES.includes(name)).catch(() => null);
381
- return fromZip ?? fs_extra_1.default.readFile(filePath);
382
- }
383
- async function readFirstZipEntry(zipPath, matches) {
384
- let found = null;
385
- await (0, zip_entries_1.enumZipEntries)(zipPath, async (entry, zipFile) => {
386
- if (!found && matches(entry.fileName)) {
387
- found = await (0, zip_entries_1.readEntry)(entry, zipFile);
388
- }
389
- });
390
- return found;
337
+ const fromZip = await (0, zip_entries_1.readFirstEntry)(filePath, (name) => exports.BUNDLE_ENTRY_NAMES.includes(name)).catch(() => null);
338
+ return fromZip ?? fs_1.default.promises.readFile(filePath);
391
339
  }
392
340
  // ---------------------------------------------------------------------------
393
341
  // cache (sha256-named bundles)
394
342
  // ---------------------------------------------------------------------------
395
343
  exports.DEFAULT_CACHE_MAX_BYTES = 500 * 1024 * 1024;
396
344
  exports.DEFAULT_CACHE_MAX_FILES = 20;
345
+ /** cache entries are named by the sha256 of their bundle */
346
+ const isBundleHash = (name) => /^[0-9a-f]{64}$/.test(name);
397
347
  function cacheDir() {
398
348
  return process.env.PUSHY_CACHE_DIR || path_1.default.join(constants_1.tempDir, 'cache');
399
349
  }
@@ -411,56 +361,56 @@ function cacheLimits(overrideMaxMb) {
411
361
  }
412
362
  /** Returns the cached bundle path when present and its sha256 still matches. */
413
363
  async function cacheLookup(bundleHash) {
414
- if (!/^[0-9a-f]{64}$/.test(bundleHash))
364
+ if (!isBundleHash(bundleHash))
415
365
  return null;
416
366
  const file = path_1.default.join(cacheDir(), bundleHash);
417
- if (!(await fs_extra_1.default.pathExists(file)))
367
+ if (!(await (0, fs_helpers_1.pathExists)(file)))
418
368
  return null;
419
- if ((await sha256File(file).catch(() => '')) !== bundleHash) {
369
+ if ((await (0, hash_1.sha256File)(file).catch(() => '')) !== bundleHash) {
420
370
  // corrupt entry: never trust cache content
421
- await fs_extra_1.default.remove(file).catch(() => { });
371
+ await (0, fs_helpers_1.remove)(file).catch(() => { });
422
372
  return null;
423
373
  }
424
374
  const now = new Date();
425
- await fs_extra_1.default.utimes(file, now, now).catch(() => { });
375
+ await fs_1.default.promises.utimes(file, now, now).catch(() => { });
426
376
  return file;
427
377
  }
428
378
  /** Store a bundle under its sha256 (LRU-evicting to the configured limits). */
429
379
  async function cachePut(bundle, maxMb, knownHash) {
430
- const bundleHash = knownHash ?? sha256Hex(bundle);
380
+ const bundleHash = knownHash ?? (0, hash_1.sha256Hex)(bundle);
431
381
  const dir = cacheDir();
432
- await fs_extra_1.default.ensureDir(dir);
382
+ await (0, fs_helpers_1.ensureDir)(dir);
433
383
  const file = path_1.default.join(dir, bundleHash);
434
- if (!(await fs_extra_1.default.pathExists(file))) {
384
+ if (!(await (0, fs_helpers_1.pathExists)(file))) {
435
385
  const tmp = `${file}.${process.pid}.tmp`;
436
- await fs_extra_1.default.writeFile(tmp, bundle);
437
- await fs_extra_1.default.rename(tmp, file);
386
+ await fs_1.default.promises.writeFile(tmp, bundle);
387
+ await fs_1.default.promises.rename(tmp, file);
438
388
  }
439
389
  else {
440
390
  const now = new Date();
441
- await fs_extra_1.default.utimes(file, now, now).catch(() => { });
391
+ await fs_1.default.promises.utimes(file, now, now).catch(() => { });
442
392
  }
443
393
  await enforceCacheLimits(maxMb, bundleHash);
444
394
  return { path: file, bundleHash };
445
395
  }
446
396
  async function enforceCacheLimits(maxMb, keep) {
447
397
  const dir = cacheDir();
448
- if (!(await fs_extra_1.default.pathExists(dir)))
398
+ if (!(await (0, fs_helpers_1.pathExists)(dir)))
449
399
  return;
450
400
  const { maxBytes, maxFiles } = cacheLimits(maxMb);
451
401
  const entries = [];
452
402
  const staleTmpCutoff = Date.now() - STALE_CACHE_TMP_MS;
453
- for (const name of await fs_extra_1.default.readdir(dir)) {
403
+ for (const name of await fs_1.default.promises.readdir(dir)) {
454
404
  const isTmp = isCacheTmpName(name);
455
- if (!isTmp && !/^[0-9a-f]{64}$/.test(name))
405
+ if (!isTmp && !isBundleHash(name))
456
406
  continue;
457
- const stat = await fs_extra_1.default.stat(path_1.default.join(dir, name)).catch(() => null);
407
+ const stat = await fs_1.default.promises.stat(path_1.default.join(dir, name)).catch(() => null);
458
408
  if (!stat?.isFile())
459
409
  continue;
460
410
  if (isTmp) {
461
411
  // an interrupted cachePut; nothing will ever rename it into place
462
412
  if (stat.mtimeMs < staleTmpCutoff)
463
- await fs_extra_1.default.remove(path_1.default.join(dir, name)).catch(() => { });
413
+ await (0, fs_helpers_1.remove)(path_1.default.join(dir, name)).catch(() => { });
464
414
  continue;
465
415
  }
466
416
  entries.push({ name, size: stat.size, mtime: stat.mtimeMs });
@@ -472,7 +422,7 @@ async function enforceCacheLimits(maxMb, keep) {
472
422
  total += entry.size;
473
423
  count += 1;
474
424
  if (entry.name !== keep && (total > maxBytes || count > maxFiles)) {
475
- await fs_extra_1.default.remove(path_1.default.join(dir, entry.name)).catch(() => { });
425
+ await (0, fs_helpers_1.remove)(path_1.default.join(dir, entry.name)).catch(() => { });
476
426
  }
477
427
  }
478
428
  }
@@ -483,14 +433,14 @@ function isCacheTmpName(name) {
483
433
  /** Remove every cached bundle (and staging leftovers); returns the bundle count. */
484
434
  async function cleanCache() {
485
435
  const dir = cacheDir();
486
- if (!(await fs_extra_1.default.pathExists(dir)))
436
+ if (!(await (0, fs_helpers_1.pathExists)(dir)))
487
437
  return 0;
488
438
  let bundles = 0;
489
- for (const name of await fs_extra_1.default.readdir(dir)) {
490
- const isBundle = /^[0-9a-f]{64}$/.test(name);
439
+ for (const name of await fs_1.default.promises.readdir(dir)) {
440
+ const isBundle = isBundleHash(name);
491
441
  if (!isBundle && !isCacheTmpName(name))
492
442
  continue;
493
- await fs_extra_1.default.remove(path_1.default.join(dir, name));
443
+ await (0, fs_helpers_1.remove)(path_1.default.join(dir, name));
494
444
  if (isBundle)
495
445
  bundles += 1;
496
446
  }
@@ -500,11 +450,13 @@ async function cacheStats() {
500
450
  const dir = cacheDir();
501
451
  let files = 0;
502
452
  let bytes = 0;
503
- if (await fs_extra_1.default.pathExists(dir)) {
504
- for (const name of await fs_extra_1.default.readdir(dir)) {
505
- if (!/^[0-9a-f]{64}$/.test(name))
453
+ if (await (0, fs_helpers_1.pathExists)(dir)) {
454
+ for (const name of await fs_1.default.promises.readdir(dir)) {
455
+ if (!isBundleHash(name))
506
456
  continue;
507
- const stat = await fs_extra_1.default.stat(path_1.default.join(dir, name)).catch(() => null);
457
+ const stat = await fs_1.default.promises
458
+ .stat(path_1.default.join(dir, name))
459
+ .catch(() => null);
508
460
  if (stat?.isFile()) {
509
461
  files += 1;
510
462
  bytes += stat.size;
@@ -516,14 +468,14 @@ async function cacheStats() {
516
468
  /** Remove leftovers of interrupted runs (older than 24h) from the tmp dir. */
517
469
  async function cleanStaleTmp(maxAgeMs = 24 * 60 * 60 * 1000) {
518
470
  const dir = tmpDir();
519
- if (!(await fs_extra_1.default.pathExists(dir)))
471
+ if (!(await (0, fs_helpers_1.pathExists)(dir)))
520
472
  return;
521
473
  const cutoff = Date.now() - maxAgeMs;
522
- for (const name of await fs_extra_1.default.readdir(dir)) {
474
+ for (const name of await fs_1.default.promises.readdir(dir)) {
523
475
  const file = path_1.default.join(dir, name);
524
- const stat = await fs_extra_1.default.stat(file).catch(() => null);
476
+ const stat = await fs_1.default.promises.stat(file).catch(() => null);
525
477
  if (stat && stat.mtimeMs < cutoff)
526
- await fs_extra_1.default.remove(file).catch(() => { });
478
+ await (0, fs_helpers_1.remove)(file).catch(() => { });
527
479
  }
528
480
  }
529
481
  // ---------------------------------------------------------------------------
@@ -562,7 +514,7 @@ function hasBundleLocation(record) {
562
514
  async function saveResponse(response, destination, controller = new AbortController()) {
563
515
  if (!response.body)
564
516
  throw new Error('empty response body');
565
- await fs_extra_1.default.ensureDir(path_1.default.dirname(destination));
517
+ await (0, fs_helpers_1.ensureDir)(path_1.default.dirname(destination));
566
518
  const abort = () => controller.abort(new Error(`download stalled for ${STREAM_IDLE_TIMEOUT_MS / 1000}s`));
567
519
  let idle = setTimeout(abort, STREAM_IDLE_TIMEOUT_MS);
568
520
  const watchdog = new stream_1.PassThrough({
@@ -573,7 +525,7 @@ async function saveResponse(response, destination, controller = new AbortControl
573
525
  },
574
526
  });
575
527
  try {
576
- await (0, promises_1.pipeline)(stream_1.Readable.fromWeb(response.body), watchdog, fs_extra_1.default.createWriteStream(destination), { signal: controller.signal });
528
+ await (0, promises_1.pipeline)(stream_1.Readable.fromWeb(response.body), watchdog, fs_1.default.createWriteStream(destination), { signal: controller.signal });
577
529
  }
578
530
  finally {
579
531
  clearTimeout(idle);
@@ -606,20 +558,23 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }, e
606
558
  const verified = (bundle) => {
607
559
  if (!bundle)
608
560
  throw new PermanentBaseError('bundle entry not found');
609
- const bundleHash = sha256Hex(bundle);
561
+ const bundleHash = (0, hash_1.sha256Hex)(bundle);
610
562
  if (record.bundleHash && bundleHash !== record.bundleHash) {
611
563
  throw new BundleHashMismatchError(bundleHash, record.bundleHash);
612
564
  }
613
565
  return { bundle, bundleHash };
614
566
  };
615
- const fromFullResponse = async (response) => {
567
+ const fromArchive = async () => ({
568
+ ...verified(await extractBundleFromArchive(archive)),
569
+ transport: 'full',
570
+ });
571
+ const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
572
+ // a 200 to a Range request already carries the whole archive
573
+ const rangeIgnored = async (response) => {
574
+ skip('server ignores Range');
616
575
  await saveResponse(response, archive);
617
- return {
618
- ...verified(await extractBundleFromArchive(archive)),
619
- transport: 'full',
620
- };
576
+ return fromArchive();
621
577
  };
622
- const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
623
578
  // harmony .app nests the bundle in a second zip, so a location inside the
624
579
  // outer archive is never reported for it
625
580
  if (artifactType !== 'app' && hasBundleLocation(record)) {
@@ -630,7 +585,7 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }, e
630
585
  };
631
586
  try {
632
587
  const headMatches = expectHbcVersion === undefined ||
633
- (0, hbcTransform_1.getHbcVersion)(await (0, zip_range_1.fetchZipEntryHead)(record.url, location, HBC_HEAD_BYTES)) === expectHbcVersion;
588
+ (0, hbcTransform_1.getHbcVersion)(await (0, zip_range_1.fetchZipEntryHead)(record.url, location, hbcTransform_1.HBC_HEADER_SIZE)) === expectHbcVersion;
634
589
  if (!headMatches)
635
590
  throw new StaleHeadError();
636
591
  const { data, fetchedBytes, totalBytes } = await (0, zip_range_1.fetchZipEntryData)(record.url, location);
@@ -643,8 +598,7 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }, e
643
598
  }
644
599
  catch (error) {
645
600
  if (error instanceof zip_range_1.RangeUnsupportedError) {
646
- skip('server ignores Range');
647
- return fromFullResponse(error.response);
601
+ return rangeIgnored(error.response);
648
602
  }
649
603
  // not a transport failure: the directory read below settles it
650
604
  if (!(error instanceof StaleHeadError)) {
@@ -656,13 +610,12 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }, e
656
610
  try {
657
611
  const remote = await (0, zip_range_1.openRemoteZip)(record.url);
658
612
  if (remote.kind === 'full') {
659
- skip('server ignores Range');
660
- return fromFullResponse(remote.response);
613
+ return rangeIgnored(remote.response);
661
614
  }
662
615
  const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches, remote.reader, expectHbcVersion === undefined
663
616
  ? undefined
664
617
  : {
665
- bytes: HBC_HEAD_BYTES,
618
+ bytes: hbcTransform_1.HBC_HEADER_SIZE,
666
619
  check: (head) => {
667
620
  const version = (0, hbcTransform_1.getHbcVersion)(head);
668
621
  if (version !== expectHbcVersion) {
@@ -679,8 +632,7 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }, e
679
632
  }
680
633
  catch (error) {
681
634
  if (error instanceof zip_range_1.RangeUnsupportedError) {
682
- skip('server ignores Range');
683
- return fromFullResponse(error.response);
635
+ return rangeIgnored(error.response);
684
636
  }
685
637
  // the real entry was read and is not the recorded one: final
686
638
  if (error instanceof PermanentBaseError)
@@ -689,10 +641,7 @@ async function fetchBaseBundle(record, artifactType, archive, log = () => { }, e
689
641
  }
690
642
  }
691
643
  await downloadToFile(record.url, archive);
692
- return {
693
- ...verified(await extractBundleFromArchive(archive)),
694
- transport: 'full',
695
- };
644
+ return fromArchive();
696
645
  }
697
646
  /**
698
647
  * Pick and materialize the base bundle for this compile. Returns null (with
@@ -746,11 +695,6 @@ async function resolveHermesBase(params) {
746
695
  }));
747
696
  return null;
748
697
  }
749
- const source = record?.artifactType && record.artifactType !== 'ppk'
750
- ? 'native-package'
751
- : record?.bytecodeVersion == null
752
- ? 'latest-version'
753
- : 'download';
754
698
  if (!record) {
755
699
  log((0, i18n_1.t)('hermesBaseNone', { reason: 'no published version yet' }));
756
700
  return null;
@@ -765,18 +709,18 @@ async function resolveHermesBase(params) {
765
709
  // 1. cache by bundleHash
766
710
  if (record.bundleHash) {
767
711
  const hit = await cacheLookup(record.bundleHash);
768
- if (hit && record.bytecodeVersion == null) {
769
- // the server does not know the HBC version (legacy version, native
770
- // package): the download path checks it, the cache path must too
771
- const version = await readFileHbcVersion(hit);
772
- if (version !== bytecodeVersion) {
773
- log((0, i18n_1.t)('hermesBaseNone', {
774
- reason: `cached base is HBC ${version ?? 'n/a'}, need ${bytecodeVersion}`,
775
- }));
776
- return null;
777
- }
778
- }
779
712
  if (hit) {
713
+ if (record.bytecodeVersion == null) {
714
+ // the server does not know the HBC version (legacy version, native
715
+ // package): the download path checks it, the cache path must too
716
+ const version = await readFileHbcVersion(hit);
717
+ if (version !== bytecodeVersion) {
718
+ log((0, i18n_1.t)('hermesBaseNone', {
719
+ reason: `cached base is HBC ${version ?? 'n/a'}, need ${bytecodeVersion}`,
720
+ }));
721
+ return null;
722
+ }
723
+ }
780
724
  log((0, i18n_1.t)('hermesBaseUsing', {
781
725
  source: `cache ${record.bundleHash.slice(0, 12)}${record.versionId == null ? '' : ` (version ${record.versionId})`}`,
782
726
  version: bytecodeVersion,
@@ -792,17 +736,17 @@ async function resolveHermesBase(params) {
792
736
  }
793
737
  }
794
738
  // 2. download, extract, verify, cache — transport errors get a second try
739
+ const artifactType = ['ppk', 'apk', 'ipa', 'app'].includes(record.artifactType ?? '')
740
+ ? record.artifactType
741
+ : 'ppk';
742
+ const source = record.artifactType && record.artifactType !== 'ppk'
743
+ ? 'native-package'
744
+ : record.bytecodeVersion == null
745
+ ? 'latest-version'
746
+ : 'download';
795
747
  for (let attempt = 1; attempt <= 2; attempt++) {
796
748
  const dir = tmpDir();
797
- await fs_extra_1.default.ensureDir(dir);
798
- const artifactType = [
799
- 'ppk',
800
- 'apk',
801
- 'ipa',
802
- 'app',
803
- ].includes(record.artifactType ?? '')
804
- ? record.artifactType
805
- : 'ppk';
749
+ await (0, fs_helpers_1.ensureDir)(dir);
806
750
  const archive = path_1.default.join(dir, `base-${process.pid}-${Date.now()}-${attempt}.${artifactType}`);
807
751
  try {
808
752
  log((0, i18n_1.t)('hermesBaseDownloading', { url: record.url }));
@@ -849,7 +793,7 @@ async function resolveHermesBase(params) {
849
793
  }
850
794
  }
851
795
  finally {
852
- await fs_extra_1.default.remove(archive).catch(() => { });
796
+ await (0, fs_helpers_1.remove)(archive).catch(() => { });
853
797
  }
854
798
  }
855
799
  return null;
@@ -1020,7 +964,7 @@ function normalizeDisassemblyLine(line, strings, literals) {
1020
964
  // wider form. Fold the suffix and the column padding that follows it.
1021
965
  if (opEnd > indent &&
1022
966
  (opEnd === line.length || isSpace(line.charCodeAt(opEnd)))) {
1023
- const folded = foldWidthSuffix(opcode);
967
+ const folded = (0, hermes_raw_1.foldWidthSuffix)(opcode);
1024
968
  line = `${line.slice(0, indent)}${folded}${normalizeOperandSpacing(line.slice(opEnd))}`;
1025
969
  // Switch jump tables sit after the instructions; their relative offset (and
1026
970
  // the table header hermesc prints for them) moves with instruction widths.
@@ -1092,14 +1036,6 @@ function isLetter(code) {
1092
1036
  return (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
1093
1037
  }
1094
1038
  /** strip one operand-width suffix (LongIndex, Long, Short) off an opcode */
1095
- function foldWidthSuffix(opcode) {
1096
- for (const suffix of ['LongIndex', 'Long', 'Short']) {
1097
- if (opcode.length > suffix.length && opcode.endsWith(suffix)) {
1098
- return opcode.slice(0, -suffix.length);
1099
- }
1100
- }
1101
- return opcode;
1102
- }
1103
1039
  /** Split a readable stream into lines without readline (Bun's readline async iterator misbehaves when pulled manually). */
1104
1040
  async function* streamLines(stream) {
1105
1041
  const decoder = new node_string_decoder_1.StringDecoder('utf8');
@@ -1127,9 +1063,6 @@ const TRAILER_SECTION = /^(?:Debug |Textified callees table)/;
1127
1063
  const DUMP_STDERR_KEEP = 4 * 1024;
1128
1064
  /** a diagnostic line is cut to this many characters */
1129
1065
  const DETAIL_LINE_MAX = 120;
1130
- function isFunctionHeader(line) {
1131
- return /^(?:Function|NCFunction|Constructor)</.test(line);
1132
- }
1133
1066
  /**
1134
1067
  * Structured reader over one `hermesc -dump-bytecode -pretty-disassemble`
1135
1068
  * stream. Everything before the functions is either the string table (kept
@@ -1169,7 +1102,7 @@ class DumpReader {
1169
1102
  const pass = (this.pass = new stream_1.PassThrough());
1170
1103
  proc.stdout.pipe(pass);
1171
1104
  if (dumpTo) {
1172
- const output = (this.debugOutput = fs_extra_1.default.createWriteStream(dumpTo));
1105
+ const output = (this.debugOutput = fs_1.default.createWriteStream(dumpTo));
1173
1106
  this.debugFinished = new Promise((resolve) => {
1174
1107
  output.once('finish', resolve);
1175
1108
  output.once('error', (error) => {
@@ -1224,7 +1157,7 @@ class DumpReader {
1224
1157
  const line = await this.nextLine();
1225
1158
  if (line === null)
1226
1159
  return null;
1227
- if (isFunctionHeader(line)) {
1160
+ if ((0, hermes_raw_1.isFunctionHeader)(line)) {
1228
1161
  this.inFunctions = true;
1229
1162
  return line;
1230
1163
  }
@@ -1262,14 +1195,14 @@ class DumpReader {
1262
1195
  if (header === null)
1263
1196
  return null;
1264
1197
  // a non-function header here is a trailer section: no more functions
1265
- if (!isFunctionHeader(header))
1198
+ if (!(0, hermes_raw_1.isFunctionHeader)(header))
1266
1199
  return null;
1267
1200
  const lines = [];
1268
1201
  for (;;) {
1269
1202
  const line = await this.nextLine();
1270
1203
  if (line === null)
1271
1204
  break;
1272
- if (isFunctionHeader(line) || TRAILER_SECTION.test(line)) {
1205
+ if ((0, hermes_raw_1.isFunctionHeader)(line) || TRAILER_SECTION.test(line)) {
1273
1206
  this.pending = line;
1274
1207
  break;
1275
1208
  }
@@ -1387,16 +1320,23 @@ async function compareHermesBytecode(hermesCommand, withBase, plain, options = {
1387
1320
  signal: controller.signal,
1388
1321
  killSignal: 'SIGKILL',
1389
1322
  });
1390
- // The literal buffers are read from both files up front (header + three
1391
- // byte ranges). Only when both sides can be read do the instructions
1392
- // compare decoded literals; otherwise both fall back to the dumped buffers
1393
- // as a whole, so the two sides always normalize the same way.
1394
- const [buffersA, buffersB, dataA, dataB] = await Promise.all([
1395
- (0, hermes_literals_1.readLiteralBuffers)(withBase).catch(() => null),
1396
- (0, hermes_literals_1.readLiteralBuffers)(plain).catch(() => null),
1397
- (0, hermes_raw_1.readHermesSemanticData)(withBase).catch(() => null),
1398
- (0, hermes_raw_1.readHermesSemanticData)(plain).catch(() => null),
1399
- ]);
1323
+ // Each file is read once; its literal buffers and semantic data both come
1324
+ // from those bytes. Only when both sides' buffers can be read do the
1325
+ // instructions compare decoded literals; otherwise both fall back to the
1326
+ // dumped buffers as a whole, so the two sides always normalize the same way.
1327
+ const [bytesA, bytesB] = await Promise.all([withBase, plain].map((file) => fs_1.default.promises.readFile(file).catch(() => null)));
1328
+ const orNull = (read) => {
1329
+ try {
1330
+ return read();
1331
+ }
1332
+ catch {
1333
+ return null;
1334
+ }
1335
+ };
1336
+ const buffersA = bytesA && orNull(() => (0, hermes_literals_1.literalBuffersFromBytes)(bytesA));
1337
+ const buffersB = bytesB && orNull(() => (0, hermes_literals_1.literalBuffersFromBytes)(bytesB));
1338
+ const dataA = bytesA && orNull(() => (0, hermes_raw_1.hermesSemanticData)(bytesA));
1339
+ const dataB = bytesB && orNull(() => (0, hermes_raw_1.hermesSemanticData)(bytesB));
1400
1340
  const binary = buffersA && buffersB && buffersA.version === buffersB.version;
1401
1341
  const literals = binary ? 'instruction' : 'buffer';
1402
1342
  const a = new DumpReader(spawnDump(withBase), options.dumpTo?.withBase, binary ? buffersA : null, dataA?.strings);