@gfean/react-native-bundle-drop 0.9.0 → 0.11.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.
Files changed (107) hide show
  1. package/BundleDrop.podspec +17 -20
  2. package/README.md +77 -1
  3. package/android/build.gradle +4 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +20 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +4 -1
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +5 -1
  7. package/docs/native-fingerprint.md +211 -0
  8. package/expo/android/build.gradle +61 -56
  9. package/ios/BundleDropLocator.swift +12 -0
  10. package/ios/BundleDropModule.swift +31 -13
  11. package/ios/BundleDropReactContent.swift +54 -0
  12. package/ios/BundleDropStartupRecovery.swift +48 -2
  13. package/ios/BundleDropStartupRecoveryAdapter.swift +87 -30
  14. package/lib/CLI/cli.js +12 -0
  15. package/lib/CLI/scripts/doctor.js +18 -7
  16. package/lib/CLI/scripts/expo/configure-expo.js +8 -3
  17. package/lib/CLI/scripts/fingerprint-cli.d.ts +12 -0
  18. package/lib/CLI/scripts/fingerprint-cli.js +36 -0
  19. package/lib/CLI/scripts/native/write-runtime-identity.js +3 -1
  20. package/lib/CLI/scripts/sight-ota.js +12 -3
  21. package/lib/CLI/scripts/upload-cli.d.ts +3 -0
  22. package/lib/CLI/scripts/upload-cli.js +239 -107
  23. package/lib/context.js +9 -1
  24. package/lib/errors.d.ts +2 -1
  25. package/lib/errors.js +2 -1
  26. package/lib/expo/buildIdentity.d.ts +1 -1
  27. package/lib/expo/buildIdentity.js +3 -0
  28. package/lib/expo/runtimeVersion.d.ts +10 -0
  29. package/lib/expo/runtimeVersion.js +11 -9
  30. package/lib/fingerprint/client.d.ts +5 -0
  31. package/lib/fingerprint/client.js +21 -0
  32. package/lib/fingerprint/collect.d.ts +3 -0
  33. package/lib/fingerprint/collect.js +116 -0
  34. package/lib/fingerprint/config.d.ts +14 -0
  35. package/lib/fingerprint/config.js +60 -0
  36. package/lib/fingerprint/normalizeBuildNumber.d.ts +4 -0
  37. package/lib/fingerprint/normalizeBuildNumber.js +55 -0
  38. package/lib/fingerprint/normalizeIosBuildNumber.d.ts +4 -0
  39. package/lib/fingerprint/normalizeIosBuildNumber.js +62 -0
  40. package/lib/fingerprint/types.d.ts +29 -0
  41. package/lib/fingerprint/types.js +2 -0
  42. package/lib/fingerprint/worker.d.ts +1 -0
  43. package/lib/fingerprint/worker.js +24 -0
  44. package/lib/fs/installedReportHistory.d.ts +2 -0
  45. package/lib/fs/installedReportHistory.js +55 -0
  46. package/lib/loadConfig.d.ts +6 -2
  47. package/lib/manager/downloadAndInstall.d.ts +1 -0
  48. package/lib/manager/downloadAndInstall.js +4 -0
  49. package/lib/manager/pendingRollback.d.ts +11 -0
  50. package/lib/manager/pendingRollback.js +54 -0
  51. package/lib/manager/reporting.d.ts +1 -0
  52. package/lib/manager/reporting.js +23 -6
  53. package/lib/manager/updateState.d.ts +3 -0
  54. package/lib/manager/updateState.js +1 -0
  55. package/lib/metro.js +3 -0
  56. package/lib/native/bundleDropNative.d.ts +2 -0
  57. package/lib/native/bundleDropNative.js +15 -5
  58. package/lib/patch-engine/installFromPatchSet.js +1 -1
  59. package/lib/patch-engine/patchTransport.d.ts +2 -1
  60. package/lib/patch-engine/patchTransport.js +4 -2
  61. package/lib/runtime/service.d.ts +2 -1
  62. package/lib/runtime/service.js +77 -22
  63. package/lib/scripts/bundle.js +10 -0
  64. package/lib/scripts/canonicalArtifact.d.ts +3 -0
  65. package/lib/scripts/canonicalArtifact.js +3 -1
  66. package/lib/scripts/exportProject.js +11 -0
  67. package/lib/scripts/nativeBuildNumber.d.ts +9 -0
  68. package/lib/scripts/nativeBuildNumber.js +110 -0
  69. package/lib/scripts/runtimeCompatibilityMetadata.d.ts +10 -0
  70. package/lib/scripts/runtimeCompatibilityMetadata.js +13 -0
  71. package/package.json +26 -12
  72. package/third_party/expo-fingerprint/LICENSE +22 -0
  73. package/third_party/expo-fingerprint/NOTICE +5 -0
  74. package/third_party/expo-fingerprint/PROVENANCE.md +41 -0
  75. package/third_party/expo-fingerprint/build/Config.js +122 -0
  76. package/third_party/expo-fingerprint/build/Dedup.js +89 -0
  77. package/third_party/expo-fingerprint/build/ExpoConfig.js +93 -0
  78. package/third_party/expo-fingerprint/build/ExpoConfigLoader.js +201 -0
  79. package/third_party/expo-fingerprint/build/ExpoResolver.js +84 -0
  80. package/third_party/expo-fingerprint/build/Fingerprint.js +111 -0
  81. package/third_party/expo-fingerprint/build/Fingerprint.types.js +3 -0
  82. package/third_party/expo-fingerprint/build/Options.js +140 -0
  83. package/third_party/expo-fingerprint/build/Presets.js +62 -0
  84. package/third_party/expo-fingerprint/build/ProjectWorkflow.js +163 -0
  85. package/third_party/expo-fingerprint/build/Sort.js +46 -0
  86. package/third_party/expo-fingerprint/build/hash/FileHookTransform.js +42 -0
  87. package/third_party/expo-fingerprint/build/hash/Hash.js +264 -0
  88. package/third_party/expo-fingerprint/build/hash/ReactImportsPatcher.js +344 -0
  89. package/third_party/expo-fingerprint/build/index.js +23 -0
  90. package/third_party/expo-fingerprint/build/sourcer/AutolinkingConfig.js +130 -0
  91. package/third_party/expo-fingerprint/build/sourcer/Bare.js +231 -0
  92. package/third_party/expo-fingerprint/build/sourcer/Expo.js +376 -0
  93. package/third_party/expo-fingerprint/build/sourcer/Packages.js +54 -0
  94. package/third_party/expo-fingerprint/build/sourcer/PatchPackage.js +22 -0
  95. package/third_party/expo-fingerprint/build/sourcer/SourceSkips.js +79 -0
  96. package/third_party/expo-fingerprint/build/sourcer/Sourcer.js +58 -0
  97. package/third_party/expo-fingerprint/build/sourcer/Utils.js +129 -0
  98. package/third_party/expo-fingerprint/build/types/module.d.js +2 -0
  99. package/third_party/expo-fingerprint/build/utils/Concurrency.js +47 -0
  100. package/third_party/expo-fingerprint/build/utils/Env.js +28 -0
  101. package/third_party/expo-fingerprint/build/utils/Path.js +161 -0
  102. package/third_party/expo-fingerprint/build/utils/Predicates.js +6 -0
  103. package/third_party/expo-fingerprint/build/utils/Profile.js +41 -0
  104. package/third_party/expo-fingerprint/build/utils/Spawn.js +38 -0
  105. package/third_party/expo-fingerprint/build/utils/SpawnIPC.js +28 -0
  106. package/third_party/expo-fingerprint/scheme-1-contract.json +132 -0
  107. package/third_party/expo-fingerprint/upstream-files.json +37 -0
