@gfean/react-native-bundle-drop 0.10.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 +60 -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 +9 -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 +1 -0
  22. package/lib/CLI/scripts/upload-cli.js +35 -0
  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 +25 -11
  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
@@ -48,6 +48,7 @@ const logo_1 = require("../logo");
48
48
  const ui_1 = require("../utils/ui");
49
49
  const read_xml_plist_1 = require("../utils/read-xml-plist");
50
50
  const resolve_ios_version_1 = require("../../scripts/resolve-ios-version");
51
+ const nativeBuildNumber_1 = require("../../scripts/nativeBuildNumber");
51
52
  const expo_1 = require("../../expo");
52
53
  const resolveModule_1 = require("../../scripts/resolveModule");
53
54
  const serverUrl_1 = require("../serverUrl");
@@ -304,6 +305,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
304
305
  ui_1.log.label('Project', projectSlug);
305
306
  ui_1.log.label('Channel', channel);
306
307
  let version = options.version;
308
+ let parsedIosPlist;
307
309
  let expoBuildIdentity;
308
310
  const buildGradlePath = options.buildGradlePath || options.buildgradlePath;
309
311
  const parseAndroidVersionFromGradle = (filePath) => {
@@ -348,6 +350,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
348
350
  }
349
351
  try {
350
352
  const parsed = await (0, read_xml_plist_1.readXmlPlist)(options.plistFile);
353
+ parsedIosPlist = parsed;
351
354
  const rawVersion = Object.prototype.hasOwnProperty.call(parsed, 'CFBundleShortVersionString')
352
355
  ? parsed.CFBundleShortVersionString
353
356
  : undefined;
@@ -392,6 +395,35 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
392
395
  ui_1.log.error('❌ Version could not be determined');
393
396
  process.exit(1);
394
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);
395
427
  ui_1.log.label('App Version', version);
396
428
  console.log();
397
429
  console.log((0, logo_1.buildBundleDropLogo)());
@@ -432,6 +464,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
432
464
  env: {
433
465
  ...process.env,
434
466
  BUNDLE_DROP_APP_VERSION: version,
467
+ BUNDLE_DROP_BUILD_NUMBER: buildNumber ?? '',
435
468
  },
436
469
  });
437
470
  if (result.error)
@@ -509,6 +542,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
509
542
  orgSlug,
510
543
  projectSlug,
511
544
  runtimeVersion,
545
+ buildNumber,
512
546
  packageVersion: packageVersion ?? null,
513
547
  releaseNotes: releaseNotes ?? null,
514
548
  author: options.author ?? null,
