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

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 (115) 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 +151 -56
  20. package/lib/CLI/logo.js +1 -1
  21. package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
  22. package/lib/CLI/scripts/aipowered/{apply-plan.js → apply-setup-plan.js} +24 -19
  23. package/lib/CLI/scripts/aipowered/backend-client.d.ts +4 -4
  24. package/lib/CLI/scripts/aipowered/backend-client.js +7 -7
  25. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
  26. package/lib/CLI/scripts/aipowered/init-project-config.js +418 -0
  27. package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -3
  28. package/lib/CLI/scripts/aipowered/scanner.js +225 -201
  29. package/lib/CLI/scripts/aipowered/types.d.ts +37 -33
  30. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +9 -2
  31. package/lib/CLI/scripts/aipowered/validate-plan.js +70 -119
  32. package/lib/CLI/scripts/bare-metro-config.d.ts +7 -0
  33. package/lib/CLI/scripts/{init-metro-config.js → bare-metro-config.js} +16 -30
  34. package/lib/CLI/scripts/doctor.d.ts +17 -0
  35. package/lib/CLI/scripts/doctor.js +410 -0
  36. package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
  37. package/lib/CLI/scripts/expo/build-receipt.js +223 -0
  38. package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
  39. package/lib/CLI/scripts/expo/configure-expo.js +268 -0
  40. package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
  41. package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
  42. package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
  43. package/lib/CLI/scripts/expo/package-manager.js +84 -0
  44. package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
  45. package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
  46. package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
  47. package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
  48. package/lib/CLI/scripts/init-config.d.ts +18 -1
  49. package/lib/CLI/scripts/init-config.js +29 -8
  50. package/lib/CLI/scripts/login-cli.js +21 -3
  51. package/lib/CLI/scripts/native-setup-contract.d.ts +7 -0
  52. package/lib/CLI/scripts/native-setup-contract.js +101 -0
  53. package/lib/CLI/scripts/post-init.d.ts +6 -1
  54. package/lib/CLI/scripts/post-init.js +6 -33
  55. package/lib/CLI/scripts/upload-cli.d.ts +1 -0
  56. package/lib/CLI/scripts/upload-cli.js +106 -36
  57. package/lib/context.d.ts +0 -2
  58. package/lib/context.js +18 -2
  59. package/lib/expo/buildIdentity.d.ts +15 -0
  60. package/lib/expo/buildIdentity.js +201 -0
  61. package/lib/expo/buildReceipt.d.ts +42 -0
  62. package/lib/expo/buildReceipt.js +272 -0
  63. package/lib/expo/config.d.ts +7 -0
  64. package/lib/expo/config.js +43 -0
  65. package/lib/expo/configCache.d.ts +1 -0
  66. package/lib/expo/configCache.js +20 -0
  67. package/lib/expo/errors.d.ts +6 -0
  68. package/lib/expo/errors.js +11 -0
  69. package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
  70. package/lib/expo/expoUpdatesOwnership.js +22 -0
  71. package/lib/expo/exportExpoProject.d.ts +21 -0
  72. package/lib/expo/exportExpoProject.js +125 -0
  73. package/lib/expo/exportValidation.d.ts +11 -0
  74. package/lib/expo/exportValidation.js +115 -0
  75. package/lib/expo/index.d.ts +18 -0
  76. package/lib/expo/index.js +25 -0
  77. package/lib/expo/localModules.d.ts +4 -0
  78. package/lib/expo/localModules.js +51 -0
  79. package/lib/expo/nativeIdentity.d.ts +1 -0
  80. package/lib/expo/nativeIdentity.js +17 -0
  81. package/lib/expo/projectType.d.ts +7 -0
  82. package/lib/expo/projectType.js +200 -0
  83. package/lib/expo/runtimeVersion.d.ts +13 -0
  84. package/lib/expo/runtimeVersion.js +45 -0
  85. package/lib/expo/types.d.ts +15 -0
  86. package/lib/expo/types.js +2 -0
  87. package/lib/fs/userProperties.d.ts +0 -2
  88. package/lib/fs/userProperties.js +0 -3
  89. package/lib/index.d.ts +1 -1
  90. package/lib/index.js +1 -2
  91. package/lib/loadConfig.d.ts +15 -7
  92. package/lib/loadConfig.js +2 -19
  93. package/lib/metro.d.ts +17 -0
  94. package/lib/metro.js +57 -0
  95. package/lib/native/bundleDropNative.d.ts +2 -0
  96. package/lib/native/bundleDropNative.js +9 -1
  97. package/lib/runtime/service.js +12 -1
  98. package/lib/scripts/bundle.d.ts +2 -2
  99. package/lib/scripts/bundle.js +10 -97
  100. package/lib/scripts/canonicalArtifact.d.ts +30 -0
  101. package/lib/scripts/canonicalArtifact.js +212 -0
  102. package/lib/scripts/exportProject.d.ts +41 -0
  103. package/lib/scripts/exportProject.js +82 -0
  104. package/package.json +51 -46
  105. package/plugin/constants.js +9 -0
  106. package/plugin/expoUpdates.js +131 -0
  107. package/plugin/index.js +11 -0
  108. package/plugin/markers.js +31 -0
  109. package/plugin/withBundleDrop.js +36 -0
  110. package/plugin/xcodeBuildPhase.js +77 -0
  111. package/react-native.config.js +15 -0
  112. package/lib/CLI/scripts/aipowered/apply-plan.d.ts +0 -10
  113. package/lib/CLI/scripts/aipowered/init-native-config.d.ts +0 -2
  114. package/lib/CLI/scripts/aipowered/init-native-config.js +0 -131
  115. package/lib/CLI/scripts/init-metro-config.d.ts +0 -2