@@ -43,9 +43,12 @@ const child_process_1 = require("child_process");
43
43
  const form_data_1 = __importDefault(require("form-data"));
44
44
  const fs = __importStar(require("fs"));
45
45
  const path = __importStar(require("path"));
46
+ const perf_hooks_1 = require("perf_hooks");
47
+ const logo_1 = require("../logo");
46
48
  const ui_1 = require("../utils/ui");
47
49
  const read_xml_plist_1 = require("../utils/read-xml-plist");
48
50
  const resolve_ios_version_1 = require("../../scripts/resolve-ios-version");
51
+ const nativeBuildNumber_1 = require("../../scripts/nativeBuildNumber");
49
52
  const expo_1 = require("../../expo");
50
53
  const resolveModule_1 = require("../../scripts/resolveModule");
51
54
  const serverUrl_1 = require("../serverUrl");
@@ -62,7 +65,37 @@ const defaultUploadDependencies = () => ({
62
65
  packageRoot: path.resolve(__dirname, '..', '..', '..'),
63
66
  spawnProcess: child_process_1.spawnSync,
64
67
  resolveModule: resolveModule_1.resolveModuleFrom,
68
+ nowMs: () => perf_hooks_1.performance.now(),
65
69
  });
70
+ const MAX_RELEASE_NOTES_LENGTH = 2000;
71
+ const STAGING_SERVER_URL = 'https://api-staging.bundledrop.app';
72
+ const dashboardProjectUrl = (serverUrl, orgSlug, projectSlug) => {
73
+ const projectPath = `/organizations/${encodeURIComponent(orgSlug)}/projects/${encodeURIComponent(projectSlug)}`;
74
+ const normalizedServerUrl = (0, serverUrl_1.normalizeServerUrl)(serverUrl);
75
+ if (normalizedServerUrl === serverUrl_1.DEFAULT_SERVER_URL) {
76
+ return `https://developer.bundledrop.app${projectPath}`;
77
+ }
78
+ if (normalizedServerUrl === STAGING_SERVER_URL) {
79
+ return `https://develop.bundle-drop-web.pages.dev${projectPath}`;
80
+ }
81
+ return null;
82
+ };
83
+ const elapsedMs = (startMs, endMs) => Math.round(endMs - startMs);
84
+ const formatSeconds = (milliseconds) => `${(milliseconds / 1000).toFixed(1)}s`;
85
+ const errorMessage = (error) => error instanceof Error ? error.message : String(error);
86
+ const warnAfterUpload = (message) => {
87
+ try {
88
+ ui_1.log.warn(message);
89
+ }
90
+ catch {
91
+ try {
92
+ process.stderr.write(`Warning: ${message}\n`);
93
+ }
94
+ catch {
95
+ // Output is unavailable, but the server upload still succeeded.
96
+ }
97
+ }
98
+ };
66
99
  const assertPathInside = (targetPath, parentPath, label) => {
67
100
  const resolvedParent = path.resolve(parentPath);
68
101
  const resolvedTarget = path.resolve(targetPath);
@@ -133,12 +166,67 @@ const bareArtifactPaths = (packageRoot, platform) => {
133
166
  zipPath: path.join(outputDir, `bundle-${platform}.zip`),
134
167
  };
135
168
  };
