@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
package/lib/metro.js CHANGED
@@ -81,6 +81,9 @@ function withBundleDrop(config, options = {}) {
81
81
  const generatedConfigPath = writeGeneratedRuntimeConfig({
82
82
  projectRoot,
83
83
  runtimeDelivery: resolveRuntimeDelivery(projectRoot, baseConfig),
84
+ ...(baseConfig.runtimeVersion?.compatibilitySource === 'fingerprint'
85
+ ? { runtimeVersion: { ios: { source: 'native' }, android: { source: 'native' } } }
86
+ : {}),
84
87
  });
85
88
  return mergeMetroAlias(config, generatedConfigPath);
86
89
  }
@@ -41,6 +41,8 @@ export type StartupRollbackResult = {
41
41
  toEmbedded: boolean;
42
42
  hash?: string;
43
43
  };
44
+ /** undefined identifies an older binary; null identifies missing required native data. */
45
+ export declare function getNativeRuntimeVersion(): string | null | undefined;
44
46
  export declare function isBundleDropNativeAvailable(): boolean;
45
47
  export declare function isExpoOtaStartupEnabledNative(): boolean;
46
48
  export declare function isStartupRecoveryAvailableNative(): boolean;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNativeRuntimeVersion = getNativeRuntimeVersion;
3
4
  exports.isBundleDropNativeAvailable = isBundleDropNativeAvailable;
4
5
  exports.isExpoOtaStartupEnabledNative = isExpoOtaStartupEnabledNative;
5
6
  exports.isStartupRecoveryAvailableNative = isStartupRecoveryAvailableNative;
@@ -27,6 +28,16 @@ const BundleDropExpoIdentity = react_native_1.NativeModules.BundleDropExpoIdenti
27
28
  // the running identity or the attempt acknowledged by reportHealthy().
28
29
  const startupRecoverySelectedHash = readStartupRecoverySelectedHash(BundleDrop);
29
30
  const startupRecoveryAttempt = readStartupRecoveryAttempt(BundleDrop);
31
+ // New Architecture host objects expose constants through getters without own
32
+ // property descriptors. Read the value once rather than testing hasOwnProperty.
33
+ const capturedNativeRuntime = BundleDrop?.nativeRuntimeVersion;
34
+ const nativeRuntimeVersion = capturedNativeRuntime === undefined
35
+ ? undefined
36
+ : nonEmptyString(capturedNativeRuntime);
37
+ /** undefined identifies an older binary; null identifies missing required native data. */
38
+ function getNativeRuntimeVersion() {
39
+ return nativeRuntimeVersion;
40
+ }
30
41
  let hasWarnedAboutStartupRecoveryCapability = false;