@@ -0,0 +1,325 @@
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.parseAndroidBuildCandidateArguments = exports.parseBuildReceiptArguments = void 0;
7
+ exports.writeAndroidBuildIdentityCandidate = writeAndroidBuildIdentityCandidate;
8
+ exports.writeExpoBuildReceipt = writeExpoBuildReceipt;
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const child_process_1 = __importDefault(require("child_process"));
13
+ const expo_1 = require("../../../expo");
14
+ const buildReceipt_1 = require("../../../expo/buildReceipt");
15
+ const build_receipt_1 = require("./build-receipt");
16
+ const IOS_RUNTIME_INFO_PLIST_KEY = 'BundleDropRuntimeVersion';
17
+ const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
18
+ const writeJsonAtomically = (filePath, value) => {
19
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
20
+ const temporaryPath = `${filePath}.${process.pid}.tmp`;
21
+ fs_1.default.writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
22
+ fs_1.default.renameSync(temporaryPath, filePath);
23
+ };
24
+ const writeBufferAtomically = (filePath, content) => {
25
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
26
+ const temporaryPath = `${filePath}.${process.pid}.tmp`;
27
+ fs_1.default.writeFileSync(temporaryPath, content);
28
+ fs_1.default.renameSync(temporaryPath, filePath);
29
+ };
30
+ const runSignatureVerification = (executable, args, label) => {
31
+ const result = child_process_1.default.spawnSync(executable, args, { encoding: 'utf8', shell: false });
32
+ if (result.error || result.status !== 0) {
33
+ const detail = result.error?.message || result.stderr?.trim() || `${label} rejected the artifact`;
34
+ throw new Error(`Bundle Drop Android artifact signature verification failed: ${detail}`);
35
+ }
36
+ };
37
+ const findApkSigner = (androidSdkRoot) => {
38
+ const sdkRoot = androidSdkRoot || process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME;
39
+ if (!sdkRoot) {
40
+ throw new Error('Bundle Drop cannot verify an APK signature without the Android SDK path.');
41
+ }
42
+ const buildToolsRoot = path_1.default.join(path_1.default.resolve(sdkRoot), 'build-tools');
43
+ if (!fs_1.default.existsSync(buildToolsRoot)) {
44
+ throw new Error(`Bundle Drop cannot find Android build-tools under ${buildToolsRoot}.`);
45
+ }
46
+ const candidates = fs_1.default.readdirSync(buildToolsRoot)
47
+ .map(version => path_1.default.join(buildToolsRoot, version, process.platform === 'win32' ? 'apksigner.bat' : 'apksigner'))
48
+ .filter(candidate => fs_1.default.existsSync(candidate))
49
+ .sort((left, right) => right.localeCompare(left, undefined, { numeric: true }));
50
+ if (!candidates[0])
51
+ throw new Error('Bundle Drop cannot find apksigner in Android build-tools.');
52
+ return candidates[0];
53
+ };
54
+ const verifyAndroidArtifactSignature = (artifactPath, androidSdkRoot) => {
55
+ if (artifactPath.toLowerCase().endsWith('.apk')) {
56
+ runSignatureVerification(findApkSigner(androidSdkRoot), ['verify', artifactPath], 'apksigner');
57
+ return;
58
+ }
59
+ // jarsigner reports an unsigned JAR as a successful verification unless
60
+ // strict mode is enabled. AAB proof must never be issued for that result.
61
+ runSignatureVerification('jarsigner', ['-verify', '-strict', artifactPath], 'jarsigner');
62
+ };
63
+ const readIosBundleValue = (artifactPath, key) => {
64
+ if (!fs_1.default.existsSync(artifactPath)) {
65
+ throw new Error(`Bundle Drop ios artifact does not exist at ${artifactPath}.`);
66
+ }
67
+ if (!fs_1.default.statSync(artifactPath).isDirectory() || !artifactPath.endsWith('.app')) {
68
+ throw new Error('Bundle Drop iOS receipt writer requires an exact .app bundle directory.');
69
+ }
70
+ const infoPlistPath = path_1.default.join(artifactPath, 'Info.plist');
71
+ if (!fs_1.default.existsSync(infoPlistPath) || !fs_1.default.statSync(infoPlistPath).isFile()) {
72
+ throw new Error('Bundle Drop iOS receipt writer requires the packaged app Info.plist.');
73
+ }
74
+ const result = child_process_1.default.spawnSync('/usr/bin/plutil', ['-extract', key, 'raw', '-o', '-', infoPlistPath], { encoding: 'utf8', shell: false });
75
+ const value = result.stdout?.trim();
76
+ if (result.error || result.status !== 0 || !value) {
77
+ const detail = result.error?.message || result.stderr?.trim() || `${key} is empty`;
78
+ throw new Error(`Bundle Drop could not read ${key} from the packaged iOS app: ${detail}`);
79
+ }
80
+ return value;
81
+ };
82
+ const writeIosRuntimeVersion = (artifactPath, runtimeVersion) => {
83
+ const infoPlistPath = path_1.default.join(artifactPath, 'Info.plist');
84
+ const replaceResult = child_process_1.default.spawnSync('/usr/bin/plutil', ['-replace', IOS_RUNTIME_INFO_PLIST_KEY, '-string', runtimeVersion, infoPlistPath], { encoding: 'utf8', shell: false });
85
+ if (!replaceResult.error && replaceResult.status === 0)
86
+ return;
87
+ const insertResult = child_process_1.default.spawnSync('/usr/bin/plutil', ['-insert', IOS_RUNTIME_INFO_PLIST_KEY, '-string', runtimeVersion, infoPlistPath], { encoding: 'utf8', shell: false });
88
+ if (insertResult.error || insertResult.status !== 0) {
89
+ const detail = insertResult.error?.message || insertResult.stderr?.trim() ||
90
+ replaceResult.error?.message || replaceResult.stderr?.trim() || 'plutil rejected the value';
91
+ throw new Error(`Bundle Drop could not embed the iOS runtime version: ${detail}`);
92
+ }
93
+ };
94
+ const resolvePackagedBuildVersions = (platform, artifactPath, options) => {
95
+ if (platform === 'android') {
96
+ return {
97
+ officialAppVersion: options.officialAppVersion,
98
+ officialNativeBuildVersion: options.officialNativeBuildVersion,
99
+ };
100
+ }
101
+ return {
102
+ officialAppVersion: readIosBundleValue(artifactPath, 'CFBundleShortVersionString'),
103
+ officialNativeBuildVersion: readIosBundleValue(artifactPath, 'CFBundleVersion'),
104
+ };
105
+ };
106
+ const createLocalProof = (params) => {
107
+ const artifactPath = path_1.default.resolve(params.artifactPath);
108
+ if (!fs_1.default.existsSync(artifactPath)) {
109
+ throw new Error(`Bundle Drop ${params.platform} artifact does not exist at ${artifactPath}.`);
110
+ }
111
+ if (params.platform === 'android') {
112
+ if (!fs_1.default.statSync(artifactPath).isFile() || !/\.(apk|aab)$/i.test(artifactPath)) {
113
+ throw new Error('Bundle Drop Android receipt writer requires an exact APK or AAB file.');
114
+ }
115
+ verifyAndroidArtifactSignature(artifactPath, params.androidSdkRoot);
116
+ const embeddedCandidate = (0, build_receipt_1.readAndroidEmbeddedBuildCandidate)(artifactPath);
117
+ const expectedCandidate = (0, build_receipt_1.createEmbeddedBuildCandidate)({
118
+ platform: 'android',
119
+ identityHash: params.identityHash,
120
+ integrationGeneration: params.integrationGeneration,
121
+ runtimeVersion: params.runtimeVersion,
122
+ });
123
+ try {
124
+ JSON.parse(embeddedCandidate.toString('utf8'));
125
+ }
126
+ catch {
127
+ throw new Error('Bundle Drop Android embedded build identity candidate is malformed.');
128
+ }
129
+ if (!embeddedCandidate.equals((0, build_receipt_1.serializeEmbeddedBuildCandidate)(expectedCandidate))) {
130
+ throw new Error('Bundle Drop Android signed artifact contains a different build identity candidate.');
131
+ }
132
+ return {
133
+ createdAt: params.createdAt,
134
+ evidence: 'android-signed-artifact',
135
+ integrationGeneration: params.integrationGeneration,
136
+ artifactPath,
137
+ artifactSha256: sha256(fs_1.default.readFileSync(artifactPath)),
138
+ embeddedCandidateSha256: sha256(embeddedCandidate),
139
+ };
140
+ }
141
+ const candidate = {
142
+ ...(0, build_receipt_1.createEmbeddedBuildCandidate)({
143
+ platform: 'ios',
144
+ identityHash: params.identityHash,
145
+ integrationGeneration: params.integrationGeneration,
146
+ runtimeVersion: params.runtimeVersion,
147
+ }),
148
+ createdAt: params.createdAt,
149
+ };
150
+ const candidateContent = Buffer.from(`${JSON.stringify(candidate)}\n`, 'utf8');
151
+ const candidatePath = path_1.default.join(artifactPath, build_receipt_1.IOS_EMBEDDED_BUILD_CANDIDATE);
152
+ fs_1.default.writeFileSync(candidatePath, candidateContent);
153
+ return {
154
+ createdAt: params.createdAt,
155
+ evidence: 'ios-signed-app',
156
+ integrationGeneration: params.integrationGeneration,
157
+ artifactPath,
158
+ embeddedCandidateSha256: sha256(candidateContent),
159
+ };
160
+ };
161
+ /**
162
+ * Creates the deterministic Android asset that Gradle packages before signing.
163
+ * Receipt creation later accepts only the exact candidate extracted from the
164
+ * signed APK/AAB, so changing project config after the build cannot forge proof.
165
+ */
166
+ async function writeAndroidBuildIdentityCandidate(options) {
167
+ const projectRoot = path_1.default.resolve(options.projectRoot);
168
+ const outputPath = path_1.default.resolve(options.outputPath);
169
+ const identity = await (0, expo_1.resolveExpoBuildIdentity)(projectRoot, 'android', {
170
+ officialAppVersion: options.officialAppVersion,
171
+ officialNativeBuildVersion: options.officialNativeBuildVersion,
172
+ });
173
+ const candidate = (0, build_receipt_1.createEmbeddedBuildCandidate)({
174
+ platform: 'android',
175
+ identityHash: identity.identityHash,
176
+ integrationGeneration: (0, buildReceipt_1.resolveExpoIntegrationGeneration)(),
177
+ runtimeVersion: identity.runtimeVersion,
178
+ });
179
+ writeBufferAtomically(outputPath, (0, build_receipt_1.serializeEmbeddedBuildCandidate)(candidate));
180
+ return outputPath;
181
+ }
182
+ async function writeExpoBuildReceipt(options) {
183
+ const projectRoot = path_1.default.resolve(options.projectRoot);
184
+ const artifactPath = path_1.default.resolve(options.artifactPath);
185
+ const integrationGeneration = (0, buildReceipt_1.resolveExpoIntegrationGeneration)();
186
+ const packagedVersions = resolvePackagedBuildVersions(options.platform, artifactPath, options);
187
+ const identity = await (0, expo_1.resolveExpoBuildIdentity)(projectRoot, options.platform, {
188
+ officialAppVersion: packagedVersions.officialAppVersion,
189
+ officialNativeBuildVersion: packagedVersions.officialNativeBuildVersion,
190
+ });
191
+ if (options.platform === 'ios') {
192
+ writeIosRuntimeVersion(artifactPath, identity.runtimeVersion);
193
+ }
194
+ const createdAt = new Date().toISOString();
195
+ const proof = createLocalProof({
196
+ platform: options.platform,
197
+ artifactPath,
198
+ identityHash: identity.identityHash,
199
+ integrationGeneration,
200
+ runtimeVersion: identity.runtimeVersion,
201
+ createdAt,
202
+ androidSdkRoot: options.androidSdkRoot,
203
+ });
204
+ const receiptPath = path_1.default.join(projectRoot, '.bundle-drop', 'build-identity.json');
205
+ let previousReceipt = null;
206
+ try {
207
+ previousReceipt = (0, build_receipt_1.readExpoBuildIdentityReceipt)(projectRoot);
208
+ }
209
+ catch {
210
+ previousReceipt = null;
211
+ }
212
+ const identities = {
213
+ [options.platform]: identity,
214
+ };
215
+ const proofs = {
216
+ [options.platform]: proof,
217
+ };
218
+ const otherPlatform = options.platform === 'ios' ? 'android' : 'ios';
219
+ const otherIdentity = previousReceipt?.identities[otherPlatform];
220
+ const otherProof = previousReceipt?.proofs[otherPlatform];
221
+ if (otherIdentity && otherProof) {
222
+ try {
223
+ const currentOtherIdentity = await (0, expo_1.resolveExpoBuildIdentity)(projectRoot, otherPlatform);
224
+ if (currentOtherIdentity.identityHash === otherIdentity.identityHash &&
225
+ otherProof.integrationGeneration === integrationGeneration) {
226
+ identities[otherPlatform] = otherIdentity;
227
+ proofs[otherPlatform] = otherProof;
228
+ }
229
+ }
230
+ catch {
231
+ // A platform is retained only when its current identity and prior proof can be revalidated.
232
+ }
233
+ }
234
+ const receipt = {
235
+ schemaVersion: 3,
236
+ identities,
237
+ proofs,
238
+ };
239
+ writeJsonAtomically(receiptPath, receipt);
240
+ return receiptPath;
241
+ }
242
+ const parseBuildReceiptArguments = (argv) => {
243
+ const values = new Map();
244
+ for (let index = 0; index < argv.length; index += 2) {
245
+ const flag = argv[index];
246
+ const value = argv[index + 1];
247
+ if (![
248
+ '--project-root',
249
+ '--platform',
250
+ '--artifact',
251
+ '--android-sdk',
252
+ '--app-version',
253
+ '--native-build-version',
254
+ ].includes(flag) || !value) {
255
+ throw new Error('Usage: write-build-receipt --project-root <path> --platform ios|android --artifact <path>');
256
+ }
257
+ if (values.has(flag))
258
+ throw new Error(`Duplicate argument ${flag}.`);
259
+ values.set(flag, value);
260
+ }
261
+ const projectRoot = values.get('--project-root');
262
+ const platform = values.get('--platform');
263
+ const artifactPath = values.get('--artifact');
264
+ if (!projectRoot || (platform !== 'ios' && platform !== 'android') || !artifactPath) {
265
+ throw new Error('Usage: write-build-receipt --project-root <path> --platform ios|android --artifact <path>');
266
+ }
267
+ return {
268
+ projectRoot,
269
+ platform,
270
+ artifactPath,
271
+ ...(values.get('--android-sdk') ? { androidSdkRoot: values.get('--android-sdk') } : {}),
272
+ ...(values.get('--app-version') ? { officialAppVersion: values.get('--app-version') } : {}),
273
+ ...(values.get('--native-build-version')
274
+ ? { officialNativeBuildVersion: values.get('--native-build-version') }
275
+ : {}),
276
+ };
277
+ };
278
+ exports.parseBuildReceiptArguments = parseBuildReceiptArguments;
279
+ const parseAndroidBuildCandidateArguments = (argv) => {
280
+ const values = new Map();
281
+ for (let index = 0; index < argv.length; index += 2) {
282
+ const flag = argv[index];
283
+ const value = argv[index + 1];
284
+ if (![
285
+ '--project-root',
286
+ '--candidate-output',
287
+ '--app-version',
288
+ '--native-build-version',
289
+ ].includes(flag) || !value) {
290
+ throw new Error('Usage: write-build-receipt --project-root <path> --candidate-output <path> ' +
291
+ '--app-version <version> --native-build-version <version>');
292
+ }
293
+ if (values.has(flag))
294
+ throw new Error(`Duplicate argument ${flag}.`);
295
+ values.set(flag, value);
296
+ }
297
+ const projectRoot = values.get('--project-root');
298
+ const outputPath = values.get('--candidate-output');
299
+ const officialAppVersion = values.get('--app-version');
300
+ const officialNativeBuildVersion = values.get('--native-build-version');
301
+ if (!projectRoot || !outputPath || !officialAppVersion || !officialNativeBuildVersion) {
302
+ throw new Error('Usage: write-build-receipt --project-root <path> --candidate-output <path> ' +
303
+ '--app-version <version> --native-build-version <version>');
304
+ }
305
+ return {
306
+ projectRoot,
307
+ outputPath,
308
+ officialAppVersion,
309
+ officialNativeBuildVersion,
310
+ };
311
+ };
312
+ exports.parseAndroidBuildCandidateArguments = parseAndroidBuildCandidateArguments;
313
+ // The child-process test exercises this executable boundary; Jest does not merge
314
+ // coverage counters from the spawned Node process back into the parent.
315
+ /* istanbul ignore next */
316
+ if (require.main === module) {
317
+ const argv = process.argv.slice(2);
318
+ const operation = argv.includes('--candidate-output')
319
+ ? writeAndroidBuildIdentityCandidate((0, exports.parseAndroidBuildCandidateArguments)(argv))
320
+ : writeExpoBuildReceipt((0, exports.parseBuildReceiptArguments)(argv));
321
+ operation.catch(error => {
322
+ process.stderr.write(`${error.message}\n`);
323
+ process.exitCode = 1;
324
+ });
325
+ }
@@ -0,0 +1,8 @@
1
+ import type { MobilePlatform } from '../../../expo';
2
+ export type WriteEasBuildReceiptOptions = {
3
+ projectRoot: string;
4
+ platform: MobilePlatform;
5
+ easBuildId: string;
6
+ outputPath?: string;
7
+ };
8
+ export declare function writeEasBuildReceipt(options: WriteEasBuildReceiptOptions): Promise<string>;
@@ -0,0 +1,71 @@
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.writeEasBuildReceipt = writeEasBuildReceipt;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const buildReceipt_1 = require("../../../expo/buildReceipt");
11
+ const eas_build_proof_1 = require("./eas-build-proof");
12
+ const defaultReceiptPath = (projectRoot, platform, easBuildId) => path_1.default.join(projectRoot, '.bundle-drop', `eas-build-identity-${platform}-${easBuildId}.json`);
13
+ const writeJsonWithoutOverwrite = (filePath, value) => {
14
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
15
+ if (fs_1.default.existsSync(filePath)) {
16
+ throw new Error(`Bundle Drop will not overwrite the existing EAS build receipt at ${filePath}.`);
17
+ }
18
+ const temporaryPath = path_1.default.join(path_1.default.dirname(filePath), `.${path_1.default.basename(filePath)}.${process.pid}.${crypto_1.default.randomBytes(8).toString('hex')}.tmp`);
19
+ try {
20
+ const descriptor = fs_1.default.openSync(temporaryPath, 'wx', 0o600);
21
+ try {
22
+ fs_1.default.writeFileSync(descriptor, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
23
+ fs_1.default.fsyncSync(descriptor);
24
+ }
25
+ finally {
26
+ fs_1.default.closeSync(descriptor);
27
+ }
28
+ // Linking a complete temporary file publishes it atomically while retaining
29
+ // exclusive-create semantics if another process wrote the destination first.
30
+ fs_1.default.linkSync(temporaryPath, filePath);
31
+ }
32
+ catch (error) {
33
+ if (error.code === 'EEXIST') {
34
+ throw new Error(`Bundle Drop will not overwrite the existing EAS build receipt at ${filePath}.`);
35
+ }
36
+ throw error;
37
+ }
38
+ finally {
39
+ if (fs_1.default.existsSync(temporaryPath))
40
+ fs_1.default.unlinkSync(temporaryPath);
41
+ }
42
+ };
43
+ async function writeEasBuildReceipt(options) {
44
+ const projectRoot = path_1.default.resolve(options.projectRoot);
45
+ const resolvedBuild = await (0, eas_build_proof_1.resolveOfficialEasBuild)({
46
+ projectRoot,
47
+ platform: options.platform,
48
+ easBuildId: options.easBuildId,
49
+ });
50
+ const integrationGeneration = (0, buildReceipt_1.resolveExpoIntegrationGeneration)();
51
+ const receipt = {
52
+ schemaVersion: 3,
53
+ identities: {
54
+ [options.platform]: resolvedBuild.identity,
55
+ },
56
+ proofs: {
57
+ [options.platform]: {
58
+ createdAt: new Date().toISOString(),
59
+ evidence: 'eas-official-metadata',
60
+ integrationGeneration,
61
+ easBuildId: resolvedBuild.buildId,
62
+ },
63
+ },
64
+ };
65
+ const validatedReceipt = (0, buildReceipt_1.parseExpoBuildIdentityReceipt)(receipt, integrationGeneration);
66
+ const receiptPath = options.outputPath
67
+ ? path_1.default.resolve(projectRoot, options.outputPath)
68
+ : defaultReceiptPath(projectRoot, options.platform, resolvedBuild.buildId);
69
+ writeJsonWithoutOverwrite(receiptPath, validatedReceipt);
70
+ return receiptPath;
71
+ }
@@ -1,3 +1,4 @@
1
+ import type { ProjectType } from '../../expo';
1
2
  type Project = {
2
3
  name: string;
3
4
  slug: string;
@@ -16,5 +17,21 @@ export declare function initConfig(params: {
16
17
  organizations: Org[];
17
18
  downloadApiKey?: string;
18
19
  authToken?: string;
19
- }): Promise<void>;
20
+ dryRun?: boolean;
21
+ projectType?: ProjectType;
22
+ }): Promise<{
23
+ configPath: string;
24
+ content: any;
25
+ created: boolean;
26
+ serverUrl?: undefined;
27
+ orgSlug?: undefined;
28
+ projectSlug?: undefined;
29
+ } | {
30
+ configPath: string;
31
+ content: string;
32
+ created: boolean;
33
+ serverUrl: string;
34
+ orgSlug: string;
35
+ projectSlug: string;
36
+ }>;
20
37
  export default initConfig;