169
+ const cleanupUploadArtifacts = (artifact, projectRoot, packageRoot, platform, isExpoProject) => {
170
+ const generatedRoot = isExpoProject
171
+ ? path.join(projectRoot, '.bundle-drop', 'artifacts')
172
+ : path.join(packageRoot, 'dist');
173
+ assertPathInside(artifact.outputDir, generatedRoot, 'Artifact output');
174
+ const cleanupFiles = [
175
+ artifact.zipPath,
176
+ artifact.metadataPath,
177
+ artifact.manifestPath,
178
+ artifact.bundlePath,
179
+ artifact.sourceMapPath,
180
+ ];
181
+ for (const file of cleanupFiles) {
182
+ if (!file)
183
+ continue;
184
+ assertPathInside(file, artifact.outputDir, 'Artifact file');
185
+ if (fs.existsSync(file))
186
+ fs.unlinkSync(file);
187
+ }
188
+ const assetsPath = path.join(artifact.outputDir, 'assets');
189
+ assertPathInside(assetsPath, artifact.outputDir, 'Artifact assets');
190
+ if (fs.existsSync(assetsPath))
191
+ fs.rmSync(assetsPath, { recursive: true, force: true });
192
+ const expoExportDirectory = artifact.expoExportDirectory ??
193
+ path.join(packageRoot, 'dist', `expo-export-${platform}`);
194
+ assertPathInside(expoExportDirectory, generatedRoot, 'Expo export');
195
+ if (fs.existsSync(expoExportDirectory)) {
196
+ fs.rmSync(expoExportDirectory, { recursive: true, force: true });
197
+ }
198
+ };
136
199
  async function runUpload(platform, options, dependencies = defaultUploadDependencies()) {
200
+ const nowMs = dependencies.nowMs ?? (() => perf_hooks_1.performance.now());
201
+ const commandStartMs = nowMs();
137
202
  console.log(); // blank line
138
203
  ui_1.log.info('🚀 React Native OTA Upload Initialized');
139
204
  const projectRoot = process.cwd();
140
205
  const artifactDir = options.artifactDir ? path.resolve(options.artifactDir) : undefined;
141
206
  prepareArtifactDirForRun(artifactDir);
207
+ if (options.releaseNotes !== undefined && options.releaseNotesFile !== undefined) {
208
+ ui_1.log.error('❌ Use either --release-notes or --release-notes-file, not both.');
209
+ process.exit(1);
210
+ }
211
+ let releaseNotes = options.releaseNotes;
212
+ if (options.releaseNotesFile !== undefined) {
213
+ const notesPath = path.resolve(projectRoot, options.releaseNotesFile);
214
+ try {
215
+ releaseNotes = fs.readFileSync(notesPath, 'utf8');
216
+ }
217
+ catch (error) {
218
+ ui_1.log.error(`❌ Cannot read release notes file ${notesPath}: ${errorMessage(error)}`);
219
+ process.exit(1);
220
+ }
221
+ if (!releaseNotes?.trim()) {
222
+ ui_1.log.error(`❌ Release notes file is empty: ${notesPath}`);
223
+ process.exit(1);
224
+ }
225
+ }
226
+ if (releaseNotes && releaseNotes.length > MAX_RELEASE_NOTES_LENGTH) {
227
+ ui_1.log.warn(`Release notes too long (${releaseNotes.length}); truncating to ${MAX_RELEASE_NOTES_LENGTH} chars.`);
228
+ releaseNotes = releaseNotes.slice(0, MAX_RELEASE_NOTES_LENGTH);
229
+ }
142
230
  const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
143
231
  //eslint-disable-next-line
144
232
  const authPath = path.join(require('os').homedir(), '.bundle-drop', 'auth.json');
@@ -175,6 +263,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
175
263
  ui_1.log.error(`❌ Missing "serverUrl", "org.slug" or "project.slug" in config\nSee ${DOCS_INSTALLATION_URL}`);
176
264
  process.exit(1);
177
265
  }
266
+ const dashboardUrl = dashboardProjectUrl(serverUrl, orgSlug, projectSlug);
178
267
  // Resolve auth token: --token flag takes priority over auth.json
179
268
  let token = options.token;