@@ -544,6 +578,7 @@ async function runUpload(platform, options, dependencies = defaultUploadDependen
544
578
  orgSlug,
545
579
  projectSlug,
546
580
  runtimeVersion: responseData.runtimeVersion ?? runtimeVersion ?? null,
581
+ buildNumber: responseData.buildNumber ?? buildNumber,
547
582
  packageVersion: responseData.packageVersion ?? packageVersion ?? null,
548
583
  bundleId: responseData.bundleId ?? null,
549
584
  bundleVersion: responseData.bundleVersion ?? null,
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>;
@@ -0,0 +1,116 @@
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.collectNativeFingerprint = collectNativeFingerprint;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const config_1 = require("./config");
11
+ const normalizeBuildNumber_1 = require("./normalizeBuildNumber");
12
+ const normalizeIosBuildNumber_1 = require("./normalizeIosBuildNumber");
13
+ // The complete maintained adaptation is packaged independently of the mobile SDK.
14
+ const upstreamRoot = path_1.default.resolve(__dirname, '..', '..', 'third_party', 'expo-fingerprint', 'build');
15
+ const upstream = (file) => require(path_1.default.join(upstreamRoot, file));
16
+ const GENERATED_PATHS = [
17
+ '**/.bundle-drop/generated/**', '**/.bundle-drop/artifacts/**',
18
+ '**/.bundle-drop/fingerprints/**', '**/.bundle-drop/build-identity.json',
19
+ '**/.bundle-drop/runtime-delivery.lock.json', '**/.bundle-drop/runtime-delivery.generated.json',
20
+ '**/bundle.drop.config.js',
21
+ '**/node_modules/@gfean/react-native-bundle-drop/dist/**',
22
+ '**/*-gradle-plugin/.kotlin/**', '**/android/.kotlin/**', '**/android/local.properties',
23
+ '**/android/**/debug.keystore', '**/android/**/output-metadata.json',
24
+ ];
25
+ function extraSources(projectRoot, platform, entries) {
26
+ const ids = new Set();
27
+ return entries.flatMap(entry => {
28
+ if (!entry || typeof entry.id !== 'string' || !entry.id.trim() ||
29
+ typeof entry.value !== 'string' || !entry.value ||
30
+ !['file', 'dir', 'environment'].includes(entry.type)) {
31
+ throw new Error('Invalid fingerprint extra source. Supply id, type, and value.');
32
+ }
33
+ if (ids.has(entry.id))
34
+ throw new Error(`Duplicate fingerprint extra source: ${entry.id}`);
35
+ ids.add(entry.id);
36
+ if (entry.platforms && !entry.platforms.includes(platform))
37
+ return [];
38
+ const value = entry.type === 'environment' ? process.env[entry.value] : path_1.default.resolve(projectRoot, entry.value);
39
+ const present = entry.type === 'environment' ? value !== undefined : fs_1.default.existsSync(value);
40
+ if (!present) {
41
+ if (!entry.optional)
42
+ throw new Error(`Required fingerprint extra source is missing: ${entry.id}`);
43
+ return [{ type: 'contents', id: `extra:${entry.id}`, contents: 'absent', reasons: ['explicitOptionalInput'] }];
44
+ }
45
+ if (entry.type === 'environment') {
46
+ return [{ type: 'contents', id: `extra:${entry.id}`, contents: JSON.stringify({ value }), reasons: ['explicitEnvironment'] }];
47
+ }
48
+ const stat = fs_1.default.statSync(value);
49
+ if ((entry.type === 'file' && !stat.isFile()) || (entry.type === 'dir' && !stat.isDirectory())) {
50
+ throw new Error(`Fingerprint extra source has the wrong type: ${entry.id}`);
51
+ }
52
+ return [{ type: entry.type, filePath: path_1.default.relative(projectRoot, value).split(path_1.default.sep).join('/'),
53
+ overrideHashKey: `extra:${entry.id}`, reasons: ['explicitNativeInput'] }];
54
+ });
55
+ }
56
+ /** Each call collects fresh source inputs; receipts and previous reports are never read. */
57
+ async function collectNativeFingerprint(projectRoot, platform) {
58
+ // Config modules are resolved by Node to physical paths. Use the same root
59
+ // for source IDs so a checkout symlink cannot change the native identity.
60
+ projectRoot = fs_1.default.realpathSync(path_1.default.resolve(projectRoot));
61
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
62
+ delete require.cache[require.resolve(configPath)];
63
+ const config = require(configPath);
64
+ const selected = (0, config_1.selectRuntimeVersion)(config.runtimeVersion, platform);
65
+ if (selected.source !== 'fingerprint')
66
+ throw new Error('Fingerprint collection requires compatibilitySource: fingerprint.');
67
+ const mode = selected.options.nativeProjectMode?.[platform];
68
+ if (mode === 'native' && !fs_1.default.statSync(path_1.default.join(projectRoot, platform)).isDirectory()) {
69
+ throw new Error(`The selected native fingerprint project is missing ${platform}/.`);
70
+ }
71
+ const bufferedFiles = new Map();
72
+ const options = await upstream('Options').normalizeOptionsAsync(projectRoot, {
73
+ platforms: [platform], preset: 'strict', hashAlgorithm: 'sha256', concurrentIoLimit: 8,
74
+ nativeModuleSourceType: 'files', configPluginSourceType: 'files',
75
+ bundleDropNativeProjectMode: selected.options.nativeProjectMode,
76
+ sourceSkips: upstream('sourcer/SourceSkips').SourceSkips.PackageJsonAndroidAndIosScriptsIfNotContainRun |
77
+ upstream('sourcer/SourceSkips').SourceSkips.ExpoConfigVersions |
78
+ upstream('sourcer/SourceSkips').SourceSkips.GitIgnore,
79
+ ignorePaths: GENERATED_PATHS,
80
+ extraSources: extraSources(projectRoot, platform, selected.options.extraSources ?? []),
81
+ debug: true, silent: true,
82
+ fileHookTransform: (source, chunk, isEnd) => {
83
+ const normalize = /\.gradle(?:\.kts)?$/.test(source.filePath) ? normalizeBuildNumber_1.normalizeAndroidBuildNumber
84
+ : /^ios\/[^/]+\.xcodeproj\/project\.pbxproj$/.test(source.filePath) ? normalizeIosBuildNumber_1.normalizeIosProjectBuildNumber : null;
85
+ if (source.type !== 'file' || !normalize)
86
+ return chunk;
87
+ const chunks = bufferedFiles.get(source.filePath) ?? [];
88
+ if (chunk)
89
+ chunks.push(Buffer.from(chunk));
90
+ if (!isEnd) {
91
+ bufferedFiles.set(source.filePath, chunks);
92
+ return null;
93
+ }
94
+ bufferedFiles.delete(source.filePath);
95
+ return normalize(Buffer.concat(chunks).toString('utf8'));
96
+ },
97
+ });
98
+ if (!options.useCNGForPlatforms[platform] && !fs_1.default.existsSync(path_1.default.join(projectRoot, platform))) {
99
+ throw new Error(`Required native fingerprint directory is missing: ${platform}/.`);
100
+ }
101
+ const collected = await upstream('sourcer/Sourcer').getHashSourcesAsync(projectRoot, options);
102
+ const sources = upstream('Sort').sortSources(upstream('Dedup').dedupSources(collected, projectRoot));
103
+ const fingerprint = await upstream('hash/Hash').createFingerprintFromSourcesAsync(sources, projectRoot, options);
104
+ const runtimeVersion = `bdfp1-${crypto_1.default.createHash('sha256').update(JSON.stringify({
105
+ domain: 'bundle-drop-native-fingerprint', schemeVersion: 1, platform,
106
+ manualBoundary: selected.boundary, nativeHash: fingerprint.hash,
107
+ })).digest('hex')}`;
108
+ return {
109
+ status: 'stable', schemeVersion: 1, platform, runtimeVersion,
110
+ nativeHash: fingerprint.hash, manualBoundary: selected.boundary,
111
+ sources: fingerprint.sources.map((source) => ({
112
+ type: source.type, id: upstream('hash/Hash').createSourceId(source),
113
+ hash: source.hash, reasons: source.reasons, debugInfo: source.debugInfo,
114
+ })),
115
+ };
116
+ }
@@ -0,0 +1,14 @@
1
+ import type { FingerprintOptions } from './types';
2
+ type RuntimeSelection = {
3
+ source: 'manual';
4
+ runtimeVersion: string;
5
+ } | {
6
+ source: 'expo';
7
+ } | {
8
+ source: 'fingerprint';
9
+ boundary: string | null;
10
+ options: FingerprintOptions;
11
+ };
12
+ /** Validate selectors once, independently of Expo/project detection. */
13
+ export declare function selectRuntimeVersion(value: unknown, platform: 'ios' | 'android'): RuntimeSelection;
14
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectRuntimeVersion = selectRuntimeVersion;
4
+ /** Validate selectors once, independently of Expo/project detection. */
5
+ function selectRuntimeVersion(value, platform) {
6
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
7
+ throw new Error(`bundle.drop.config.js must define runtimeVersion.${platform}.`);
8
+ }
9
+ const config = value;
10
+ if (config.source !== undefined) {
11
+ if (config.source !== 'expo')
12
+ throw new Error('Unsupported runtimeVersion.source.');
13
+ if (['compatibilitySource', 'fingerprint', 'ios', 'android'].some(key => config[key] !== undefined)) {
14
+ throw new Error('runtimeVersion.source: expo cannot be combined with compatibilitySource, fingerprint options, or platform literals.');
15
+ }
16
+ return { source: 'expo' };
17
+ }
18
+ if (config.compatibilitySource !== undefined && config.compatibilitySource !== 'manual' && config.compatibilitySource !== 'fingerprint') {
19
+ throw new Error('Unsupported runtimeVersion.compatibilitySource.');
20
+ }
21
+ if (config.compatibilitySource === 'fingerprint') {
22
+ for (const name of ['ios', 'android']) {
23
+ const boundary = config[name];
24
+ if (boundary !== undefined && (typeof boundary !== 'string' || !boundary.trim())) {
25
+ throw new Error(`Fingerprint runtimeVersion.${name} must be a non-empty literal or omitted.`);
26
+ }
27
+ }
28
+ const options = config.fingerprint ?? {};
29
+ if (!options || typeof options !== 'object' || Array.isArray(options)) {
30
+ throw new Error('runtimeVersion.fingerprint must be an object.');
31
+ }
32
+ const typed = options;
33
+ if (Object.keys(options).some(key => !['schemeVersion', 'nativeProjectMode', 'extraSources'].includes(key))) {
34
+ throw new Error('Unsupported runtimeVersion.fingerprint option.');
35
+ }
36
+ if (typed.schemeVersion !== undefined && typed.schemeVersion !== 1) {
37
+ throw new Error('Unsupported fingerprint scheme. Only scheme 1 is available.');
38
+ }
39
+ if (typed.nativeProjectMode !== undefined) {
40
+ if (!typed.nativeProjectMode || typeof typed.nativeProjectMode !== 'object' || Array.isArray(typed.nativeProjectMode)) {
41
+ throw new Error('fingerprint.nativeProjectMode must be a platform map.');
42
+ }
43
+ for (const mode of Object.values(typed.nativeProjectMode)) {
44
+ if (mode !== 'native' && mode !== 'cng')
45
+ throw new Error('Unsupported fingerprint nativeProjectMode.');
46
+ }
47
+ }
48
+ if (typed.extraSources !== undefined && !Array.isArray(typed.extraSources)) {
49
+ throw new Error('fingerprint.extraSources must be an array.');
50
+ }
51
+ return { source: 'fingerprint', boundary: config[platform]?.trim() ?? null, options: typed };
52
+ }
53
+ if (config.fingerprint !== undefined)
54
+ throw new Error('Fingerprint options require compatibilitySource: fingerprint.');
55
+ const literal = config[platform];
56
+ if (typeof literal !== 'string' || !literal.trim()) {
57
+ throw new Error(`bundle.drop.config.js must define a non-empty runtimeVersion.${platform} literal. Use runtimeVersion: { source: 'expo' } only when explicitly opting into Expo runtime policies.`);
58
+ }
59
+ return { source: 'manual', runtimeVersion: literal.trim() };
60
+ }
@@ -0,0 +1,4 @@
1
+ /** Only normalize literal `versionCode 1` / `versionCode = 1` statements inside
2
+ * defaultConfig or a productFlavors block. All ambiguous expressions stay intact.
3
+ */
4
+ export declare function normalizeAndroidBuildNumber(source: string): string;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAndroidBuildNumber = normalizeAndroidBuildNumber;
4
+ /** Tokenize enough Groovy/Kotlin to distinguish code from comments and strings.
5
+ * This deliberately does not evaluate expressions or interpret build scripts.
6
+ */
7
+ function tokenize(source) {
8
+ const tokens = [];
9
+ const pattern = /\/\*[\s\S]*?\*\/|\/\/[^\r\n]*|"""[\s\S]*?"""|'''[\s\S]*?'''|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[A-Za-z_$][\w$]*|\d+(?:[A-Za-z_][\w]*)?|\r?\n|[^\s]/g;
10
+ for (const match of source.matchAll(pattern)) {
11
+ const text = match[0];
12
+ if (text.startsWith('//') || text.startsWith('/*'))
13
+ continue;
14
+ tokens.push({ text, start: match.index, end: match.index + text.length });
15
+ }
16
+ return tokens;
17
+ }
18
+ /** Only normalize literal `versionCode 1` / `versionCode = 1` statements inside
19
+ * defaultConfig or a productFlavors block. All ambiguous expressions stay intact.
20
+ */
21
+ function normalizeAndroidBuildNumber(source) {
22
+ const tokens = tokenize(source);
23
+ // Slashy strings and incomplete literals are outside the recognized grammar.
24
+ if (tokens.some(token => ['/', '"', "'"].includes(token.text)))
25
+ return source;
26
+ const scopes = [];
27
+ const replacements = [];
28
+ for (let index = 0; index < tokens.length; index++) {
29
+ const token = tokens[index];
30
+ if (token.text === '{') {
31
+ scopes.push(tokens[index - 1]?.text ?? '');
32
+ }
33
+ else if (token.text === '}') {
34
+ scopes.pop();
35
+ }
36
+ else if (token.text === 'versionCode' && (scopes.includes('defaultConfig') || scopes.includes('productFlavors'))) {
37
+ const before = tokens[index - 1]?.text;
38
+ const numberIndex = index + (tokens[index + 1]?.text === '=' ? 2 : 1);
39
+ const number = tokens[numberIndex];
40
+ const after = tokens[numberIndex + 1]?.text;
41
+ const nextLineToken = tokens.slice(numberIndex + 1).find(candidate => !['\n', '\r\n'].includes(candidate.text))?.text;
42
+ const hasContinuation = ['\n', '\r\n'].includes(after) &&
43
+ ['+', '-', '*', '%', '.', '?', ':', '(', '[', '{', '&', '|', '^', '<', '>', '=', '!', ','].includes(nextLineToken ?? '');
44
+ if (['\n', '\r\n', '{', ';'].includes(before) && /^\d+$/.test(number?.text ?? '') &&
45
+ (after === undefined || ['\n', '\r\n', ';', '}'].includes(after)) && !hasContinuation) {
46
+ replacements.push(number);
47
+ }
48
+ }
49
+ }
50
+ let result = source;
51
+ for (const token of replacements.reverse()) {
52
+ result = result.slice(0, token.start) + '<bundle-drop-build-number>' + result.slice(token.end);
53
+ }
54
+ return result;
55
+ }
@@ -0,0 +1,4 @@
1
+ /** Normalize only numeric CURRENT_PROJECT_VERSION literals in buildSettings.
2
+ * Expressions, conditional keys, comments and other fields retain their bytes.
3
+ */
4
+ export declare function normalizeIosProjectBuildNumber(source: string): string;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeIosProjectBuildNumber = normalizeIosProjectBuildNumber;
4
+ /** A lexer for the small OpenStep dictionary form written by Xcode. */
5
+ function tokenize(source) {
6
+ const tokens = [];
7
+ const pattern = /\s+|"(?:\\.|[^"\\])*"|[{}=;(),]|[^\s{}=;(),"]+/gy;
8
+ let cursor = 0;
9
+ while (cursor < source.length) {
10
+ if (source.startsWith('/*', cursor)) {
11
+ const end = source.indexOf('*/', cursor + 2);
12
+ if (end < 0)
13
+ return null;
14
+ cursor = end + 2;
15
+ continue;
16
+ }
17
+ if (source.startsWith('//', cursor)) {
18
+ const end = source.indexOf('\n', cursor + 2);
19
+ cursor = end < 0 ? source.length : end;
20
+ continue;
21
+ }
22
+ pattern.lastIndex = cursor;
23
+ const match = pattern.exec(source);
24
+ if (!match)
25
+ return null;
26
+ cursor = pattern.lastIndex;
27
+ if (!/^\s+$/.test(match[0]))
28
+ tokens.push({ text: match[0], start: match.index, end: cursor });
29
+ }
30
+ return tokens;
31
+ }
32
+ /** Normalize only numeric CURRENT_PROJECT_VERSION literals in buildSettings.
33
+ * Expressions, conditional keys, comments and other fields retain their bytes.
34
+ */
35
+ function normalizeIosProjectBuildNumber(source) {
36
+ const tokens = tokenize(source);
37
+ if (!tokens)
38
+ return source;
39
+ const scopes = [];
40
+ const replacements = [];
41
+ for (let index = 0; index < tokens.length; index++) {
42
+ const token = tokens[index];
43
+ if (token.text === '{') {
44
+ scopes.push(tokens[index - 1]?.text === '=' && tokens[index - 2]?.text === 'buildSettings' ? 'buildSettings' : '');
45
+ }
46
+ else if (token.text === '}') {
47
+ scopes.pop();
48
+ }
49
+ else if (token.text === 'CURRENT_PROJECT_VERSION' && scopes[scopes.length - 1] === 'buildSettings' &&
50
+ tokens[index + 1]?.text === '=' && tokens[index + 3]?.text === ';') {
51
+ const value = tokens[index + 2];
52
+ if (/^(?:\d+(?:\.\d+){0,2}|"\d+(?:\.\d+){0,2}")$/.test(value.text))
53
+ replacements.push(value);
54
+ }
55
+ }
56
+ let result = source;
57
+ for (const token of replacements.reverse()) {
58
+ const marker = token.text.startsWith('"') ? '"<bundle-drop-build-number>"' : '<bundle-drop-build-number>';
59
+ result = result.slice(0, token.start) + marker + result.slice(token.end);
60
+ }
61
+ return result;
62
+ }
@@ -0,0 +1,29 @@
1
+ export type FingerprintExtraSource = {
2
+ id: string;
3
+ type: 'file' | 'dir' | 'environment';
4
+ value: string;
5
+ platforms?: ('ios' | 'android')[];
6
+ optional?: boolean;
7
+ };
8
+ export type FingerprintOptions = {
9
+ /** Frozen scheme 1. Calculation changes require a new scheme version. */
10
+ schemeVersion?: 1;
11
+ nativeProjectMode?: Partial<Record<'ios' | 'android', 'native' | 'cng'>>;
12
+ extraSources?: FingerprintExtraSource[];
13
+ };
14
+ export type FingerprintSourceSummary = {
15
+ type: string;
16
+ id: string;
17
+ hash: string | null;
18
+ reasons: string[];
19
+ debugInfo?: unknown;
20
+ };
21
+ export type NativeFingerprint = {
22
+ status: 'stable';
23
+ schemeVersion: 1;
24
+ platform: 'ios' | 'android';
25
+ runtimeVersion: string;
26
+ nativeHash: string;
27
+ manualBoundary: string | null;
28
+ sources: FingerprintSourceSummary[];
29
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function runFingerprintWorker(args: string[]): Promise<void>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runFingerprintWorker = runFingerprintWorker;
4
+ const collect_1 = require("./collect");
5
+ async function runFingerprintWorker(args) {
6
+ const [projectRoot, platform] = args;
7
+ if (!projectRoot || (platform !== 'ios' && platform !== 'android')) {
8
+ process.stderr.write('Usage: fingerprint worker <project-root> ios|android\n');
9
+ process.exitCode = 1;
10
+ }
11
+ else {
12
+ try {
13
+ const value = await (0, collect_1.collectNativeFingerprint)(projectRoot, platform);
14
+ process.stdout.write(`${JSON.stringify(value)}\n`);
15
+ }
16
+ catch (error) {
17
+ process.stderr.write(`${error.message}\n`);
18
+ process.exitCode = 1;
19
+ }
20
+ }
21
+ }
22
+ /* istanbul ignore next -- entry point is exercised by packaged binary experiments */
23
+ if (require.main === module)
24
+ void runFingerprintWorker(process.argv.slice(2));
@@ -0,0 +1,2 @@
1
+ export declare const MAX_REPORTED_INSTALL_HASHES = 50;
2
+ export declare function mergeInstalledReportHistory(installId: string, legacyHashes: string[], reportedHash?: string): Promise<string[]>;