@gfean/react-native-bundle-drop 0.4.3 → 0.4.4

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 (108) hide show
  1. package/BundleDropExpo.podspec +21 -0
  2. package/README.md +250 -124
  3. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +33 -3
  4. package/app.plugin.js +3 -0
  5. package/expo/android/build.gradle +159 -0
  6. package/expo/android/src/main/AndroidManifest.xml +1 -0
  7. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoConfiguration.kt +35 -0
  8. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoIdentityModule.kt +30 -0
  9. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoPackage.kt +29 -0
  10. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoReactNativeHostHandler.kt +16 -0
  11. package/expo/bundle-drop-expo-gradle-plugin/build.gradle +31 -0
  12. package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/BundleDropExpoPlugin.groovy +83 -0
  13. package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/GenerateBundleDropBuildIdentityTask.groovy +57 -0
  14. package/expo/ios/Sources/BundleDropExpoIdentity.m +31 -0
  15. package/expo/ios/Sources/BundleDropExpoReactDelegateHandler.swift +24 -0
  16. package/expo-module.config.json +19 -0
  17. package/ios/BundleDropLocator.swift +7 -1
  18. package/lib/CLI/cli.d.ts +1 -2
  19. package/lib/CLI/cli.js +116 -14
  20. package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
  21. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +55 -0
  22. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -1
  23. package/lib/CLI/scripts/aipowered/backend-client.js +25 -2
  24. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
  25. package/lib/CLI/scripts/aipowered/init-project-config.js +400 -0
  26. package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -1
  27. package/lib/CLI/scripts/aipowered/scanner.js +252 -5
  28. package/lib/CLI/scripts/aipowered/types.d.ts +39 -0
  29. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +12 -0
  30. package/lib/CLI/scripts/aipowered/validate-plan.js +76 -1
  31. package/lib/CLI/scripts/doctor.d.ts +17 -0
  32. package/lib/CLI/scripts/doctor.js +412 -0
  33. package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
  34. package/lib/CLI/scripts/expo/build-receipt.js +223 -0
  35. package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
  36. package/lib/CLI/scripts/expo/configure-expo.js +268 -0
  37. package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
  38. package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
  39. package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
  40. package/lib/CLI/scripts/expo/package-manager.js +84 -0
  41. package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
  42. package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
  43. package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
  44. package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
  45. package/lib/CLI/scripts/init-config.d.ts +18 -1
  46. package/lib/CLI/scripts/init-config.js +29 -8
  47. package/lib/CLI/scripts/init-metro-config.d.ts +7 -0
  48. package/lib/CLI/scripts/init-metro-config.js +28 -8
  49. package/lib/CLI/scripts/login-cli.js +17 -3
  50. package/lib/CLI/scripts/post-init.d.ts +6 -1
  51. package/lib/CLI/scripts/post-init.js +6 -33
  52. package/lib/CLI/scripts/upload-cli.d.ts +1 -0
  53. package/lib/CLI/scripts/upload-cli.js +106 -36
  54. package/lib/context.d.ts +0 -2
  55. package/lib/context.js +18 -2
  56. package/lib/expo/buildIdentity.d.ts +15 -0
  57. package/lib/expo/buildIdentity.js +201 -0
  58. package/lib/expo/buildReceipt.d.ts +42 -0
  59. package/lib/expo/buildReceipt.js +272 -0
  60. package/lib/expo/config.d.ts +7 -0
  61. package/lib/expo/config.js +43 -0
  62. package/lib/expo/configCache.d.ts +1 -0
  63. package/lib/expo/configCache.js +20 -0
  64. package/lib/expo/errors.d.ts +6 -0
  65. package/lib/expo/errors.js +11 -0
  66. package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
  67. package/lib/expo/expoUpdatesOwnership.js +22 -0
  68. package/lib/expo/exportExpoProject.d.ts +21 -0
  69. package/lib/expo/exportExpoProject.js +125 -0
  70. package/lib/expo/exportValidation.d.ts +11 -0
  71. package/lib/expo/exportValidation.js +115 -0
  72. package/lib/expo/index.d.ts +18 -0
  73. package/lib/expo/index.js +25 -0
  74. package/lib/expo/localModules.d.ts +4 -0
  75. package/lib/expo/localModules.js +51 -0
  76. package/lib/expo/nativeIdentity.d.ts +1 -0
  77. package/lib/expo/nativeIdentity.js +17 -0
  78. package/lib/expo/projectType.d.ts +7 -0
  79. package/lib/expo/projectType.js +200 -0
  80. package/lib/expo/runtimeVersion.d.ts +13 -0
  81. package/lib/expo/runtimeVersion.js +45 -0
  82. package/lib/expo/types.d.ts +15 -0
  83. package/lib/expo/types.js +2 -0
  84. package/lib/fs/userProperties.d.ts +0 -2
  85. package/lib/fs/userProperties.js +0 -3
  86. package/lib/index.d.ts +1 -1
  87. package/lib/index.js +1 -2
  88. package/lib/loadConfig.d.ts +15 -7
  89. package/lib/loadConfig.js +2 -19
  90. package/lib/metro.d.ts +17 -0
  91. package/lib/metro.js +57 -0
  92. package/lib/native/bundleDropNative.d.ts +2 -0
  93. package/lib/native/bundleDropNative.js +9 -1
  94. package/lib/runtime/service.js +12 -1
  95. package/lib/scripts/bundle.d.ts +2 -2
  96. package/lib/scripts/bundle.js +10 -97
  97. package/lib/scripts/canonicalArtifact.d.ts +30 -0
  98. package/lib/scripts/canonicalArtifact.js +212 -0
  99. package/lib/scripts/exportProject.d.ts +41 -0
  100. package/lib/scripts/exportProject.js +82 -0
  101. package/package.json +51 -46
  102. package/plugin/constants.js +9 -0
  103. package/plugin/expoUpdates.js +131 -0
  104. package/plugin/index.js +11 -0
  105. package/plugin/markers.js +31 -0
  106. package/plugin/withBundleDrop.js +36 -0
  107. package/plugin/xcodeBuildPhase.js +77 -0
  108. package/react-native.config.js +20 -0