180
269
  if (!token) {
@@ -216,14 +305,9 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
216
305
  ui_1.log.label('Project', projectSlug);
217
306
  ui_1.log.label('Channel', channel);
218
307
  let version = options.version;
308
+ let parsedIosPlist;
219
309
  let expoBuildIdentity;
220
310
  const buildGradlePath = options.buildGradlePath || options.buildgradlePath;
221
- let releaseNotes = options.releaseNotes;
222
- const MAX_NOTES = 2000;
223
- if (releaseNotes && releaseNotes.length > MAX_NOTES) {
224
- ui_1.log.warn(`Release notes too long (${releaseNotes.length}); truncating to ${MAX_NOTES} chars.`);
225
- releaseNotes = releaseNotes.slice(0, MAX_NOTES);
226
- }
227
311
  const parseAndroidVersionFromGradle = (filePath) => {
228
312
  if (!fs.existsSync(filePath)) {
229
313
  ui_1.log.error(`❌ build.gradle not found at ${filePath}`);
@@ -266,6 +350,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
266
350
  }
267
351
  try {
268
352
  const parsed = await (0, read_xml_plist_1.readXmlPlist)(options.plistFile);
353
+ parsedIosPlist = parsed;
269
354
  const rawVersion = Object.prototype.hasOwnProperty.call(parsed, 'CFBundleShortVersionString')
270
355
  ? parsed.CFBundleShortVersionString
271
356
  : undefined;
@@ -310,9 +395,40 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
310
395
  ui_1.log.error('❌ Version could not be determined');
311
396
  process.exit(1);
312
397
  }
398
+ let buildNumber = null;
399
+ if (expoBuildIdentity)
400
+ buildNumber = (0, nativeBuildNumber_1.expoBuildNumber)(expoBuildIdentity);
401
+ else if (options.buildNumber === undefined) {
402
+ try {
403
+ if (platform === 'ios' && options.plistFile) {
404
+ const plist = parsedIosPlist ?? await (0, read_xml_plist_1.readXmlPlist)(options.plistFile);
405
+ buildNumber = (0, nativeBuildNumber_1.iosBuildNumber)(plist.CFBundleVersion, projectRoot);
406
+ }
407
+ else if (platform === 'android') {
408
+ buildNumber = (0, nativeBuildNumber_1.readAndroidBuildNumber)(projectRoot, buildGradlePath);
409
+ }
410
+ }
411
+ catch (error) {
412
+ ui_1.log.warn(`Build number is unavailable: ${error.message}. Continuing without build-number metadata.`);
413
+ }
414
+ }
415
+ if (options.buildNumber !== undefined) {
416
+ const explicit = (0, nativeBuildNumber_1.normalizeBuildNumber)(options.buildNumber, platform);
417
+ if (!explicit || (expoBuildIdentity && explicit !== buildNumber)) {
418
+ ui_1.log.error(expoBuildIdentity && explicit
419
+ ? '❌ --build-number does not match the resolved Expo build identity.'
420
+ : '❌ --build-number must be a valid Android versionCode or numeric iOS build number.');
421
+ process.exit(1);
422
+ }
423
+ buildNumber = explicit;
424
+ }
425
+ if (buildNumber)
426
+ ui_1.log.label('Build Number', buildNumber);
313
427
  ui_1.log.label('App Version', version);
314
428
  console.log();
429
+ console.log((0, logo_1.buildBundleDropLogo)());
315
430
  ui_1.log.arrow(`Bundling ${platform} app...`);
431
+ const bundlingStartMs = nowMs();
316
432
  const packageRoot = dependencies.packageRoot;
317
433
  const packageVersion = readPackageVersion(packageRoot);
318
434
  const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
@@ -348,6 +464,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
348
464
  env: {
349
465
  ...process.env,
350
466
  BUNDLE_DROP_APP_VERSION: version,
467
+ BUNDLE_DROP_BUILD_NUMBER: buildNumber ?? '',
351
468
  },
352
469
  });
353
470
  if (result.error)
@@ -376,6 +493,8 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
376
493
  ui_1.log.error(`❌ Bundle ZIP not found at: ${artifact.zipPath}`);
377
494
  process.exit(1);
378
495
  }
496
+ const zipSizeBytes = fs.statSync(artifact.zipPath).size;
497
+ const bundlingAndPackagingMs = elapsedMs(bundlingStartMs, nowMs());
379
498
  // Build form data
380
499
  const form = new form_data_1.default();
381
500
  form.append('orgSlug', orgSlug);
@@ -395,7 +514,9 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
395
514
  }
396
515
  form.append('file', fs.createReadStream(artifact.zipPath));
397
516
  const uploadLoader = (0, ui_1.startLoadingStatus)('Uploading bundle to server');
398
- let uploadSucceeded = false;
517
+ const uploadStartMs = nowMs();
518
+ let uploadMs = 0;
519
+ let responseData = {};
399
520
  try {
400
521
  const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
401
522
  headers: {
@@ -405,120 +526,131 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
405
526
  maxContentLength: Infinity,
406
527
  maxBodyLength: Infinity,
407
528
  });