31
42
  function isRecord(value) {
32
43
  return !!value && typeof value === 'object' && !Array.isArray(value);
@@ -38,12 +49,11 @@ function canonicalHash(value) {
38
49
  return typeof value === 'string' && SHA256_HASH_PATTERN.test(value) ? value : null;
39
50
  }
40
51
  function readStartupRecoverySelectedHash(nativeModule) {
41
- if (!nativeModule || !Object.prototype.hasOwnProperty.call(nativeModule, 'startupRecoverySelectedHash')) {
52
+ // New Architecture constants can be getter-backed without an own descriptor.
53
+ const selectedHash = nativeModule?.startupRecoverySelectedHash;
54
+ if (selectedHash === undefined)
42
55
  return undefined;
43
- }
44
- if (nativeModule.startupRecoverySelectedHash == null)
45
- return null;
46
- return canonicalHash(nativeModule.startupRecoverySelectedHash);
56
+ return canonicalHash(selectedHash);
47
57
  }
48
58
  function nonNegativeInteger(value) {
49
59
  return Number.isSafeInteger(value) && value >= 0 ? value : null;
@@ -59,7 +59,7 @@ async function installFromPatchSet(params) {
59
59
  await fs_1.default.downloadFile(patchesUrl, tempZipPath);
60
60
  }
61
61
  catch (e) {
62
- throw new errors_1.InstallPhaseError('download', e);
62
+ throw new errors_1.InstallPhaseError('download', e, 'patch-set');
63
63
  }
64
64
  const actualPatchSetHash = await fs_1.default.sha256File(tempZipPath);
65
65
  if (actualPatchSetHash !== patchSetHash) {
@@ -14,7 +14,8 @@ type TryInstallPatchTransportParams = {
14
14
  projectSlug: string;
15
15
  platform: 'ios' | 'android';
16
16
  runtimeVersionValue?: string;
17
+ allowUnmanagedPatchAuthFallback?: boolean;
17
18
  statusCb?: (status: string) => void;
18
19
  };
19
- export declare const tryInstallPatchTransport: ({ target, projectSlug, platform, runtimeVersionValue, statusCb, }: TryInstallPatchTransportParams) => Promise<InstallResult | null>;
20
+ export declare const tryInstallPatchTransport: ({ target, projectSlug, platform, runtimeVersionValue, allowUnmanagedPatchAuthFallback, statusCb, }: TryInstallPatchTransportParams) => Promise<InstallResult | null>;
20
21
  export {};
@@ -7,6 +7,7 @@ const clientApi_1 = require("../api/clientApi");
7
7
  const installFromPatchSet_1 = require("./installFromPatchSet");
8
8
  const patchOperations_1 = require("./patchOperations");
9
9
  const artifactCapability_1 = require("../runtime-delivery/artifactCapability");
10
+ const errors_1 = require("../errors");
10
11
  const PATCH_FAILURE_REPORT_TIMEOUT_MS = 1500;
11
12
  const reportPatchInstallFailure = async ({ projectSlug, platform, runtimeVersionValue, baseHash, targetHash, algorithm, error, }) => {
12
13
  try {
@@ -41,7 +42,7 @@ const reportPatchInstallFailureBeforeFallback = async (params) => {
41
42
  clearTimeout(timeout);
42
43
  }
43
44
  };
44
- const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtimeVersionValue, statusCb, }) => {
45
+ const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtimeVersionValue, allowUnmanagedPatchAuthFallback = false, statusCb, }) => {
45
46
  if (target.mode !== 'patch' ||
46
47
  !target.baseHash ||
47
48
  !(0, patchOperations_1.isSupportedPatchAlgorithm)(target.patchSet?.algorithm) ||
@@ -71,7 +72,8 @@ const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtime
71
72
  });
72
73
  }