@@ -0,0 +1,412 @@
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.inspectProject = inspectProject;
7
+ exports.runDoctor = runDoctor;
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const expo_1 = require("../../expo");
12
+ const build_receipt_1 = require("./expo/build-receipt");
13
+ const scanner_1 = require("./aipowered/scanner");
14
+ const PACKAGE_NAME = '@gfean/react-native-bundle-drop';
15
+ const ANDROID_MARKER = 'com.bundledrop.EXPO_ENABLED';
16
+ const IOS_MARKER = 'BundleDropExpoEnabled';
17
+ const IOS_RECEIPT_PHASE = 'Bundle Drop: Write iOS build identity';
18
+ const METRO_CONFIG_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs'];
19
+ const pluginName = (plugin) => typeof plugin === 'string'
20
+ ? plugin
21
+ : Array.isArray(plugin) && typeof plugin[0] === 'string'
22
+ ? plugin[0]
23
+ : null;
24
+ const checkExpoUpdates = (projectRoot, exp) => {
25
+ const ownership = (0, expo_1.inspectExpoUpdatesOwnership)(projectRoot, exp);
26
+ if (ownership.state === 'absent') {
27
+ return { name: 'Expo Updates ownership', status: 'pass', message: 'expo-updates is absent.' };
28
+ }
29
+ if (ownership.state === 'disabled') {
30
+ return {
31
+ name: 'Expo Updates ownership',
32
+ status: 'warning',
33
+ message: 'expo-updates is installed but disabled. Launch support requires generated-native and cold-start proof that it yields startup.',
34
+ };
35
+ }
36
+ return {
37
+ name: 'Expo Updates ownership',
38
+ status: 'error',
39
+ message: 'Active expo-updates can own startup. Migrate it and create a new native binary.',
40
+ };
41
+ };
42
+ const findFiles = (directory, suffix) => {
43
+ const files = [];
44
+ if (fs_1.default.existsSync(directory)) {
45
+ for (const entry of fs_1.default.readdirSync(directory, { withFileTypes: true })) {
46
+ if (entry.name === 'Pods' || entry.name === 'build')
47
+ continue;
48
+ const entryPath = path_1.default.join(directory, entry.name);
49
+ if (entry.isDirectory())
50
+ files.push(...findFiles(entryPath, suffix));
51
+ else if (entry.name.endsWith(suffix))
52
+ files.push(entryPath);
53
+ }
54
+ }
55
+ return files;
56
+ };
57
+ const findMetroConfig = (projectRoot) => METRO_CONFIG_EXTENSIONS
58
+ .map(extension => path_1.default.join(projectRoot, `metro.config.${extension}`))
59
+ .find(fs_1.default.existsSync);
60
+ const checkCommittedNativeIntegration = (projectRoot, platform) => {
61
+ if (platform === 'android') {
62
+ const androidRoot = path_1.default.join(projectRoot, 'android');
63
+ if (!fs_1.default.existsSync(androidRoot))
64
+ return null;
65
+ const manifestPath = path_1.default.join(androidRoot, 'app', 'src', 'main', 'AndroidManifest.xml');
66
+ const manifest = fs_1.default.existsSync(manifestPath) ? fs_1.default.readFileSync(manifestPath, 'utf8') : '';
67
+ const escapedMarker = ANDROID_MARKER.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
68
+ const valid = new RegExp(`<meta-data\\b(?=[^>]*android:name=["']${escapedMarker}["'])(?=[^>]*android:value=["']true["'])[^>]*>`).test(manifest);
69
+ return {
70
+ name: 'android generated native integration',
71
+ status: valid ? 'pass' : 'error',
72
+ message: valid
73
+ ? 'Generated Android manifest enables the Bundle Drop Expo startup adapter.'
74
+ : 'Generated Android native files are stale; run the previewed layered prebuild.',
75
+ };
76
+ }
77
+ const iosRoot = path_1.default.join(projectRoot, 'ios');
78
+ if (!fs_1.default.existsSync(iosRoot))
79
+ return null;
80
+ const plistHasMarker = findFiles(iosRoot, '.plist').some(filePath => {
81
+ const content = fs_1.default.readFileSync(filePath, 'utf8');
82
+ return content.includes(`<key>${IOS_MARKER}</key>`) && /<true\s*\/>/.test(content);
83
+ });
84
+ const projectHasReceiptPhase = findFiles(iosRoot, 'project.pbxproj').some(filePath => fs_1.default.readFileSync(filePath, 'utf8').includes(IOS_RECEIPT_PHASE));
85
+ const valid = plistHasMarker && projectHasReceiptPhase;
86
+ return {
87
+ name: 'ios generated native integration',
88
+ status: valid ? 'pass' : 'error',
89
+ message: valid
90
+ ? 'Generated iOS marker and exact build-receipt phase are present.'
91
+ : 'Generated iOS native files are stale; run the previewed layered prebuild.',
92
+ };
93
+ };
94
+ async function inspectExpoProject(projectRoot, platforms) {
95
+ const checks = [];
96
+ const { exp } = (0, expo_1.evaluateExpoConfig)(projectRoot);
97
+ const plugins = (exp.plugins || []).map(pluginName);
98
+ const bundleDropPluginCount = plugins.filter(name => name === PACKAGE_NAME).length;
99
+ checks.push({
100
+ name: 'Expo config plugin',
101
+ status: bundleDropPluginCount === 1 ? 'pass' : 'error',
102
+ message: bundleDropPluginCount === 1
103
+ ? 'Bundle Drop plugin is registered once in evaluated Expo config.'
104
+ : `Bundle Drop plugin must be registered exactly once; found ${bundleDropPluginCount}.`,
105
+ });
106
+ try {
107
+ const packageManifest = require.resolve(`${PACKAGE_NAME}/package.json`, {
108
+ paths: [projectRoot],
109
+ });
110
+ const packageRoot = path_1.default.dirname(packageManifest);
111
+ const moduleConfig = JSON.parse(fs_1.default.readFileSync(path_1.default.join(packageRoot, 'expo-module.config.json'), 'utf8'));
112
+ const valid = moduleConfig.apple?.podspecPath === 'BundleDropExpo.podspec' &&
113
+ moduleConfig.android?.path === 'expo/android' &&
114
+ fs_1.default.existsSync(path_1.default.join(packageRoot, 'react-native.config.js'));
115
+ checks.push({
116
+ name: 'Expo/native autolinking metadata',
117
+ status: valid ? 'pass' : 'error',
118
+ message: valid
119
+ ? 'Expo adapter and bare core targets have isolated autolinking metadata.'
120
+ : 'Packed Bundle Drop autolinking metadata is incomplete.',
121
+ });
122
+ }
123
+ catch (error) {
124
+ checks.push({
125
+ name: 'Expo/native autolinking metadata',
126
+ status: 'error',
127
+ message: `Could not validate the installed Bundle Drop package: ${error.message}`,
128
+ });
129
+ }
130
+ checks.push(checkExpoUpdates(projectRoot, exp));
131
+ for (const platform of platforms) {
132
+ const nativeCheck = checkCommittedNativeIntegration(projectRoot, platform);
133
+ if (nativeCheck)
134
+ checks.push(nativeCheck);
135
+ }
136
+ const metroFile = findMetroConfig(projectRoot);
137
+ const metroContent = metroFile ? fs_1.default.readFileSync(metroFile, 'utf8') : '';
138
+ checks.push({
139
+ name: 'Expo Metro wrapper',
140
+ status: metroContent.includes('withBundleDropExpo') ? 'pass' : 'error',
141
+ message: metroContent.includes('withBundleDropExpo')
142
+ ? 'Existing Expo Metro configuration is preserved through withBundleDropExpo.'
143
+ : 'Metro must use withBundleDropExpo and preserve expo/metro-config.',
144
+ });
145
+ const runtimeAuthorities = new Map(platforms.map(platform => [
146
+ platform,
147
+ (0, expo_1.resolveBundleDropRuntimeVersionAuthority)(projectRoot, platform),
148
+ ]));
149
+ const usesExpoRuntimePolicies = [...runtimeAuthorities.values()]
150
+ .some(authority => authority.source === 'expo');
151
+ const identities = new Map();
152
+ for (const platform of platforms) {
153
+ try {
154
+ const identity = await (0, expo_1.resolveExpoBuildIdentity)(projectRoot, platform);
155
+ identities.set(platform, identity);
156
+ checks.push({
157
+ name: `${platform} build identity`,
158
+ status: 'pass',
159
+ message: `${runtimeAuthorities.get(platform)?.source === 'expo' ? 'Expo policy' : 'Bundle Drop literal'} ` +
160
+ `resolved to ${identity.runtimeVersion}; ` +
161
+ `${identity.javaScriptEngine}, Expo ${identity.expoSdkVersion}, RN ${identity.reactNativeVersion}.`,
162
+ });
163
+ }
164
+ catch (error) {
165
+ const awaitingRemoteNativeVersion = /remote EAS app versions/.test(error.message);
166
+ if (!awaitingRemoteNativeVersion)
167
+ throw error;
168
+ checks.push({
169
+ name: `${platform} build identity`,
170
+ status: 'warning',
171
+ message: 'nativeVersion is binary-backed and uses the exact packaged version. ' +
172
+ 'An authenticated EAS receipt or local release build is required before upload.',
173
+ });
174
+ }
175
+ }
176
+ if (!usesExpoRuntimePolicies) {
177
+ checks.push({
178
+ name: 'Runtime authority',
179
+ status: 'pass',
180
+ message: 'Bundle Drop config owns runtime versions. Uploads do not require or compare Expo build receipts.',
181
+ });
182
+ }
183
+ else {
184
+ const receipt = (0, build_receipt_1.readExpoBuildIdentityReceipt)(projectRoot);
185
+ if (!receipt) {
186
+ checks.push({
187
+ name: 'Native build receipt',
188
+ status: 'warning',
189
+ message: 'Expo runtime policies require a native build receipt before upload.',
190
+ });
191
+ }
192
+ for (const platform of platforms) {
193
+ if (!receipt)
194
+ break;
195
+ const builtIdentity = receipt.identities[platform];
196
+ if (!builtIdentity) {
197
+ checks.push({
198
+ name: `${platform} build/upload parity`,
199
+ status: 'warning',
200
+ message: `No ${platform} identity exists in the current native build receipt.`,
201
+ });
202
+ continue;
203
+ }
204
+ let currentIdentity = identities.get(platform);
205
+ let verificationError;
206
+ if (!currentIdentity || receipt.proofs[platform]?.evidence === 'eas-official-metadata') {
207
+ try {
208
+ currentIdentity = await (0, build_receipt_1.resolveExpoUploadIdentity)({ projectRoot, platform });
209
+ identities.set(platform, currentIdentity);
210
+ }
211
+ catch (error) {
212
+ verificationError = error;
213
+ }
214
+ }
215
+ const matches = !verificationError && Boolean(builtIdentity && currentIdentity &&
216
+ builtIdentity.identityHash === currentIdentity.identityHash);
217
+ checks.push({
218
+ name: `${platform} build/upload parity`,
219
+ status: matches ? 'pass' : 'error',
220
+ message: matches
221
+ ? 'Current Expo identity matches the most recent native build receipt.'
222
+ : verificationError
223
+ ? `Could not verify the exact EAS build receipt: ${verificationError.message}`
224
+ : 'Current Expo identity differs from the most recent native build receipt.',
225
+ });
226
+ }
227
+ }
228
+ checks.push({
229
+ name: 'Expo Go',
230
+ status: 'warning',
231
+ message: 'Expo Go and standard Debug/development-client builds keep Bundle Drop OTA disabled; use a non-Debug/Release native build to test OTA behavior.',
232
+ });
233
+ return checks;
234
+ }
235
+ const checkBarePackageMetadata = (projectRoot) => {
236
+ try {
237
+ const packageManifest = require.resolve(`${PACKAGE_NAME}/package.json`, {
238
+ paths: [projectRoot],
239
+ });
240
+ const packageRoot = path_1.default.dirname(packageManifest);
241
+ const reactNativeConfigPath = path_1.default.join(packageRoot, 'react-native.config.js');
242
+ const reactNativeConfig = fs_1.default.existsSync(reactNativeConfigPath)
243
+ ? fs_1.default.readFileSync(reactNativeConfigPath, 'utf8')
244
+ : '';
245
+ const valid = fs_1.default.existsSync(path_1.default.join(packageRoot, 'BundleDrop.podspec')) &&
246
+ fs_1.default.existsSync(path_1.default.join(packageRoot, 'android')) &&
247
+ reactNativeConfig.includes('BundleDrop.podspec') &&
248
+ reactNativeConfig.includes('BundleDropPackage');
249
+ return {
250
+ name: 'Bare/native autolinking metadata',
251
+ status: valid ? 'pass' : 'error',
252
+ message: valid
253
+ ? 'The installed package exposes the BundleDrop pod and Android package to React Native autolinking.'
254
+ : 'The installed Bundle Drop package has incomplete bare React Native autolinking metadata.',
255
+ };
256
+ }
257
+ catch (error) {
258
+ return {
259
+ name: 'Bare/native autolinking metadata',
260
+ status: 'error',
261
+ message: `Could not validate the installed Bundle Drop package: ${error.message}`,
262
+ };
263
+ }
264
+ };
265
+ const checkBareRuntimeIdentity = (projectRoot, platform) => {
266
+ if (!fs_1.default.existsSync(path_1.default.join(projectRoot, 'bundle.drop.config.js'))) {
267
+ return {
268
+ name: `${platform} runtime identity`,
269
+ status: 'error',
270
+ message: `Cannot resolve runtimeVersion.${platform} without bundle.drop.config.js.`,
271
+ };
272
+ }
273
+ try {
274
+ const authority = (0, expo_1.resolveBundleDropRuntimeVersionAuthority)(projectRoot, platform);
275
+ if (authority.source === 'expo') {
276
+ return {
277
+ name: `${platform} runtime identity`,
278
+ status: 'error',
279
+ message: 'Bare projects require a literal Bundle Drop runtime version, not Expo runtime authority.',
280
+ };
281
+ }
282
+ return {
283
+ name: `${platform} runtime identity`,
284
+ status: 'pass',
285
+ message: `Bundle Drop literal resolved to ${authority.runtimeVersion}.`,
286
+ };
287
+ }
288
+ catch (error) {
289
+ return {
290
+ name: `${platform} runtime identity`,
291
+ status: 'error',
292
+ message: error.message,
293
+ };
294
+ }
295
+ };
296
+ const checkBareStartupIntegration = (projectRoot, platform) => {
297
+ const nativeRoot = path_1.default.join(projectRoot, platform);
298
+ const entrypointNames = platform === 'android'
299
+ ? ['MainApplication.kt', 'MainApplication.java']
300
+ : ['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'];
301
+ const entrypoints = entrypointNames.flatMap(name => findFiles(nativeRoot, name));
302
+ const hasIntegration = entrypoints.some(filePath => {
303
+ const content = fs_1.default.readFileSync(filePath, 'utf8');
304
+ return platform === 'android'
305
+ ? content.includes('BundleDropModule.resolveJSBundleFile') ||
306
+ content.includes('BundleDropNativePaths.getDownloadedBundlePath')
307
+ : content.includes('BundleDropLocator.bundleURL()') ||
308
+ content.includes('[BundleDropLocator bundleURL]');
309
+ });
310
+ return {
311
+ name: `${platform} OTA startup ownership`,
312
+ status: hasIntegration ? 'pass' : 'error',
313
+ message: hasIntegration
314
+ ? `The ${platform} application entrypoint asks Bundle Drop for the cold-start bundle.`
315
+ : `The ${platform} application entrypoint does not hand cold-start bundle resolution to Bundle Drop.`,
316
+ };
317
+ };
318
+ const checkBareNativeAutolinking = (projectRoot, platform) => {
319
+ if (platform === 'ios') {
320
+ const podfileLock = path_1.default.join(projectRoot, 'ios', 'Podfile.lock');
321
+ if (!fs_1.default.existsSync(podfileLock)) {
322
+ return {
323
+ name: 'ios native autolinking',
324
+ status: 'warning',
325
+ message: 'Podfile.lock does not exist yet; run pod install or build iOS to verify native linking.',
326
+ };
327
+ }
328
+ const linked = fs_1.default.readFileSync(podfileLock, 'utf8').includes('BundleDrop');
329
+ return {
330
+ name: 'ios native autolinking',
331
+ status: linked ? 'pass' : 'error',
332
+ message: linked
333
+ ? 'Podfile.lock includes the BundleDrop pod.'
334
+ : 'Podfile.lock exists but does not include the BundleDrop pod; run pod install.',
335
+ };
336
+ }
337
+ const candidates = [
338
+ path_1.default.join(projectRoot, 'android', 'build', 'generated', 'autolinking', 'autolinking.json'),
339
+ path_1.default.join(projectRoot, 'android', 'app', 'build', 'generated', 'autolinking', 'src', 'main', 'java', 'com', 'facebook', 'react', 'PackageList.java'),
340
+ path_1.default.join(projectRoot, 'android', 'app', 'build', 'generated', 'rncli', 'src', 'main', 'java', 'com', 'facebook', 'react', 'PackageList.java'),
341
+ ].filter(fs_1.default.existsSync);
342
+ if (!candidates.length) {
343
+ return {
344
+ name: 'android native autolinking',
345
+ status: 'warning',
346
+ message: 'No generated Android autolinking output exists yet; build Android to verify native linking.',
347
+ };
348
+ }
349
+ const linked = candidates.some(filePath => {
350
+ const content = fs_1.default.readFileSync(filePath, 'utf8');
351
+ return content.includes(PACKAGE_NAME) || content.includes('BundleDropPackage');
352
+ });
353
+ return {
354
+ name: 'android native autolinking',
355
+ status: linked ? 'pass' : 'error',
356
+ message: linked
357
+ ? 'Generated Android autolinking includes BundleDropPackage.'
358
+ : 'Generated Android autolinking exists but does not include BundleDropPackage; rebuild Android.',
359
+ };
360
+ };
361
+ function inspectBareProject(projectRoot, platforms) {
362
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
363
+ const metroPath = findMetroConfig(projectRoot);
364
+ const metroContent = metroPath ? fs_1.default.readFileSync(metroPath, 'utf8') : '';
365
+ const checks = [
366
+ {
367
+ name: 'Bundle Drop config',
368
+ status: fs_1.default.existsSync(configPath) ? 'pass' : 'error',
369
+ message: fs_1.default.existsSync(configPath)
370
+ ? 'bundle.drop.config.js exists.'
371
+ : 'bundle.drop.config.js is missing.',
372
+ },
373
+ {
374
+ name: 'Bare Metro alias',
375
+ status: metroContent.includes('bundle-drop-config') ? 'pass' : 'error',
376
+ message: metroContent.includes('bundle-drop-config')
377
+ ? 'Metro resolves bundle-drop-config.'
378
+ : 'Metro does not contain the bundle-drop-config alias.',
379
+ },
380
+ checkBarePackageMetadata(projectRoot),
381
+ ];
382
+ for (const platform of platforms) {
383
+ checks.push(checkBareRuntimeIdentity(projectRoot, platform));
384
+ checks.push(checkBareStartupIntegration(projectRoot, platform));
385
+ checks.push(checkBareNativeAutolinking(projectRoot, platform));
386
+ }
387
+ return checks;
388
+ }
389
+ async function inspectProject(options = {}) {
390
+ const projectRoot = (0, scanner_1.findProjectRoot)(options.cwd || process.cwd());
391
+ const projectType = (0, expo_1.detectProjectType)({
392
+ projectRoot,
393
+ explicitType: options.projectType,
394
+ });
395
+ const platforms = options.platform ? [options.platform] : ['ios', 'android'];
396
+ const checks = projectType === 'expo'
397
+ ? await inspectExpoProject(projectRoot, platforms)
398
+ : inspectBareProject(projectRoot, platforms);
399
+ return { projectRoot, projectType, checks };
400
+ }
401
+ async function runDoctor(options = {}) {
402
+ const result = await inspectProject(options);
403
+ console.log(chalk_1.default.cyan(`Bundle Drop doctor: ${result.projectType} project`));
404
+ for (const check of result.checks) {
405
+ const symbol = check.status === 'pass' ? '✅' : check.status === 'warning' ? '⚠️' : '❌';
406
+ console.log(`${symbol} ${check.name}: ${check.message}`);
407
+ }
408
+ const errors = result.checks.filter(check => check.status === 'error');
409
+ if (errors.length) {
410
+ throw new Error(`Bundle Drop doctor found ${errors.length} blocking issue(s).`);
411
+ }
412
+ }
@@ -0,0 +1,26 @@
1
+ import type { ExpoBuildIdentity, MobilePlatform } from '../../../expo';
2
+ import type { ExpoBuildIdentityReceipt } from '../../../metro';
3
+ export declare const IOS_EMBEDDED_BUILD_CANDIDATE = ".bundle-drop-build-identity.json";
4
+ export declare const ANDROID_APK_EMBEDDED_BUILD_CANDIDATE = "assets/bundle-drop/build-identity.json";
5
+ export declare const ANDROID_AAB_EMBEDDED_BUILD_CANDIDATE = "base/assets/bundle-drop/build-identity.json";
6
+ export declare const createEmbeddedBuildCandidate: (params: {
7
+ platform: MobilePlatform;
8
+ identityHash: string;
9
+ integrationGeneration: string;
10
+ runtimeVersion: string;
11
+ }) => Record<string, unknown>;
12
+ export declare const serializeEmbeddedBuildCandidate: (candidate: Record<string, unknown>) => Buffer;
13
+ export declare const readAndroidEmbeddedBuildCandidate: (artifactPath: string) => Buffer;
14
+ export declare function readExpoBuildIdentityReceipt(projectRoot: string, receiptFile?: string, validationPlatform?: MobilePlatform): ExpoBuildIdentityReceipt | null;
15
+ export declare function assertExpoUploadMatchesBuild(params: {
16
+ projectRoot: string;
17
+ platform: MobilePlatform;
18
+ uploadIdentity: ExpoBuildIdentity;
19
+ requireReceipt?: boolean;
20
+ receiptFile?: string;
21
+ }): void;
22
+ export declare function resolveExpoUploadIdentity(params: {
23
+ projectRoot: string;
24
+ platform: MobilePlatform;
25
+ receiptFile?: string;
26
+ }): Promise<ExpoBuildIdentity>;
@@ -0,0 +1,223 @@
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.readAndroidEmbeddedBuildCandidate = exports.serializeEmbeddedBuildCandidate = exports.createEmbeddedBuildCandidate = exports.ANDROID_AAB_EMBEDDED_BUILD_CANDIDATE = exports.ANDROID_APK_EMBEDDED_BUILD_CANDIDATE = exports.IOS_EMBEDDED_BUILD_CANDIDATE = void 0;
7
+ exports.readExpoBuildIdentityReceipt = readExpoBuildIdentityReceipt;
8
+ exports.assertExpoUploadMatchesBuild = assertExpoUploadMatchesBuild;
9
+ exports.resolveExpoUploadIdentity = resolveExpoUploadIdentity;
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const crypto_1 = __importDefault(require("crypto"));
12
+ const child_process_1 = __importDefault(require("child_process"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const adm_zip_1 = __importDefault(require("adm-zip"));
15
+ const expo_1 = require("../../../expo");
16
+ const buildReceipt_1 = require("../../../expo/buildReceipt");
17
+ const eas_build_proof_1 = require("./eas-build-proof");
18
+ exports.IOS_EMBEDDED_BUILD_CANDIDATE = '.bundle-drop-build-identity.json';
19
+ exports.ANDROID_APK_EMBEDDED_BUILD_CANDIDATE = 'assets/bundle-drop/build-identity.json';
20
+ exports.ANDROID_AAB_EMBEDDED_BUILD_CANDIDATE = 'base/assets/bundle-drop/build-identity.json';
21
+ const createEmbeddedBuildCandidate = (params) => ({
22
+ schemaVersion: 1,
23
+ platform: params.platform,
24
+ identityHash: params.identityHash,
25
+ integrationGeneration: params.integrationGeneration,
26
+ runtimeVersion: params.runtimeVersion,
27
+ });
28
+ exports.createEmbeddedBuildCandidate = createEmbeddedBuildCandidate;
29
+ const serializeEmbeddedBuildCandidate = (candidate) => Buffer.from(`${JSON.stringify(candidate)}\n`, 'utf8');
30
+ exports.serializeEmbeddedBuildCandidate = serializeEmbeddedBuildCandidate;
31
+ const sha256File = (filePath) => crypto_1.default.createHash('sha256').update(fs_1.default.readFileSync(filePath)).digest('hex');
32
+ const readAndroidEmbeddedBuildCandidate = (artifactPath) => {
33
+ let archive;
34
+ try {
35
+ archive = new adm_zip_1.default(artifactPath);
36
+ }
37
+ catch {
38
+ throw new Error('Bundle Drop Android build artifact is not a readable APK/AAB archive.');
39
+ }
40
+ const expectedPath = artifactPath.toLowerCase().endsWith('.aab')
41
+ ? exports.ANDROID_AAB_EMBEDDED_BUILD_CANDIDATE
42
+ : exports.ANDROID_APK_EMBEDDED_BUILD_CANDIDATE;
43
+ const candidates = archive.getEntries().filter(entry => entry.entryName === expectedPath && !entry.isDirectory);
44
+ if (candidates.length !== 1) {
45
+ throw new Error(`Bundle Drop Android build artifact must contain exactly one signed identity candidate at ${expectedPath}.`);
46
+ }
47
+ const candidateEntry = candidates[0];
48
+ if (candidateEntry.header.size === 0 || candidateEntry.header.size > 64 * 1024) {
49
+ throw new Error('Bundle Drop Android embedded build identity candidate has an invalid size.');
50
+ }
51
+ const content = candidateEntry.getData();
52
+ if (content.length !== candidateEntry.header.size) {
53
+ throw new Error('Bundle Drop Android embedded build identity candidate has an invalid size.');
54
+ }
55
+ return content;
56
+ };
57
+ exports.readAndroidEmbeddedBuildCandidate = readAndroidEmbeddedBuildCandidate;
58
+ const parseEmbeddedCandidate = (platform, content) => {
59
+ try {
60
+ return JSON.parse(content.toString('utf8'));
61
+ }
62
+ catch {
63
+ throw new Error(`Bundle Drop ${platform} embedded build identity candidate is malformed.`);
64
+ }
65
+ };
66
+ const verifyLocalBuildProof = (platform, identity, proof) => {
67
+ if (!proof || proof.evidence === 'eas-official-metadata')
68
+ return;
69
+ if (!fs_1.default.existsSync(proof.artifactPath)) {
70
+ throw new Error(`Bundle Drop ${platform} build artifact no longer exists at ${proof.artifactPath}.`);
71
+ }
72
+ if (platform === 'android') {
73
+ if (proof.evidence !== 'android-signed-artifact' || !fs_1.default.statSync(proof.artifactPath).isFile()) {
74
+ throw new Error('Bundle Drop Android build proof does not reference an APK/AAB file.');
75
+ }
76
+ if (!/\.(apk|aab)$/i.test(proof.artifactPath)) {
77
+ throw new Error('Bundle Drop Android build proof must reference an APK or AAB.');
78
+ }
79
+ if (sha256File(proof.artifactPath) !== proof.artifactSha256) {
80
+ throw new Error('Bundle Drop Android build artifact changed after its receipt was created.');
81
+ }
82
+ const candidateContent = (0, exports.readAndroidEmbeddedBuildCandidate)(proof.artifactPath);
83
+ if (crypto_1.default.createHash('sha256').update(candidateContent).digest('hex') !== proof.embeddedCandidateSha256) {
84
+ throw new Error('Bundle Drop Android embedded build identity candidate does not match its receipt.');
85
+ }
86
+ const expectedCandidate = (0, exports.createEmbeddedBuildCandidate)({
87
+ platform: 'android',
88
+ identityHash: identity.identityHash,
89
+ integrationGeneration: proof.integrationGeneration,
90
+ runtimeVersion: identity.runtimeVersion,
91
+ });
92
+ parseEmbeddedCandidate('android', candidateContent);
93
+ if (!candidateContent.equals((0, exports.serializeEmbeddedBuildCandidate)(expectedCandidate))) {
94
+ throw new Error('Bundle Drop Android embedded build identity candidate is not bound to this build proof.');
95
+ }
96
+ return;
97
+ }
98
+ if (proof.evidence !== 'ios-signed-app' || !fs_1.default.statSync(proof.artifactPath).isDirectory()) {
99
+ throw new Error('Bundle Drop iOS build proof does not reference an app bundle.');
100
+ }
101
+ const candidatePath = path_1.default.join(proof.artifactPath, exports.IOS_EMBEDDED_BUILD_CANDIDATE);
102
+ if (!fs_1.default.existsSync(candidatePath) || !fs_1.default.statSync(candidatePath).isFile()) {
103
+ throw new Error('Bundle Drop iOS app does not contain its embedded build identity candidate.');
104
+ }
105
+ const candidateContent = fs_1.default.readFileSync(candidatePath);
106
+ if (crypto_1.default.createHash('sha256').update(candidateContent).digest('hex') !== proof.embeddedCandidateSha256) {
107
+ throw new Error('Bundle Drop iOS embedded build identity candidate does not match its receipt.');
108
+ }
109
+ const candidate = parseEmbeddedCandidate('ios', candidateContent);
110
+ const expectedCandidate = {
111
+ ...(0, exports.createEmbeddedBuildCandidate)({
112
+ platform: 'ios',
113
+ identityHash: identity.identityHash,
114
+ integrationGeneration: proof.integrationGeneration,
115
+ runtimeVersion: identity.runtimeVersion,
116
+ }),
117
+ createdAt: proof.createdAt,
118
+ };
119
+ if (JSON.stringify(candidate) !== JSON.stringify(expectedCandidate)) {
120
+ throw new Error('Bundle Drop iOS embedded build identity candidate is not bound to this build proof.');
121
+ }
122
+ const verification = child_process_1.default.spawnSync('/usr/bin/codesign', ['--verify', '--deep', '--strict', proof.artifactPath], { encoding: 'utf8', shell: false });
123
+ if (verification.error || verification.status !== 0) {
124
+ const detail = verification.error?.message || verification.stderr?.trim() || 'codesign rejected the app';
125
+ throw new Error(`Bundle Drop iOS app signature verification failed: ${detail}`);
126
+ }
127
+ };
128
+ function readExpoBuildIdentityReceipt(projectRoot, receiptFile, validationPlatform) {
129
+ const receiptPath = receiptFile
130
+ ? path_1.default.resolve(projectRoot, receiptFile)
131
+ : path_1.default.join(projectRoot, '.bundle-drop', 'build-identity.json');
132
+ if (!fs_1.default.existsSync(receiptPath))
133
+ return null;
134
+ let receipt;
135
+ try {
136
+ receipt = (0, buildReceipt_1.parseExpoBuildIdentityReceipt)(JSON.parse(fs_1.default.readFileSync(receiptPath, 'utf8')), (0, buildReceipt_1.resolveExpoIntegrationGeneration)());
137
+ }
138
+ catch (error) {
139
+ const reason = error instanceof SyntaxError
140
+ ? `Bundle Drop build identity receipt is malformed: ${error.message}`
141
+ : error.message;
142
+ throw new Error(reason);
143
+ }
144
+ const platforms = validationPlatform
145
+ ? [validationPlatform]
146
+ : ['ios', 'android'];
147
+ for (const platform of platforms) {
148
+ const identity = receipt.identities[platform];
149
+ const proof = receipt.proofs[platform];
150
+ if (identity && proof)
151
+ verifyLocalBuildProof(platform, identity, proof);
152
+ }
153
+ return receipt;
154
+ }
155
+ function assertExpoUploadMatchesBuild(params) {
156
+ const receipt = readExpoBuildIdentityReceipt(params.projectRoot, params.receiptFile, params.platform);
157
+ if (!receipt) {
158
+ if (params.requireReceipt) {
159
+ throw new Error('No native build identity receipt is available. Build the app locally first, or provide an ' +
160
+ 'exact user-controlled EAS build receipt; Bundle Drop will not guess runtime identity.');
161
+ }
162
+ return;
163
+ }
164
+ const buildIdentity = receipt.identities[params.platform];
165
+ if (!buildIdentity) {
166
+ throw new Error(`Build identity receipt does not contain ${params.platform}.`);
167
+ }
168
+ if (buildIdentity.identityHash !== params.uploadIdentity.identityHash) {
169
+ throw new Error(`Expo ${params.platform} build/upload identity mismatch. ` +
170
+ `Built ${buildIdentity.runtimeVersion}, upload resolved ${params.uploadIdentity.runtimeVersion}. ` +
171
+ 'Create a new native build or restore the exact build configuration before uploading.');
172
+ }
173
+ }
174
+ async function resolveExpoUploadIdentity(params) {
175
+ const runtimeAuthority = (0, expo_1.resolveBundleDropRuntimeVersionAuthority)(params.projectRoot, params.platform);
176
+ if (runtimeAuthority.source === 'bundle-drop' && !params.receiptFile) {
177
+ return (0, expo_1.resolveExpoBuildIdentity)(params.projectRoot, params.platform);
178
+ }
179
+ const receipt = readExpoBuildIdentityReceipt(params.projectRoot, params.receiptFile, params.platform);
180
+ if (!receipt) {
181
+ throw new Error('Expo upload requires an exact native build identity receipt. Build locally first, or pass ' +
182
+ '--build-receipt with an officially resolved EAS build receipt.');
183
+ }
184
+ const buildIdentity = receipt.identities[params.platform];
185
+ if (!buildIdentity) {
186
+ throw new Error(`Build identity receipt does not contain ${params.platform}.`);
187
+ }
188
+ const proof = receipt.proofs[params.platform];
189
+ if (proof?.evidence === 'eas-official-metadata') {
190
+ return (0, eas_build_proof_1.resolveOfficialEasBuildIdentity)({
191
+ projectRoot: params.projectRoot,
192
+ platform: params.platform,
193
+ receiptIdentity: buildIdentity,
194
+ proof,
195
+ });
196
+ }
197
+ let uploadIdentity;
198
+ try {
199
+ uploadIdentity = await (0, expo_1.resolveExpoBuildIdentity)(params.projectRoot, params.platform);
200
+ }
201
+ catch (error) {
202
+ if (!/remote EAS app versions/.test(error.message))
203
+ throw error;
204
+ const nativePrefix = `${buildIdentity.appVersion}(`;
205
+ if (!buildIdentity.nativeVersion.startsWith(nativePrefix) ||
206
+ !buildIdentity.nativeVersion.endsWith(')')) {
207
+ throw new Error('The local build receipt has an invalid Expo native version.');
208
+ }
209
+ const officialNativeBuildVersion = buildIdentity.nativeVersion.slice(nativePrefix.length, -1);
210
+ uploadIdentity = await (0, expo_1.resolveExpoBuildIdentity)(params.projectRoot, params.platform, {
211
+ officialAppVersion: buildIdentity.appVersion,
212
+ officialNativeBuildVersion,
213
+ });
214
+ }
215
+ assertExpoUploadMatchesBuild({
216
+ projectRoot: params.projectRoot,
217
+ platform: params.platform,
218
+ uploadIdentity,
219
+ requireReceipt: true,
220
+ receiptFile: params.receiptFile,
221
+ });
222
+ return uploadIdentity;
223
+ }