408
- const hasSourceMap = options.sourcemap && artifact.sourceMapPath &&
409
- fs.existsSync(artifact.sourceMapPath);
410
- const result = {
411
- platform,
412
- appVersion: version,
413
- channel,
414
- orgSlug,
415
- projectSlug,
416
- runtimeVersion: res.data?.runtimeVersion ?? runtimeVersion ?? null,
417
- packageVersion: res.data?.packageVersion ?? packageVersion ?? null,
418
- bundleId: res.data?.bundleId ?? null,
419
- bundleVersion: res.data?.bundleVersion ?? null,
420
- bundleVersionLabel: res.data?.bundleVersionLabel ?? null,
421
- hash: res.data?.hash ?? null,
422
- releaseNotes: releaseNotes ?? null,
423
- author: options.author ?? null,
424
- };
425
- if (artifactDir) {
426
- try {
427
- fs.mkdirSync(artifactDir, { recursive: true });
428
- if (fs.existsSync(artifact.bundlePath)) {
429
- fs.copyFileSync(artifact.bundlePath, path.join(artifactDir, 'main.jsbundle'));
430
- result.bundlePath = path.join(artifactDir, 'main.jsbundle');
431
- }
432
- if (hasSourceMap && artifact.sourceMapPath) {
433
- fs.copyFileSync(artifact.sourceMapPath, path.join(artifactDir, 'main.jsbundle.map'));
434
- result.sourceMapPath = path.join(artifactDir, 'main.jsbundle.map');
435
- }
436
- }
437
- catch (copyErr) {
438
- ui_1.log.warn(`Upload succeeded but artifact copy failed: ${copyErr.message}`);
439
- }
440
- }
441
- uploadLoader.stop();
442
- ui_1.log.success(`✅ Upload complete`);
443
- if (result.bundleVersion != null)
444
- ui_1.log.label('Bundle Version', `${result.bundleVersion}`);
445
- if (result.bundleVersionLabel)
446
- ui_1.log.label('Bundle Label', `${result.bundleVersionLabel}`);
447
- if (result.hash)
448
- ui_1.log.label('Hash', `${result.hash}`);
449
- const resultDir = artifactDir ?? artifact.outputDir;
450
- if (!fs.existsSync(resultDir))
451
- fs.mkdirSync(resultDir, { recursive: true });
452
- const resultPath = path.join(resultDir, 'bundle-drop-result.json');
453
- fs.writeFileSync(resultPath, JSON.stringify(result, null, 2));
454
- ui_1.log.label('Result file', resultPath);
455
- if (artifactDir) {
456
- ui_1.log.label('Artifact dir', artifactDir);
457
- }
458
- uploadSucceeded = true;
529
+ uploadMs = elapsedMs(uploadStartMs, nowMs());
530
+ responseData = res.data ?? {};
459
531
  }
460
532
  catch (err) {
461
- uploadLoader.stop();
462
533
  const uploadError = stringifyUploadError(err);
463
- writeArtifactResult(artifactDir, {
464
- success: false,
465
- status: 'failed',
466
- error: uploadError,
467
- platform,
468
- appVersion: version,
469
- channel,
470
- orgSlug,
471
- projectSlug,
472
- runtimeVersion,
473
- packageVersion: packageVersion ?? null,
474
- releaseNotes: releaseNotes ?? null,
475
- author: options.author ?? null,
476
- });
534
+ try {
535
+ writeArtifactResult(artifactDir, {
536
+ success: false,
537
+ status: 'failed',
538
+ error: uploadError,
539
+ platform,
540
+ appVersion: version,
541
+ channel,
542
+ orgSlug,
543
+ projectSlug,
544
+ runtimeVersion,
545
+ buildNumber,
546
+ packageVersion: packageVersion ?? null,
547
+ releaseNotes: releaseNotes ?? null,
548
+ author: options.author ?? null,
549
+ });
550
+ }
551
+ catch (writeError) {
552
+ ui_1.log.warn(`Could not write failed upload result: ${errorMessage(writeError)}`);
553
+ }
477
554
  ui_1.log.error(`Upload failed: ${uploadError}`);
478
555
  process.exitCode = 1;
556
+ try {
557
+ cleanupUploadArtifacts(artifact, projectRoot, packageRoot, platform, isExpoProject);
558
+ }
559
+ catch (cleanupError) {
560
+ ui_1.log.warn(`Cleanup failed: ${errorMessage(cleanupError)}`);
561
+ }
479
562
  return;
480
563
  }