73
74
  catch (e) {
74
- if ((0, artifactCapability_1.isArtifactCapabilityRejected)(e))
75
+ if ((0, artifactCapability_1.isArtifactCapabilityRejected)(e) && !(allowUnmanagedPatchAuthFallback &&
76
+ (0, errors_1.isInstallPhaseError)(e) && e.downloadSource === 'patch-set'))
75
77
  throw e;
76
78
  await reportPatchInstallFailureBeforeFallback({
77
79
  projectSlug,
@@ -106,9 +106,10 @@ export declare function getObservabilityContext(): Promise<ObservabilityContext>
106
106
  * Read the current local update state from disk.
107
107
  */
108
108
  export declare function getRuntimeUpdateState(): Promise<{
109
+ pendingRollback?: boolean;
110
+ pendingApply: boolean;
109
111
  hasBundle: boolean;
110
112
  info: BundleInfo;
111
- pendingApply: boolean;
112
113
  }>;
113
114
  /**
114
115
  * Named-export variant of `useBundleDrop().checkLatest()`.
@@ -33,6 +33,7 @@ const bundlePointer_1 = require("../fs/bundlePointer");
33
33
  const downloadAndInstall_1 = require("../manager/downloadAndInstall");
34
34
  const updateCheck_1 = require("../manager/updateCheck");
35
35
  const rollbackState_1 = require("../manager/rollbackState");
36
+ const pendingRollback_1 = require("../manager/pendingRollback");
36
37
  const updateState_1 = require("../manager/updateState");
37
38
  const initState_1 = require("./initState");
38
39
  const DEFAULT_STATUS = 'Click the button to check for updates';
@@ -164,7 +165,9 @@ function getApplyStatus(result) {
164
165
  : result.status === 'noBundle'
165
166
  ? '⚠️ No downloaded bundle to apply'
166
167
  : result.status === 'blocked'
167
- ? '⚠️ Update previously failed on this device'
168
+ ? result.reason === 'ROLLBACK_REVALIDATION_FAILED'
169
+ ? '⚠️ Rollback decision changed or could not be revalidated; check for updates again'
170
+ : '⚠️ Update previously failed on this device'
168
171
  : 'ℹ️ Bundle already applied';
169
172
  }
170
173
  function requestRuntimeRestart() {
@@ -173,9 +176,56 @@ function requestRuntimeRestart() {
173
176
  }
174
177
  async function applyAuthoritativeRollback(reason) {
175
178
  const result = await (0, rollbackState_1.rollbackStartupBundle)(isCurrentRevokedRollback(reason));
176
- if (result?.rolledBack) {
179
+ if (!result)
180
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
181
+ // A bookkeeping failure must not prevent confirmed-revocation recovery.
182
+ await (0, pendingRollback_1.clearPendingRollback)().catch(error => {
183
+ console.warn('⚠️ Failed to clear pending BundleDrop rollback:', error);
184
+ });
185
+ if (result.rolledBack) {
177
186
  requestRuntimeRestart();
187
+ return { status: 'applied' };
188
+ }
189
+ return { status: 'alreadyApplied' };
190
+ }
191
+ async function handleDownloadRollback(result) {
192
+ if (result.status !== 'rollback') {
193
+ await (0, pendingRollback_1.clearPendingRollback)();
194
+ return result;
195
+ }
196
+ const runtime = (0, initState_1.assertBundleDropInitialized)();
197
+ if (runtime.policy === 'manual' && !isCurrentRevokedRollback(result.reason)) {
198
+ await (0, pendingRollback_1.stageRollback)(runtime.channelName, result.reason);
199
+ return { ...result, pendingApply: true };
178
200
  }
201
+ await applyAuthoritativeRollback(result.reason);
202
+ return result;
203
+ }
204
+ async function applyPendingRollback() {
205
+ const intent = await (0, pendingRollback_1.readPendingRollback)();
206
+ if (!intent)
207
+ return null;
208
+ const runtime = (0, initState_1.assertBundleDropInitialized)();
209
+ if (!await (0, pendingRollback_1.isPendingRollbackCurrent)(intent, runtime.channelName)) {
210
+ await (0, pendingRollback_1.clearPendingRollback)();
211
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
212
+ }
213
+ // Refresh authority before native atomically selects and verifies the fallback.
214
+ const decision = await (0, updateCheck_1.checkForUpdate)(runtime.channelName);
215
+ if (decision?.action === 'ROLLBACK' && isCurrentRevokedRollback(decision.reason)) {
216
+ return applyAuthoritativeRollback(decision.reason);
217
+ }
218
+ if (decision?.action !== 'ROLLBACK' || decision.reason !== intent.reason) {
219
+ if (decision)
220
+ await (0, pendingRollback_1.clearPendingRollback)();
221
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
222
+ }
223
+ // A native recovery or another selection may have happened during the check.
224
+ if (!await (0, pendingRollback_1.isPendingRollbackCurrent)(intent, runtime.channelName)) {
225
+ await (0, pendingRollback_1.clearPendingRollback)();
226
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
227
+ }
228
+ return applyAuthoritativeRollback(decision.reason);
179
229
  }
180
230
  async function markActiveCandidateHealthy() {
181
231
  const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)();
@@ -186,12 +236,17 @@ async function markActiveCandidateHealthy() {
186
236
  }
187
237
  async function refreshState(cached) {
188
238
  const state = await (0, updateState_1.getUpdateState)(cached);
239
+ const intent = await (0, pendingRollback_1.readPendingRollback)();
240
+ const pendingRollback = !!intent &&
241
+ await (0, pendingRollback_1.isPendingRollbackCurrent)(intent, (0, initState_1.assertBundleDropInitialized)().channelName);
242
+ const pendingApply = state.pendingApply || pendingRollback;
189
243
  patchSnapshot({
190
244
  installedInfo: state.info || null,
191
- pendingApply: state.pendingApply,
245
+ pendingApply,
192
246
  hasBundle: state.hasBundle,
193
247
  });
194
- return state;
248
+ // Startup automatic bundle application must never consume a manual rollback intent.
249
+ return { ...state, pendingApply, ...(pendingRollback ? { pendingRollback: true } : {}) };
195
250
  }
196
251
  async function withBusy(fn) {
197
252
  if (updateFlowActive) {
@@ -253,7 +308,7 @@ async function runStartupFlow() {
253
308
  })();
254
309
  const { bundlePath } = await localStartupPromise;
255
310
  const pendingState = await refreshState({ bundlePath });
256
- if (pendingState.pendingApply) {
311
+ if (pendingState.pendingApply && !pendingState.pendingRollback) {
257
312
  if (runtime.policy === 'immediate') {
258
313
  emitStatus('♻️ Applying previously downloaded update...');
259
314
  const applied = await (0, updateState_1.applyUpdate)(statusCb, () => {
@@ -279,6 +334,9 @@ async function runStartupFlow() {
279
334
  if (!decision)
280
335
  return;
281
336
  if (decision.action === 'ROLLBACK') {
337
+ if (!isCurrentRevokedRollback(decision.reason) && (runtime.policy === 'manual' || runtime.checkOnly)) {
338
+ return;
339
+ }
282
340
  emitStatus('↩️ Server requested rollback...');
283
341
  await applyAuthoritativeRollback(decision.reason);
284
342
  return;
@@ -370,8 +428,11 @@ function initBundleDrop(options) {
370
428
  (0, bundleDropNative_1.warnIfStartupRecoveryUnavailableNative)();
371
429
  }
372
430
  }
373
- // Persist for the next cold start and for native path reads in this process.
374
- nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
431
+ // Explicit app enablement persists across cold starts. Implicit Expo Debug
432
+ // suppression is local to this process and must not disable the Release app.
433
+ if (!useExpoDevelopmentFallback) {
434
+ nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
435
+ }
375
436
  patchSnapshot({
376
437
  channelName: config.channelName,
377
438
  isEnabled: config.enabled,
@@ -450,10 +511,8 @@ async function downloadAndStage(extraStatusHandler) {
450
511
  }
451
512
  await waitForStartupIfNeeded();
452
513
  return withBusy(async () => {
453
- const result = await (0, downloadAndInstall_1.downloadUpdate)({ channelName: runtime.channelName }, status => emitStatus(status, extraStatusHandler));
454
- if (result.status === 'rollback') {
455
- await applyAuthoritativeRollback(result.reason);
456
- }
514
+ const downloadResult = await (0, downloadAndInstall_1.downloadUpdate)({ channelName: runtime.channelName }, status => emitStatus(status, extraStatusHandler));
515
+ const result = await handleDownloadRollback(downloadResult);
457
516
  const status = getDownloadStatus(result);
458
517
  if (status) {
459
518
  emitStatus(status, extraStatusHandler);
@@ -471,9 +530,7 @@ async function applyDownloadedUpdate(extraStatusHandler) {
471
530
  await waitForStartupIfNeeded();
472
531
  await nativeOtaEnabledPromise;
473
532
  return withBusy(async () => {
474
- const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => {
475
- runtimeRestartRequested = true;
476
- });
533
+ const result = await applyPendingRollback() ?? await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => { runtimeRestartRequested = true; });
477
534
  const status = getApplyStatus(result);
478
535
  if (status) {
479
536
  emitStatus(status, extraStatusHandler);
@@ -551,11 +608,10 @@ async function installBundleFromListItem(bundle) {
551
608
  const canUseResolvedTransport = resolvedDecision?.action === 'INSTALL' &&
552
609
  (resolvedDecision.bundleHash ?? resolvedDecision.hash) === bundle.hash;
553
610
  if (usesManagedRuntimeDelivery && resolvedDecision?.action === 'ROLLBACK') {
554
- const result = {
611
+ const result = await handleDownloadRollback({
555
612
  status: 'rollback',
556
613
  reason: resolvedDecision.reason,
557
- };
558
- await applyAuthoritativeRollback(result.reason);
614
+ });
559
615
  const status = getDownloadStatus(result);
560
616
  if (status)
561
617
  emitStatus(status);
@@ -568,7 +624,7 @@ async function installBundleFromListItem(bundle) {
568
624
  status: MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS,
569
625
  };
570
626
  }
571
- const result = canUseResolvedTransport
627
+ let result = canUseResolvedTransport
572
628
  ? await (0, downloadAndInstall_1.downloadUpdate)({
573
629
  channelName: runtime.channelName,
574
630
  resolvedTarget: {
@@ -593,9 +649,7 @@ async function installBundleFromListItem(bundle) {
593
649
  channelName: runtime.channelName,
594
650
  onStatusUpdate: emitStatus,
595
651
  });
596
- if (usesManagedRuntimeDelivery && result.status === 'rollback') {
597
- await applyAuthoritativeRollback(result.reason);
598
- }
652
+ result = await handleDownloadRollback(result);
599
653
  if (result.status === 'staged') {
600
654
  const status = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
601
655
  emitStatus(status);
@@ -725,10 +779,11 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
725
779
  return { status: 'incompatible' };
726
780
  }
727
781
  return withBusy(async () => {
728
- const result = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
782
+ const downloadResult = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
729
783
  channelName: runtime.channelName,
730
784
  onStatusUpdate: status => emitStatus(status, onStatusUpdate),
731
785
  });
786
+ const result = await handleDownloadRollback(downloadResult);
732
787
  const status = getDownloadStatus(result);
733
788
  if (status) {
734
789
  emitStatus(status, onStatusUpdate);
@@ -41,10 +41,13 @@ const fs = __importStar(require("fs"));
41
41
  const path = __importStar(require("path"));
42
42
  const bundleManifest_1 = require("../manifest/bundleManifest");
43
43
  const canonicalArtifact_1 = require("./canonicalArtifact");
44
+ const runtimeCompatibilityMetadata_1 = require("./runtimeCompatibilityMetadata");
45
+ const nativeBuildNumber_1 = require("./nativeBuildNumber");
44
46
  const projectRoot_1 = require("./projectRoot");
45
47
  Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
46
48
  const resolveModule_1 = require("./resolveModule");
47
49
  const iosHermesDefault_1 = require("./iosHermesDefault");
50
+ const runtimeVersion_1 = require("../expo/runtimeVersion");
48
51
  const SENTRY_HERMES_OTA_DOCS_URL = 'https://bundledrop.app/docs/observability#sentry-and-hermes-ota-builds';
49
52
  const SENTRY_DEBUG_ID_MARKERS = ['//# debugId=', 'sentry-dbid-'];
50
53
  const runProcess = (spawnProcess, executable, args, options) => {
@@ -229,6 +232,11 @@ function runBundleScript(options = {}) {
229
232
  //eslint-disable-next-line
230
233
  const cfg = require(configPath);
231
234
  runtimeVersion = cfg?.runtimeVersion?.[platform];
235
+ if (cfg?.runtimeVersion?.compatibilitySource === 'fingerprint') {
236
+ const authority = (0, runtimeVersion_1.resolveBundleDropRuntimeVersionAuthority)(projectRoot, platform);
237
+ if (authority.source === 'bundle-drop')
238
+ runtimeVersion = authority.runtimeVersion;
239
+ }
232
240
  if (!runtimeVersion) {
233
241
  console.error(`❌ Missing runtimeVersion.${platform} in bundle.drop.config.js. Example: runtimeVersion: { ios: "1.0.0", android: "1.0.0" }`);
234
242
  process.exit(1);
@@ -341,6 +349,8 @@ function runBundleScript(options = {}) {
341
349
  platform: platform,
342
350
  appVersion,
343
351
  runtimeVersion,
352
+ runtimeCompatibility: (0, runtimeCompatibilityMetadata_1.runtimeCompatibilityMetadata)(cfg.runtimeVersion, platform, runtimeVersion),
353
+ buildNumber: (0, nativeBuildNumber_1.normalizeBuildNumber)(process.env.BUNDLE_DROP_BUILD_NUMBER, platform),
344
354
  bundlePath,
345
355
  assetsDir,
346
356
  outputDir,
@@ -1,9 +1,12 @@
1
+ import type { RuntimeCompatibilityMetadata } from './runtimeCompatibilityMetadata';
1
2
  export type CanonicalArtifactPlatform = 'ios' | 'android';
2
3
  export type CanonicalAssetTraversal = 'strict' | 'legacy-bare';
3
4
  export type BuildCanonicalArtifactOptions = {
4
5
  platform: CanonicalArtifactPlatform;
5
6
  appVersion: string;
6
7
  runtimeVersion: string;
8
+ runtimeCompatibility?: RuntimeCompatibilityMetadata;
9
+ buildNumber?: string | null;
7
10
  bundlePath: string;
8
11
  assetsDir: string;
9
12
  outputDir: string;
@@ -130,7 +130,7 @@ const collectLegacyBareAssets = (assetsDir) => {
130
130
  * ZIP roles. Framework-specific export commands must finish before this runs.
131
131
  */
132
132
  function buildCanonicalArtifact(options) {
133
- const { platform, appVersion, runtimeVersion, bundlePath, assetsDir, outputDir, sourceMapPath, assetTraversal = 'strict', } = options;
133
+ const { platform, appVersion, runtimeVersion, runtimeCompatibility = { compatibilitySource: 'manual' }, buildNumber, bundlePath, assetsDir, outputDir, sourceMapPath, assetTraversal = 'strict', } = options;
134
134
  if (!appVersion.trim())
135
135
  throw new Error('Canonical artifact requires an app version');
136
136
  if (!runtimeVersion.trim())
@@ -153,6 +153,8 @@ function buildCanonicalArtifact(options) {
153
153
  bundlePath: 'main.jsbundle',
154
154
  sizeInBytes: bundleBuffer.length,
155
155
  runtimeVersion,
156
+ ...runtimeCompatibility,
157
+ ...(buildNumber != null ? { buildNumber } : {}),
156
158
  };
157
159
  const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
158
160
  const stagedFiles = new Map([
@@ -10,6 +10,8 @@ const expo_1 = require("../expo");
10
10
  const build_receipt_1 = require("../CLI/scripts/expo/build-receipt");
11
11
  const canonicalArtifact_1 = require("./canonicalArtifact");
12
12
  const bundle_1 = require("./bundle");
13
+ const runtimeVersion_1 = require("../expo/runtimeVersion");
14
+ const nativeBuildNumber_1 = require("./nativeBuildNumber");
13
15
  const getExpoArtifactRoot = (projectRoot) => path_1.default.join(projectRoot, '.bundle-drop', 'artifacts');
14
16
  const assertExpoUpdatesDoesNotOwnExport = (projectRoot) => {
15
17
  const { exp } = (0, expo_1.evaluateExpoConfig)(projectRoot);
@@ -62,10 +64,19 @@ async function exportProjectArtifact(options) {
62
64
  const sourceMapPath = path_1.default.join(outputDir, 'main.jsbundle.map');
63
65
  fs_extra_1.default.copyFileSync(exported.bundlePath, bundlePath);
64
66
  fs_extra_1.default.copyFileSync(exported.sourceMapPath, sourceMapPath);
67
+ const selection = (0, runtimeVersion_1.readBundleDropRuntimeSelection)(projectRoot, options.platform);
68
+ const runtimeCompatibility = selection.source === 'fingerprint'
69
+ ? {
70
+ compatibilitySource: 'fingerprint',
71
+ fingerprint: { schemeVersion: 1, hash: buildIdentity.runtimeVersion, manualBoundary: selection.boundary },
72
+ }
73
+ : { compatibilitySource: 'manual' };
65
74
  const artifact = (0, canonicalArtifact_1.buildCanonicalArtifact)({
66
75
  platform: options.platform,
67
76
  appVersion: buildIdentity.appVersion,
68
77
  runtimeVersion: buildIdentity.runtimeVersion,
78
+ runtimeCompatibility,
79
+ buildNumber: (0, nativeBuildNumber_1.expoBuildNumber)(buildIdentity),
69
80
  bundlePath,
70
81
  assetsDir: exported.assetsDirectory,
71
82
  outputDir,
@@ -0,0 +1,9 @@
1
+ import type { ExpoBuildIdentity, MobilePlatform } from '../expo/types';
2
+ /** Optional upload context, never a runtime compatibility input. */
3
+ export declare function normalizeBuildNumber(value: unknown, platform: MobilePlatform): string | null;
4
+ export declare function expoBuildNumber(identity: ExpoBuildIdentity): string | null;
5
+ /** Recognize literal statements only; do not evaluate Gradle or select a flavor. */
6
+ export declare function androidBuildNumber(source: string): string | null;
7
+ export declare function readAndroidBuildNumber(projectRoot: string, gradlePath?: string): string | null;
8
+ /** Resolve only the exact standard variable with unambiguous literal settings. */
9
+ export declare function iosBuildNumber(raw: unknown, projectRoot: string): string | null;
@@ -0,0 +1,110 @@
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.normalizeBuildNumber = normalizeBuildNumber;
7
+ exports.expoBuildNumber = expoBuildNumber;
8
+ exports.androidBuildNumber = androidBuildNumber;
9
+ exports.readAndroidBuildNumber = readAndroidBuildNumber;
10
+ exports.iosBuildNumber = iosBuildNumber;
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const path_1 = __importDefault(require("path"));
13
+ /** Optional upload context, never a runtime compatibility input. */
14
+ function normalizeBuildNumber(value, platform) {
15
+ if (typeof value !== 'string' && typeof value !== 'number')
16
+ return null;
17
+ const number = String(value).trim();
18
+ if (platform === 'ios')
19
+ return /^\d+(?:\.\d+){0,2}$/.test(number) && number.length <= 64 ? number : null;
20
+ return /^\d+$/.test(number) && Number.isSafeInteger(Number(number)) &&
21
+ Number(number) > 0 && Number(number) <= 2100000000 ? number : null;
22
+ }
23
+ function expoBuildNumber(identity) {
24
+ const prefix = `${identity.appVersion}(`;
25
+ if (!identity.nativeVersion.startsWith(prefix) || !identity.nativeVersion.endsWith(')'))
26
+ return null;
27
+ return normalizeBuildNumber(identity.nativeVersion.slice(prefix.length, -1), identity.platform);
28
+ }
29
+ function buildTokens(source) {
30
+ const pattern = /\/\*[\s\S]*?\*\/|\/\/[^\r\n]*|"""[\s\S]*?"""|'''[\s\S]*?'''|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[A-Za-z_$][\w$]*|\d+(?:[A-Za-z_][\w]*)?|\r?\n|[^\s]/g;
31
+ return [...source.matchAll(pattern)].map(match => match[0])
32
+ .filter(token => !token.startsWith('//') && !token.startsWith('/*'));
33
+ }
34
+ /** Recognize literal statements only; do not evaluate Gradle or select a flavor. */
35
+ function androidBuildNumber(source) {
36
+ const tokens = buildTokens(source);
37
+ if (tokens.some(token => ['/', '"', "'", 'productFlavors', 'setVersionCode', 'versionCodeOverride'].includes(token)))
38
+ return null;
39
+ if (tokens.filter(token => token === 'versionCode').length !== 1)
40
+ return null;
41
+ const scopes = [];
42
+ const index = tokens.indexOf('versionCode');
43
+ for (let cursor = 0; cursor < index; cursor++) {
44
+ const token = tokens[cursor];
45
+ if (token === '{')
46
+ scopes.push(tokens[cursor - 1] ?? '');
47
+ else if (token === '}')
48
+ scopes.pop();
49
+ }
50
+ if (scopes[scopes.length - 1] !== 'defaultConfig' || !['{', '\n', '\r\n', ';'].includes(tokens[index - 1]))
51
+ return null;
52
+ const numberIndex = index + (tokens[index + 1] === '=' ? 2 : 1);
53
+ const after = tokens[numberIndex + 1];
54
+ if (after !== undefined && !['\n', '\r\n', ';', '}'].includes(after))
55
+ return null;
56
+ // A continuation on the next line is still an expression.
57
+ const next = tokens.slice(numberIndex + 1).find(item => !['\n', '\r\n'].includes(item));
58
+ if (['\n', '\r\n'].includes(after) && next && /^[+\-*%?.:(\[{&|^<>=!,]$/.test(next))
59
+ return null;
60
+ return normalizeBuildNumber(tokens[numberIndex], 'android');
61
+ }
62
+ function readAndroidBuildNumber(projectRoot, gradlePath) {
63
+ const candidates = gradlePath ? [path_1.default.resolve(projectRoot, gradlePath)] : [
64
+ path_1.default.join(projectRoot, 'android/app/build.gradle'),
65
+ path_1.default.join(projectRoot, 'android/app/build.gradle.kts'),
66
+ ];
67
+ const files = candidates.filter(file => fs_1.default.existsSync(file));
68
+ if (files.length !== 1)
69
+ return null;
70
+ return androidBuildNumber(fs_1.default.readFileSync(files[0], 'utf8'));
71
+ }
72
+ /** Resolve only the exact standard variable with unambiguous literal settings. */
73
+ function iosBuildNumber(raw, projectRoot) {
74
+ if (raw !== '$(CURRENT_PROJECT_VERSION)' && raw !== '${CURRENT_PROJECT_VERSION}')
75
+ return normalizeBuildNumber(raw, 'ios');
76
+ const iosDir = path_1.default.join(projectRoot, 'ios');
77
+ if (!fs_1.default.existsSync(iosDir))
78
+ return null;
79
+ const projects = fs_1.default.readdirSync(iosDir).filter(name => name.endsWith('.xcodeproj'));
80
+ if (projects.length !== 1)
81
+ return null;
82
+ const projectFile = path_1.default.join(iosDir, projects[0], 'project.pbxproj');
83
+ if (!fs_1.default.existsSync(projectFile))
84
+ return null;
85
+ const tokens = buildTokens(fs_1.default.readFileSync(projectFile, 'utf8')).filter(token => !['\n', '\r\n'].includes(token));
86
+ // PBX source paths may contain unquoted slashes; validate the setting value below.
87
+ if (tokens.some(token => ['"', "'"].includes(token)))
88
+ return null;
89
+ const scopes = [];
90
+ const values = new Set();
91
+ for (let index = 0; index < tokens.length; index++) {
92
+ const token = tokens[index];
93
+ if (token === '{')
94
+ scopes.push(tokens[index - 1] === '=' && tokens[index - 2] === 'buildSettings' ? 'settings' : '');
95
+ else if (token === '}')
96
+ scopes.pop();
97
+ else if (token === 'CURRENT_PROJECT_VERSION') {
98
+ if (scopes[scopes.length - 1] !== 'settings' || tokens[index + 1] !== '=')
99
+ return null;
100
+ const end = tokens.indexOf(';', index + 2);
101
+ if (end === -1)
102
+ return null;
103
+ const value = normalizeBuildNumber(tokens.slice(index + 2, end).join('').replace(/^"|"$/g, ''), 'ios');
104
+ if (!value)
105
+ return null;
106
+ values.add(value);
107
+ }
108
+ }
109
+ return values.size === 1 ? [...values][0] : null;
110
+ }
@@ -0,0 +1,10 @@
1
+ /** Display metadata only. runtimeVersion remains the exact compatibility key. */
2
+ export type RuntimeCompatibilityMetadata = {
3
+ compatibilitySource: 'manual' | 'fingerprint';
4
+ fingerprint?: {
5
+ schemeVersion: 1;
6
+ hash: string;
7
+ manualBoundary: string | null;
8
+ };
9
+ };
10
+ export declare function runtimeCompatibilityMetadata(runtimeConfig: unknown, platform: 'ios' | 'android', runtimeVersion: string): RuntimeCompatibilityMetadata;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runtimeCompatibilityMetadata = runtimeCompatibilityMetadata;
4
+ const config_1 = require("../fingerprint/config");
5
+ function runtimeCompatibilityMetadata(runtimeConfig, platform, runtimeVersion) {
6
+ const selection = (0, config_1.selectRuntimeVersion)(runtimeConfig, platform);
7
+ if (selection.source !== 'fingerprint')
8
+ return { compatibilitySource: 'manual' };
9
+ return {
10
+ compatibilitySource: 'fingerprint',
11
+ fingerprint: { schemeVersion: 1, hash: runtimeVersion, manualBoundary: selection.boundary },
12
+ };
13
+ }