@gfean/react-native-bundle-drop 0.4.2 → 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 (111) hide show
  1. package/BundleDropExpo.podspec +21 -0
  2. package/README.md +339 -74
  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 +126 -31
  20. package/lib/CLI/logo.d.ts +9 -0
  21. package/lib/CLI/logo.js +26 -0
  22. package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
  23. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +55 -0
  24. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -1
  25. package/lib/CLI/scripts/aipowered/backend-client.js +25 -2
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +400 -0
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -1
  29. package/lib/CLI/scripts/aipowered/scanner.js +274 -5
  30. package/lib/CLI/scripts/aipowered/types.d.ts +39 -0
  31. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +12 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.js +76 -1
  33. package/lib/CLI/scripts/doctor.d.ts +17 -0
  34. package/lib/CLI/scripts/doctor.js +412 -0
  35. package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
  36. package/lib/CLI/scripts/expo/build-receipt.js +223 -0
  37. package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
  38. package/lib/CLI/scripts/expo/configure-expo.js +268 -0
  39. package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
  40. package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
  41. package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
  42. package/lib/CLI/scripts/expo/package-manager.js +84 -0
  43. package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
  44. package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
  45. package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
  46. package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
  47. package/lib/CLI/scripts/init-config.d.ts +18 -1
  48. package/lib/CLI/scripts/init-config.js +29 -9
  49. package/lib/CLI/scripts/init-metro-config.d.ts +7 -0
  50. package/lib/CLI/scripts/init-metro-config.js +28 -8
  51. package/lib/CLI/scripts/login-cli.js +17 -3
  52. package/lib/CLI/scripts/post-init.d.ts +6 -1
  53. package/lib/CLI/scripts/post-init.js +6 -33
  54. package/lib/CLI/scripts/upload-cli.d.ts +1 -0
  55. package/lib/CLI/scripts/upload-cli.js +106 -36
  56. package/lib/context.d.ts +0 -2
  57. package/lib/context.js +19 -3
  58. package/lib/expo/buildIdentity.d.ts +15 -0
  59. package/lib/expo/buildIdentity.js +201 -0
  60. package/lib/expo/buildReceipt.d.ts +42 -0
  61. package/lib/expo/buildReceipt.js +272 -0
  62. package/lib/expo/config.d.ts +7 -0
  63. package/lib/expo/config.js +43 -0
  64. package/lib/expo/configCache.d.ts +1 -0
  65. package/lib/expo/configCache.js +20 -0
  66. package/lib/expo/errors.d.ts +6 -0
  67. package/lib/expo/errors.js +11 -0
  68. package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
  69. package/lib/expo/expoUpdatesOwnership.js +22 -0
  70. package/lib/expo/exportExpoProject.d.ts +21 -0
  71. package/lib/expo/exportExpoProject.js +125 -0
  72. package/lib/expo/exportValidation.d.ts +11 -0
  73. package/lib/expo/exportValidation.js +115 -0
  74. package/lib/expo/index.d.ts +18 -0
  75. package/lib/expo/index.js +25 -0
  76. package/lib/expo/localModules.d.ts +4 -0
  77. package/lib/expo/localModules.js +51 -0
  78. package/lib/expo/nativeIdentity.d.ts +1 -0
  79. package/lib/expo/nativeIdentity.js +17 -0
  80. package/lib/expo/projectType.d.ts +7 -0
  81. package/lib/expo/projectType.js +200 -0
  82. package/lib/expo/runtimeVersion.d.ts +13 -0
  83. package/lib/expo/runtimeVersion.js +45 -0
  84. package/lib/expo/types.d.ts +15 -0
  85. package/lib/expo/types.js +2 -0
  86. package/lib/fs/userProperties.d.ts +0 -2
  87. package/lib/fs/userProperties.js +0 -3
  88. package/lib/index.d.ts +1 -1
  89. package/lib/index.js +1 -2
  90. package/lib/loadConfig.d.ts +17 -5
  91. package/lib/loadConfig.js +2 -19
  92. package/lib/metro.d.ts +17 -0
  93. package/lib/metro.js +57 -0
  94. package/lib/native/bundleDropNative.d.ts +2 -0
  95. package/lib/native/bundleDropNative.js +9 -1
  96. package/lib/runtime/service.js +12 -1
  97. package/lib/scripts/bundle.d.ts +2 -2
  98. package/lib/scripts/bundle.js +30 -99
  99. package/lib/scripts/canonicalArtifact.d.ts +30 -0
  100. package/lib/scripts/canonicalArtifact.js +212 -0
  101. package/lib/scripts/download-bundle.js +1 -1
  102. package/lib/scripts/exportProject.d.ts +41 -0
  103. package/lib/scripts/exportProject.js +82 -0
  104. package/package.json +74 -55
  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 +20 -0
@@ -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: 'General',
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
  },
@@ -158,10 +166,22 @@ async function initConfig(params) {
158
166
  slug: '${projectSlug}',
159
167
  apiKey: '${apiKey.replace(/'/g, "\\'")}',
160
168
  },
161
- debugLocal: false,
162
169
  };
163
170
  `;
164
- await fs_extra_1.default.writeFile(configPath, content, 'utf8');
165
- 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
+ };
166
186
  }
167
187
  exports.default = initConfig;
@@ -1,2 +1,9 @@
1
+ export type MetroConfigChange = {
2
+ file: 'metro.config.js';
3
+ original: string | null;
4
+ updated: string;
5
+ reason: string;
6
+ };
7
+ export declare function planBareMetroConfig(projectRoot: string): MetroConfigChange | null;
1
8
  export declare function initMetroConfig(): Promise<void>;
2
9
  export default initMetroConfig;
@@ -3,6 +3,7 @@ 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.planBareMetroConfig = planBareMetroConfig;
6
7
  exports.initMetroConfig = initMetroConfig;
7
8
  const chalk_1 = __importDefault(require("chalk"));
8
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -46,21 +47,40 @@ config.resolver.extraNodeModules = {
46
47
  module.exports = config;
47
48
  ${APPEND_SNIPPET}
48
49
  `;