481
564
  finally {
482
565
  try {
483
- const generatedRoot = isExpoProject
484
- ? path.join(projectRoot, '.bundle-drop', 'artifacts')
485
- : path.join(packageRoot, 'dist');
486
- assertPathInside(artifact.outputDir, generatedRoot, 'Artifact output');
487
- const cleanupFiles = [
488
- artifact.zipPath,
489
- artifact.metadataPath,
490
- artifact.manifestPath,
491
- artifact.bundlePath,
492
- artifact.sourceMapPath,
493
- ];
494
- const assetsPath = path.join(artifact.outputDir, 'assets');
495
- const expoExportDirectory = artifact.expoExportDirectory ??
496
- path.join(packageRoot, 'dist', `expo-export-${platform}`);
497
- for (const file of cleanupFiles) {
498
- if (file) {
499
- assertPathInside(file, artifact.outputDir, 'Artifact file');
500
- if (fs.existsSync(file))
501
- fs.unlinkSync(file);
502
- }
503
- }
504
- assertPathInside(assetsPath, artifact.outputDir, 'Artifact assets');
505
- if (fs.existsSync(assetsPath)) {
506
- fs.rmSync(assetsPath, { recursive: true, force: true });
507
- }
508
- assertPathInside(expoExportDirectory, generatedRoot, 'Expo export');
509
- if (fs.existsSync(expoExportDirectory)) {
510
- fs.rmSync(expoExportDirectory, { recursive: true, force: true });
566
+ uploadLoader.stop();
567
+ }
568
+ catch (loaderError) {
569
+ warnAfterUpload(`Could not stop upload status: ${errorMessage(loaderError)}`);
570
+ }
571
+ }
572
+ const hasSourceMap = Boolean(options.sourcemap && artifact.sourceMapPath &&
573
+ fs.existsSync(artifact.sourceMapPath));
574
+ const result = {
575
+ platform,
576
+ appVersion: version,
577
+ channel,
578
+ orgSlug,
579
+ projectSlug,
580
+ runtimeVersion: responseData.runtimeVersion ?? runtimeVersion ?? null,
581
+ buildNumber: responseData.buildNumber ?? buildNumber,
582
+ packageVersion: responseData.packageVersion ?? packageVersion ?? null,
583
+ bundleId: responseData.bundleId ?? null,
584
+ bundleVersion: responseData.bundleVersion ?? null,
585
+ bundleVersionLabel: responseData.bundleVersionLabel ?? null,
586
+ hash: responseData.hash ?? null,
587
+ releaseNotes: releaseNotes ?? null,
588
+ author: options.author ?? null,
589
+ zipSizeBytes,
590
+ bundlingAndPackagingMs,
591
+ uploadMs,
592
+ dashboardUrl,
593
+ };
594
+ if (artifactDir) {
595
+ try {
596
+ fs.mkdirSync(artifactDir, { recursive: true });
597
+ if (fs.existsSync(artifact.bundlePath)) {
598
+ fs.copyFileSync(artifact.bundlePath, path.join(artifactDir, 'main.jsbundle'));
599
+ result.bundlePath = path.join(artifactDir, 'main.jsbundle');
511
600
  }
512
- if (uploadSucceeded) {
513
- console.log();
514
- ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
515
- console.log();
601
+ if (hasSourceMap && artifact.sourceMapPath) {
602
+ fs.copyFileSync(artifact.sourceMapPath, path.join(artifactDir, 'main.jsbundle.map'));
603
+ result.sourceMapPath = path.join(artifactDir, 'main.jsbundle.map');
516
604
  }
517
605
  }
518
- catch (cleanupErr) {
519
- ui_1.log.warn(`Cleanup failed: ${cleanupErr.message}`);
606
+ catch (copyError) {
607
+ warnAfterUpload(`Upload succeeded but artifact copy failed: ${errorMessage(copyError)}`);
520
608
  }
521
609
  }
610
+ try {
611
+ cleanupUploadArtifacts(artifact, projectRoot, packageRoot, platform, isExpoProject);
612
+ }
613
+ catch (cleanupError) {
614
+ warnAfterUpload(`Cleanup failed: ${errorMessage(cleanupError)}`);
615
+ }
616
+ const totalMs = elapsedMs(commandStartMs, nowMs());
617
+ result.totalMs = totalMs;
618
+ const resultDir = artifactDir ?? artifact.outputDir;
619
+ const resultPath = path.join(resultDir, 'bundle-drop-result.json');
620
+ let resultWritten = false;
621
+ try {
622
+ if (!fs.existsSync(resultDir))
623
+ fs.mkdirSync(resultDir, { recursive: true });
624
+ fs.writeFileSync(resultPath, JSON.stringify(result, null, 2));
625
+ resultWritten = true;
626
+ }
627
+ catch (writeError) {
628
+ warnAfterUpload(`Upload succeeded but local result writing failed: ${errorMessage(writeError)}`);
629
+ }
630
+ try {
631
+ const summary = [
632
+ ` Organization / project: ${orgSlug} / ${projectSlug}`,
633
+ ` Channel / platform: ${channel} / ${platform}`,
634
+ ` App / runtime: ${version} / ${result.runtimeVersion}`,
635
+ ...(result.bundleVersion != null ? [` Bundle version: ${result.bundleVersion}`] : []),
636
+ ...(result.bundleVersionLabel ? [` Bundle label: ${result.bundleVersionLabel}`] : []),
637
+ ...(result.hash ? [` Hash: ${result.hash}`] : []),
638
+ ` Uploaded ZIP: ${zipSizeBytes} bytes`,
639
+ ` Source map: ${!options.sourcemap ? 'not requested' : !hasSourceMap ? 'not generated' :
640
+ result.sourceMapPath ? `generated; retained at ${result.sourceMapPath}` : 'generated; not retained'}`,
641
+ ...(result.bundlePath ? [` Retained bundle: ${result.bundlePath}`] : []),
642
+ ` Timings: bundle/package ${formatSeconds(bundlingAndPackagingMs)} · upload ${formatSeconds(uploadMs)} · total ${formatSeconds(totalMs)}`,
643
+ ...(resultWritten ? [` Result file: ${resultPath}`] : []),
644
+ ` Dashboard: ${dashboardUrl ?? 'unavailable for this server'}`,
645
+ ];
646
+ console.log();
647
+ ui_1.log.success('Upload complete.');
648
+ console.log(summary.join('\n'));
649
+ console.log();
650
+ }
651
+ catch (summaryError) {
652
+ warnAfterUpload(`Upload succeeded but summary rendering failed: ${errorMessage(summaryError)}`);
653
+ }
522
654
  }
523
655
  function upload(platform, options) {
524
656
  return runUpload(platform, options);
package/lib/context.js CHANGED
@@ -20,7 +20,7 @@ const isExpoDevelopmentWithoutNativeAdapter = exports.config.projectType === 'ex
20
20
  typeof __DEV__ !== 'undefined' &&
21
21
  __DEV__ &&
22
22
  !(0, bundleDropNative_1.isBundleDropNativeAvailable)();
23
- exports.runtimeVersion = typeof platformRuntimeVersion === 'string'
23
+ const configuredRuntime = typeof platformRuntimeVersion === 'string'
24
24
  ? platformRuntimeVersion
25
25
  : platformRuntimeVersion?.source === 'appVersion' ||
26
26
  platformRuntimeVersion?.source === 'nativeVersion'
@@ -28,6 +28,14 @@ exports.runtimeVersion = typeof platformRuntimeVersion === 'string'
28
28
  ? undefined
29
29
  : (0, nativeIdentity_1.resolveExpoNativeRuntimeVersion)(platformRuntimeVersion.source)
30
30
  : undefined;
31
+ const binaryRuntime = (0, bundleDropNative_1.getNativeRuntimeVersion)();
32
+ const needsNativeRuntime = platformRuntimeVersion && typeof platformRuntimeVersion === 'object' &&
33
+ platformRuntimeVersion.source === 'native';
34
+ if (needsNativeRuntime && binaryRuntime === undefined && !isExpoDevelopmentWithoutNativeAdapter &&
35
+ !(typeof __DEV__ !== 'undefined' && __DEV__)) {
36
+ throw new Error('[BundleDrop] Fingerprint runtime requires a new native binary with embedded identity.');
37
+ }
38
+ exports.runtimeVersion = binaryRuntime !== undefined ? binaryRuntime ?? undefined : configuredRuntime;
31
39
  exports.defaultChannel = exports.config.defaultChannel || 'develop';
32
40
  const configuredMaxCrashCount = exports.config.rollback?.maxCrashCount ?? 3;
33
41
  if (!Number.isSafeInteger(configuredMaxCrashCount) ||
package/lib/errors.d.ts CHANGED
@@ -34,8 +34,9 @@ export declare class BundleDropError extends Error {
34
34
  export declare function isBundleDropError(e: unknown): e is BundleDropError;
35
35
  export type InstallPhase = 'download' | 'install';
36
36
  export declare class InstallPhaseError extends Error {
37
+ readonly downloadSource?: 'patch-set';
37
38
  phase: InstallPhase;
38
39
  originalCause: unknown;
39
- constructor(phase: InstallPhase, cause: unknown);
40
+ constructor(phase: InstallPhase, cause: unknown, downloadSource?: 'patch-set');
40
41
  }
41
42
  export declare function isInstallPhaseError(e: unknown): e is InstallPhaseError;
package/lib/errors.js CHANGED
@@ -27,9 +27,10 @@ function isBundleDropError(e) {
27
27
  return !!e && typeof e === 'object' && e.name === 'BundleDropError';
28
28
  }
29
29
  class InstallPhaseError extends Error {
30
- constructor(phase, cause) {
30
+ constructor(phase, cause, downloadSource) {
31
31
  const msg = cause instanceof Error ? cause.message : String(cause);
32
32
  super(msg);
33
+ this.downloadSource = downloadSource;
33
34
  this.name = 'InstallPhaseError';
34
35
  this.phase = phase;
35
36
  this.originalCause = cause;
@@ -5,7 +5,7 @@ export declare function resolveExpoBuildIdentity(projectRoot: string, platform:
5
5
  officialNativeBuildVersion?: string;
6
6
  }): Promise<ExpoBuildIdentity>;
7
7
  export type ExpoMetroRuntimeVersion = string | {
8
- source: 'appVersion' | 'nativeVersion';
8
+ source: 'appVersion' | 'nativeVersion' | 'native';
9
9
  };
10
10
  /**
11
11
  * App-derived policies read the signed binary at runtime. This remains exact
@@ -188,6 +188,9 @@ async function resolveExpoBuildIdentity(projectRoot, platform, options = {}) {
188
188
  */
189
189
  async function resolveExpoMetroRuntimeVersion(projectRoot, platform) {
190
190
  const absoluteProjectRoot = path_1.default.resolve(projectRoot);
191
+ if ((0, runtimeVersion_1.readBundleDropRuntimeSelection)(absoluteProjectRoot, platform).source === 'fingerprint') {
192
+ return { source: 'native' };
193
+ }
191
194
  const runtimeAuthority = (0, runtimeVersion_1.resolveBundleDropRuntimeVersionAuthority)(absoluteProjectRoot, platform);
192
195
  if (runtimeAuthority.source === 'bundle-drop') {
193
196
  return runtimeAuthority.runtimeVersion;
@@ -10,4 +10,14 @@ export type BundleDropRuntimeVersionAuthority = {
10
10
  * type. Expo runtime policies remain available only through an explicit
11
11
  * `runtimeVersion: { source: 'expo' }` opt-in.
12
12
  */
13
+ export declare function readBundleDropRuntimeSelection(projectRoot: string, platform: MobilePlatform): {
14
+ source: "manual";
15
+ runtimeVersion: string;
16
+ } | {
17
+ source: "expo";
18
+ } | {
19
+ source: "fingerprint";
20
+ boundary: string | null;
21
+ options: import("../fingerprint/types").FingerprintOptions;
22
+ };
13
23
  export declare function resolveBundleDropRuntimeVersionAuthority(projectRoot: string, platform: MobilePlatform): BundleDropRuntimeVersionAuthority;
@@ -3,9 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readBundleDropRuntimeSelection = readBundleDropRuntimeSelection;
6
7
  exports.resolveBundleDropRuntimeVersionAuthority = resolveBundleDropRuntimeVersionAuthority;
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const errors_1 = require("./errors");
10
+ const config_1 = require("../fingerprint/config");
11
+ const client_1 = require("../fingerprint/client");
9
12
  const loadBundleDropConfig = (projectRoot) => {
10
13
  const configPath = path_1.default.join(path_1.default.resolve(projectRoot), 'bundle.drop.config.js');
11
14
  try {
@@ -27,19 +30,18 @@ const loadBundleDropConfig = (projectRoot) => {
27
30
  * type. Expo runtime policies remain available only through an explicit
28
31
  * `runtimeVersion: { source: 'expo' }` opt-in.
29
32
  */
33
+ function readBundleDropRuntimeSelection(projectRoot, platform) {
34
+ return (0, config_1.selectRuntimeVersion)(loadBundleDropConfig(projectRoot).runtimeVersion, platform);
35
+ }
30
36
  function resolveBundleDropRuntimeVersionAuthority(projectRoot, platform) {
31
- const config = loadBundleDropConfig(projectRoot);
32
- const configuredRuntimeVersion = config.runtimeVersion;
33
- if (configuredRuntimeVersion?.source === 'expo') {
37
+ const selection = readBundleDropRuntimeSelection(projectRoot, platform);
38
+ if (selection.source === 'expo') {
34
39
  return { source: 'expo' };
35
40
  }
36
- const runtimeVersion = configuredRuntimeVersion?.[platform];
37
- if (typeof runtimeVersion !== 'string' || !runtimeVersion.trim()) {
38
- throw new errors_1.ExpoIntegrationError(`bundle.drop.config.js must define a non-empty runtimeVersion.${platform} literal. ` +
39
- "Use runtimeVersion: { source: 'expo' } only when explicitly opting into Expo runtime policies.");
40
- }
41
41
  return {
42
42
  source: 'bundle-drop',
43
- runtimeVersion: runtimeVersion.trim(),
43
+ runtimeVersion: selection.source === 'fingerprint'
44
+ ? (0, client_1.calculateFingerprintSync)(projectRoot, platform).runtimeVersion
45
+ : selection.runtimeVersion,
44
46
  };
45
47
  }
@@ -0,0 +1,5 @@
1
+ import type { NativeFingerprint } from './types';
2
+ /** The existing build/config APIs are synchronous. Isolate async discovery in
3
+ * a bounded process instead of adding Node/collector code to mobile bundles.
4
+ */
5
+ export declare function calculateFingerprintSync(projectRoot: string, platform: 'ios' | 'android'): NativeFingerprint;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calculateFingerprintSync = calculateFingerprintSync;
7
+ const child_process_1 = require("child_process");
8
+ const path_1 = __importDefault(require("path"));
9
+ /** The existing build/config APIs are synchronous. Isolate async discovery in
10
+ * a bounded process instead of adding Node/collector code to mobile bundles.
11
+ */
12
+ function calculateFingerprintSync(projectRoot, platform) {
13
+ const result = (0, child_process_1.spawnSync)(process.execPath, [path_1.default.join(__dirname, 'worker.js'), path_1.default.resolve(projectRoot), platform], {
14
+ encoding: 'utf8', shell: false, timeout: 120000, maxBuffer: 32 * 1024 * 1024,
15
+ env: { ...process.env, NODE_ENV: process.env.NODE_ENV === 'development' ? 'development' : 'production' },
16
+ });
17
+ if (result.error || result.status !== 0) {
18
+ throw new Error(`Fingerprint collection failed: ${result.error?.message || result.stderr.trim() || `exit ${result.status}`}`);
19
+ }
20
+ return JSON.parse(result.stdout);
21
+ }
@@ -0,0 +1,3 @@
1
+ import type { NativeFingerprint } from './types';
2
+ /** Each call collects fresh source inputs; receipts and previous reports are never read. */
3
+ export declare function collectNativeFingerprint(projectRoot: string, platform: 'ios' | 'android'): Promise<NativeFingerprint>;