@@ -60,7 +60,11 @@ async function initConfig(params) {
60
60
  if (fs_extra_1.default.existsSync(configPath)) {
61
61
  console.log(chalk_1.default.yellow(`ℹ️ bundle.drop.config.js already exists at ${configPath}. If this is accidental, delete it and rerun the init/login.\n` +
62
62
  `See ${DOCS_INSTALLATION_URL}`));
63
- return;
63
+ return {
64
+ configPath,
65
+ content: fs_extra_1.default.readFileSync(configPath, 'utf8'),
66
+ created: false,
67
+ };
64
68
  }
65
69
  let orgSlug = '';
66
70
  let project = null;
@@ -143,13 +147,17 @@ async function initConfig(params) {
143
147
  else if (projectSlug && !params.authToken && !apiKey) {
144
148
  console.log(chalk_1.default.yellow('⚠️ Missing auth token; cannot fetch project API key.'));
145
149
  }
146
- const content = `module.exports = {
147
- serverUrl: '${resolvedServerUrl}',
148
- defaultChannel: 'develop',
149
- runtimeVersion: {
150
+ const projectTypeConfig = params.projectType
151
+ ? ` projectType: '${params.projectType}',\n`
152
+ : '';
153
+ const runtimeVersionConfig = ` runtimeVersion: {
150
154
  ios: '1.0.0',
151
155
  android: '1.0.0',
152
- },
156
+ },`;
157
+ const content = `module.exports = {
158
+ ${projectTypeConfig} serverUrl: '${resolvedServerUrl}',
159
+ defaultChannel: 'develop',
160
+ ${runtimeVersionConfig}
153
161
  org: {
154
162
  slug: '${orgSlug}',
155
163
  },
@@ -160,7 +168,20 @@ async function initConfig(params) {
160
168
  },
161
169
  };
162
170
  `;
163
- await fs_extra_1.default.writeFile(configPath, content, 'utf8');
164
- console.log(chalk_1.default.green(`✅ Created bundle.drop.config.js at ${configPath}`));
171
+ if (params.dryRun) {
172
+ console.log(chalk_1.default.cyan(`Dry-run bundle.drop.config.js preview:\n${content}`));
173
+ }
174
+ else {
175
+ await fs_extra_1.default.writeFile(configPath, content, 'utf8');
176
+ console.log(chalk_1.default.green(`✅ Created bundle.drop.config.js at ${configPath}`));
177
+ }
178
+ return {
179
+ configPath,
180
+ content,
181
+ created: !params.dryRun,
182
+ serverUrl: resolvedServerUrl,
183
+ orgSlug,
184
+ projectSlug,
185
+ };
165
186
  }
166
187
  exports.default = initConfig;
@@ -14,7 +14,9 @@ const prompts_1 = __importDefault(require("prompts"));
14
14
  const child_process_1 = require("child_process");
15
15
  const init_config_1 = require("./init-config");
16
16
  const post_init_1 = require("./post-init");
17
+ const expo_1 = require("../../expo");
17
18
  const LOGIN_TIMEOUT_MS = 10 * 60 * 1000;
19
+ const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
18
20
  const getBaseUrl = () => process.env.BUNDLE_DROP_SERVER_URL
19
21
  ? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
20
22
  : 'https://api.bundledrop.app';
@@ -238,6 +240,8 @@ const login = async () => {
238
240
  const baseUrl = (0, exports.getBaseUrl)();
239
241
  const clientName = (0, exports.getClientName)();
240
242
  let serverHandle;
243
+ let loginCompleted = false;
244
+ let createdConfigPath = null;
241
245
  try {
242
246
  serverHandle = await (0, exports.startCallbackServer)({ baseUrl });
243
247
  const session = await (0, exports.createLoginSession)({
@@ -261,25 +265,39 @@ const login = async () => {
261
265
  payload: authPayload,
262
266
  serverUrl: baseUrl,
263
267
  });
268
+ loginCompleted = true;
264
269
  console.log(chalk_1.default.green('✅ Logged in successfully as:'), chalk_1.default.cyan(`${authFile.user.firstName} ${authFile.user.lastName}`));
265
270
  if ((0, init_config_1.hasExistingBundleDropConfig)()) {
266
271
  console.log(chalk_1.default.gray(`ℹ️ Found existing bundle.drop.config.js at ${(0, init_config_1.getBundleDropConfigPath)()}. Skipping setup prompts.`));
267
272
  return;
268
273
  }
269
- await (0, init_config_1.initConfig)({
274
+ const projectType = (0, expo_1.detectProjectType)({ projectRoot: process.cwd() });
275
+ const configResult = await (0, init_config_1.initConfig)({
270
276
  serverUrl: baseUrl,
271
277
  projects: authFile.projects,
272
278
  organizations: authFile.organizations,
273
279
  downloadApiKey: authFile.downloadApiKey,
274
280
  authToken: authFile.token,
281
+ projectType,
275
282
  });
276
- await (0, post_init_1.runPostInitPrompts)();
283
+ if (configResult?.created) {
284
+ createdConfigPath = configResult.configPath;
285
+ }
286
+ await (0, post_init_1.runPostInitPrompts)({ projectType });
277
287
  }
278
288
  catch (error) {
289
+ if (createdConfigPath) {
290
+ await fs_extra_1.default.remove(createdConfigPath);
291
+ }
279
292
  const message = axios_1.default.isAxiosError(error)
280
293
  ? error.response?.data?.error || error.message
281
294
  : error.message;
282
- console.error(chalk_1.default.red('❌ Login failed:'), message);
295
+ const failureLabel = loginCompleted ? '❌ Setup failed after login:' : '❌ Login failed:';
296
+ console.error(chalk_1.default.red(failureLabel), message);
297
+ if (loginCompleted) {
298
+ console.error(chalk_1.default.gray(`Manual installation: ${DOCS_INSTALLATION_URL}`));
299
+ }
300
+ process.exitCode = 1;
283
301
  }
284
302
  finally {
285
303
  if (serverHandle) {
@@ -0,0 +1,7 @@
1
+ export declare const ANDROID_BUNDLE_DROP_MODULE = "com.bundledrop.BundleDropModule";
2
+ export declare const ANDROID_BUNDLE_DROP_PATHS = "com.bundledrop.BundleDropNativePaths";
3
+ export declare const IOS_BUNDLE_DROP_MODULE = "BundleDrop";
4
+ export declare const IOS_BUNDLE_DROP_LOCATOR_HEADER = "BundleDrop/BundleDropLocator.h";
5
+ export declare const stripCommentsAndStrings: (content: string) => string;
6
+ export declare const hasBareAndroidStartupIntegration: (code: string) => boolean;
7
+ export declare const hasBareIosStartupIntegration: (filePath: string, code: string) => boolean;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasBareIosStartupIntegration = exports.hasBareAndroidStartupIntegration = exports.stripCommentsAndStrings = exports.IOS_BUNDLE_DROP_LOCATOR_HEADER = exports.IOS_BUNDLE_DROP_MODULE = exports.ANDROID_BUNDLE_DROP_PATHS = exports.ANDROID_BUNDLE_DROP_MODULE = void 0;
4
+ exports.ANDROID_BUNDLE_DROP_MODULE = 'com.bundledrop.BundleDropModule';
5
+ exports.ANDROID_BUNDLE_DROP_PATHS = 'com.bundledrop.BundleDropNativePaths';
6
+ exports.IOS_BUNDLE_DROP_MODULE = 'BundleDrop';
7
+ exports.IOS_BUNDLE_DROP_LOCATOR_HEADER = 'BundleDrop/BundleDropLocator.h';
8
+ const stripCommentsAndStrings = (content) => {
9
+ let code = '';
10
+ let state = 'code';
11
+ let escaped = false;
12
+ for (let index = 0; index < content.length; index += 1) {
13
+ const character = content[index];
14
+ const nextCharacter = content[index + 1];
15
+ if (state === 'line-comment') {
16
+ if (character === '\n') {
17
+ state = 'code';
18
+ code += character;
19
+ }
20
+ continue;
21
+ }
22
+ if (state === 'block-comment') {
23
+ if (character === '*' && nextCharacter === '/') {
24
+ state = 'code';
25
+ index += 1;
26
+ }
27
+ continue;
28
+ }
29
+ if (state !== 'code') {
30
+ if (escaped) {
31
+ escaped = false;
32
+ continue;
33
+ }
34
+ if (character === '\\') {
35
+ escaped = true;
36
+ continue;
37
+ }
38
+ const closesState = (state === 'single' && character === "'") ||
39
+ (state === 'double' && character === '"') ||
40
+ (state === 'template' && character === '`');
41
+ if (closesState)
42
+ state = 'code';
43
+ continue;
44
+ }
45
+ if (character === '/' && nextCharacter === '/') {
46
+ state = 'line-comment';
47
+ index += 1;
48
+ continue;
49
+ }
50
+ if (character === '/' && nextCharacter === '*') {
51
+ state = 'block-comment';
52
+ index += 1;
53
+ continue;
54
+ }
55
+ if (character === "'") {
56
+ state = 'single';
57
+ continue;
58
+ }
59
+ if (character === '"') {
60
+ state = 'double';
61
+ continue;
62
+ }
63
+ if (character === '`') {
64
+ state = 'template';
65
+ continue;
66
+ }
67
+ code += character;
68
+ }
69
+ return code;
70
+ };
71
+ exports.stripCommentsAndStrings = stripCommentsAndStrings;
72
+ const hasJavaOrKotlinReference = (code, qualifiedName, member) => {
73
+ const escapedName = qualifiedName.replace(/\./g, '\\.');
74
+ return (new RegExp(`\\bimport\\s+${escapedName}\\s*;?`).test(code) ||
75
+ code.includes(`${qualifiedName}.${member}`));
76
+ };
77
+ const hasBareAndroidStartupIntegration = (code) => {
78
+ const nativeCode = (0, exports.stripCommentsAndStrings)(code);
79
+ const usesModuleResolver = nativeCode.includes('getJSBundleFile') &&
80
+ nativeCode.includes('BundleDropModule.resolveJSBundleFile') &&
81
+ hasJavaOrKotlinReference(nativeCode, exports.ANDROID_BUNDLE_DROP_MODULE, 'resolveJSBundleFile');
82
+ const usesNativePaths = nativeCode.includes('BundleDropNativePaths.getDownloadedBundlePath') &&
83
+ hasJavaOrKotlinReference(nativeCode, exports.ANDROID_BUNDLE_DROP_PATHS, 'getDownloadedBundlePath');
84
+ return usesModuleResolver || usesNativePaths;
85
+ };
86
+ exports.hasBareAndroidStartupIntegration = hasBareAndroidStartupIntegration;
87
+ const hasBareIosStartupIntegration = (filePath, code) => {
88
+ const nativeCode = (0, exports.stripCommentsAndStrings)(code);
89
+ if (filePath.endsWith('.swift')) {
90
+ const usesLocator = nativeCode.includes('bundleURL') &&
91
+ nativeCode.includes('BundleDropLocator.bundleURL()');
92
+ return usesLocator &&
93
+ new RegExp(`\\bimport\\s+${exports.IOS_BUNDLE_DROP_MODULE}\\b`).test(nativeCode);
94
+ }
95
+ const usesLocator = (nativeCode.includes('sourceURLForBridge') || nativeCode.includes('bundleURL')) &&
96
+ nativeCode.includes('[BundleDropLocator bundleURL]');
97
+ const escapedHeader = exports.IOS_BUNDLE_DROP_LOCATOR_HEADER.replace(/[/.]/g, '\\$&');
98
+ return usesLocator &&
99
+ new RegExp(`#import\\s*[<\"]${escapedHeader}[>\"]`).test(nativeCode);
100
+ };
101
+ exports.hasBareIosStartupIntegration = hasBareIosStartupIntegration;
@@ -1 +1,6 @@
1
- export declare function runPostInitPrompts(): Promise<void>;
1
+ import type { InitProjectOptions } from './aipowered/init-project-config';
2
+ /**
3
+ * Kept as the post-config seam used by login/init. Setup is now one
4
+ * project-aware AI-assisted flow instead of separate Metro/native prompts.
5
+ */
6
+ export declare function runPostInitPrompts(options?: InitProjectOptions): Promise<void>;