49
- async function initMetroConfig() {
50
- const projectRoot = findProjectRoot(process.cwd());
50
+ function planBareMetroConfig(projectRoot) {
51
51
  const metroPath = path_1.default.join(projectRoot, 'metro.config.js');
52
52
  if (!fs_extra_1.default.existsSync(metroPath)) {
53
- fs_extra_1.default.writeFileSync(metroPath, NEW_METRO_TEMPLATE.trim() + '\n', 'utf8');
54
- console.log(chalk_1.default.green(`✅ Created metro.config.js with Bundle Drop alias at ${metroPath}`));
55
- return;
53
+ return {
54
+ file: 'metro.config.js',
55
+ original: null,
56
+ updated: `${NEW_METRO_TEMPLATE.trim()}\n`,
57
+ reason: 'Create the bare React Native Metro alias for bundle.drop.config.js.',
58
+ };
56
59
  }
57
60
  const content = fs_extra_1.default.readFileSync(metroPath, 'utf8');
58
- if (content.includes('bundle-drop-config')) {
61
+ if (content.includes('bundle-drop-config'))
62
+ return null;
63
+ return {
64
+ file: 'metro.config.js',
65
+ original: content,
66
+ updated: `${content.trim()}\n${APPEND_SNIPPET}`,
67
+ reason: 'Add the Bundle Drop alias without replacing the existing Metro config.',
68
+ };
69
+ }
70
+ async function initMetroConfig() {
71
+ const projectRoot = findProjectRoot(process.cwd());
72
+ const metroPath = path_1.default.join(projectRoot, 'metro.config.js');
73
+ const change = planBareMetroConfig(projectRoot);
74
+ if (!change) {
59
75
  console.log(chalk_1.default.gray('ℹ️ metro.config.js already contains bundle-drop-config alias.'));
60
76
  return;
61
77
  }
62
- const updated = `${content.trim()}\n${APPEND_SNIPPET}`;
63
- fs_extra_1.default.writeFileSync(metroPath, updated, 'utf8');
78
+ if (change.original === null) {
79
+ fs_extra_1.default.writeFileSync(metroPath, change.updated, 'utf8');
80
+ console.log(chalk_1.default.green(`✅ Created metro.config.js with Bundle Drop alias at ${metroPath}`));
81
+ return;
82
+ }
83
+ fs_extra_1.default.writeFileSync(metroPath, change.updated, 'utf8');
64
84
  console.log(chalk_1.default.green(`✅ Added bundle-drop-config alias to metro.config.js`));
65
85
  }
66
86
  exports.default = initMetroConfig;
@@ -14,6 +14,7 @@ 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;
18
19
  const getBaseUrl = () => process.env.BUNDLE_DROP_SERVER_URL
19
20
  ? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
@@ -238,6 +239,8 @@ const login = async () => {
238
239
  const baseUrl = (0, exports.getBaseUrl)();
239
240
  const clientName = (0, exports.getClientName)();
240
241
  let serverHandle;
242
+ let loginCompleted = false;
243
+ let createdConfigPath = null;
241
244
  try {
242
245
  serverHandle = await (0, exports.startCallbackServer)({ baseUrl });
243
246
  const session = await (0, exports.createLoginSession)({
@@ -261,25 +264,36 @@ const login = async () => {
261
264
  payload: authPayload,
262
265
  serverUrl: baseUrl,
263
266
  });
267
+ loginCompleted = true;
264
268
  console.log(chalk_1.default.green('✅ Logged in successfully as:'), chalk_1.default.cyan(`${authFile.user.firstName} ${authFile.user.lastName}`));
265
269
  if ((0, init_config_1.hasExistingBundleDropConfig)()) {
266
270
  console.log(chalk_1.default.gray(`ℹ️ Found existing bundle.drop.config.js at ${(0, init_config_1.getBundleDropConfigPath)()}. Skipping setup prompts.`));
267
271
  return;
268
272
  }
269
- await (0, init_config_1.initConfig)({
273
+ const projectType = (0, expo_1.detectProjectType)({ projectRoot: process.cwd() });
274
+ const configResult = await (0, init_config_1.initConfig)({
270
275
  serverUrl: baseUrl,
271
276
  projects: authFile.projects,
272
277
  organizations: authFile.organizations,
273
278
  downloadApiKey: authFile.downloadApiKey,
274
279
  authToken: authFile.token,
280
+ projectType,
275
281
  });
276
- await (0, post_init_1.runPostInitPrompts)();
282
+ if (configResult?.created) {
283
+ createdConfigPath = configResult.configPath;
284
+ }
285
+ await (0, post_init_1.runPostInitPrompts)({ projectType });
277
286
  }
278
287
  catch (error) {
288
+ if (createdConfigPath) {
289
+ await fs_extra_1.default.remove(createdConfigPath);
290
+ }
279
291
  const message = axios_1.default.isAxiosError(error)
280
292
  ? error.response?.data?.error || error.message
281
293
  : error.message;
282
- console.error(chalk_1.default.red('❌ Login failed:'), message);
294
+ const failureLabel = loginCompleted ? '❌ Setup failed after login:' : '❌ Login failed:';
295
+ console.error(chalk_1.default.red(failureLabel), message);
296
+ process.exitCode = 1;
283
297
  }
284
298
  finally {
285
299
  if (serverHandle) {
@@ -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>;