@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,28 @@
1
+ export { setBundleDropProjectType } from '../../../expo/projectType';
2
+ export type ExpoSetupFileChange = {
3
+ file: string;
4
+ original: string | null;
5
+ updated: string;
6
+ reason: string;
7
+ };
8
+ export type ExpoSetupApplyResult = {
9
+ projectRoot: string;
10
+ backupDir: string;
11
+ changedFiles: Array<{
12
+ file: string;
13
+ existed: boolean;
14
+ }>;
15
+ buildReceiptInvalidated: boolean;
16
+ };
17
+ export declare function planExpoProjectConfiguration(params: {
18
+ projectRoot: string;
19
+ migrateExpoUpdates: boolean;
20
+ bundleConfigContent?: string;
21
+ }): ExpoSetupFileChange[];
22
+ export declare function setupChangeHash(change: ExpoSetupFileChange): string;
23
+ export declare function hasDynamicExpoConfig(projectRoot: string): boolean;
24
+ export declare function restoreExpoConfiguration(result: ExpoSetupApplyResult): void;
25
+ export declare function applyExpoConfigurationChanges(params: {
26
+ projectRoot: string;
27
+ changes: ExpoSetupFileChange[];
28
+ }): ExpoSetupApplyResult;
@@ -0,0 +1,268 @@
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.setBundleDropProjectType = void 0;
7
+ exports.planExpoProjectConfiguration = planExpoProjectConfiguration;
8
+ exports.setupChangeHash = setupChangeHash;
9
+ exports.hasDynamicExpoConfig = hasDynamicExpoConfig;
10
+ exports.restoreExpoConfiguration = restoreExpoConfiguration;
11
+ exports.applyExpoConfigurationChanges = applyExpoConfigurationChanges;
12
+ const crypto_1 = __importDefault(require("crypto"));
13
+ const fs_extra_1 = __importDefault(require("fs-extra"));
14
+ const path_1 = __importDefault(require("path"));
15
+ const projectType_1 = require("../../../expo/projectType");
16
+ var projectType_2 = require("../../../expo/projectType");
17
+ Object.defineProperty(exports, "setBundleDropProjectType", { enumerable: true, get: function () { return projectType_2.setBundleDropProjectType; } });
18
+ const PACKAGE_NAME = '@gfean/react-native-bundle-drop';
19
+ const EXPO_UPDATES = 'expo-updates';
20
+ const TRANSIENT_GRADLE_KOTLIN_FINGERPRINT_PATTERN = '**/*-gradle-plugin/.kotlin/**/*';
21
+ const EXPO_RUNTIME_SOURCE_PATTERN = /runtimeVersion\s*:\s*\{\s*source\s*:\s*['"]expo['"]\s*\}/;
22
+ const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
23
+ const configPluginName = (plugin) => {
24
+ if (typeof plugin === 'string')
25
+ return plugin;
26
+ if (Array.isArray(plugin) && typeof plugin[0] === 'string')
27
+ return plugin[0];
28
+ return null;
29
+ };
30
+ const updateAppJson = (content, migrateExpoUpdates) => {
31
+ const parsed = JSON.parse(content);
32
+ const expo = parsed.expo && typeof parsed.expo === 'object' ? parsed.expo : parsed;
33
+ const existingPlugins = Array.isArray(expo.plugins) ? expo.plugins : [];
34
+ const plugins = existingPlugins.filter((plugin) => {
35
+ const name = configPluginName(plugin);
36
+ return name !== PACKAGE_NAME && (!migrateExpoUpdates || name !== EXPO_UPDATES);
37
+ });
38
+ expo.plugins = [...plugins, PACKAGE_NAME];
39
+ if (migrateExpoUpdates && expo.updates && typeof expo.updates === 'object') {
40
+ const { url: _url, enabled: _enabled, ...remainingUpdates } = expo.updates;
41
+ if (Object.keys(remainingUpdates).length)
42
+ expo.updates = remainingUpdates;
43
+ else
44
+ delete expo.updates;
45
+ }
46
+ return `${JSON.stringify(parsed, null, 2)}\n`;
47
+ };
48
+ const updatePackageJson = (content) => {
49
+ const parsed = JSON.parse(content);
50
+ for (const dependencyGroup of [
51
+ 'dependencies',
52
+ 'devDependencies',
53
+ 'optionalDependencies',
54
+ 'peerDependencies',
55
+ ]) {
56
+ if (parsed[dependencyGroup] && typeof parsed[dependencyGroup] === 'object') {
57
+ delete parsed[dependencyGroup][EXPO_UPDATES];
58
+ }
59
+ }
60
+ return `${JSON.stringify(parsed, null, 2)}\n`;
61
+ };
62
+ const EXPO_METRO_WRAPPER = `
63
+
64
+ // Bundle Drop: preserve Expo Metro configuration and embed concrete runtime identity.
65
+ const { withBundleDropExpo } = require('@gfean/react-native-bundle-drop/metro');
66
+ module.exports = withBundleDropExpo(module.exports, { projectRoot: __dirname });
67
+ `;
68
+ const NEW_EXPO_METRO_CONFIG = `const { getDefaultConfig } = require('expo/metro-config');
69
+ const { withBundleDropExpo } = require('@gfean/react-native-bundle-drop/metro');
70
+
71
+ module.exports = withBundleDropExpo(getDefaultConfig(__dirname), {
72
+ projectRoot: __dirname,
73
+ });
74
+ `;
75
+ const updateBundleDropConfig = (content) => {
76
+ return (0, projectType_1.setBundleDropProjectType)(content, 'expo');
77
+ };
78
+ const findFirstExisting = (projectRoot, candidates) => candidates.find(candidate => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, candidate)));
79
+ function planExpoProjectConfiguration(params) {
80
+ const changes = [];
81
+ const appConfigFile = findFirstExisting(params.projectRoot, [
82
+ 'app.config.js',
83
+ 'app.config.ts',
84
+ 'app.config.cjs',
85
+ 'app.config.mjs',
86
+ ]);
87
+ const appJsonPath = path_1.default.join(params.projectRoot, 'app.json');
88
+ if (!appConfigFile && fs_extra_1.default.existsSync(appJsonPath)) {
89
+ const original = fs_extra_1.default.readFileSync(appJsonPath, 'utf8');
90
+ const updated = updateAppJson(original, params.migrateExpoUpdates);
91
+ if (updated !== original) {
92
+ changes.push({
93
+ file: 'app.json',
94
+ original,
95
+ updated,
96
+ reason: 'Register the Bundle Drop Expo plugin while preserving the existing app config.',
97
+ });
98
+ }
99
+ }
100
+ const metroFile = findFirstExisting(params.projectRoot, [
101
+ 'metro.config.js',
102
+ 'metro.config.ts',
103
+ 'metro.config.cjs',
104
+ 'metro.config.mjs',
105
+ ]);
106
+ if (metroFile) {
107
+ const original = fs_extra_1.default.readFileSync(path_1.default.join(params.projectRoot, metroFile), 'utf8');
108
+ if (!original.includes('withBundleDropExpo')) {
109
+ changes.push({
110
+ file: metroFile,
111
+ original,
112
+ updated: `${original.trimEnd()}${EXPO_METRO_WRAPPER}`,
113
+ reason: 'Wrap the existing Expo Metro config without replacing expo/metro-config.',
114
+ });
115
+ }
116
+ }
117
+ else {
118
+ changes.push({
119
+ file: 'metro.config.js',
120
+ original: null,
121
+ updated: NEW_EXPO_METRO_CONFIG,
122
+ reason: 'Create an Expo Metro config with the Bundle Drop wrapper.',
123
+ });
124
+ }
125
+ const bundleConfigPath = path_1.default.join(params.projectRoot, 'bundle.drop.config.js');
126
+ const bundleConfigExists = fs_extra_1.default.existsSync(bundleConfigPath);
127
+ const bundleConfig = bundleConfigExists
128
+ ? fs_extra_1.default.readFileSync(bundleConfigPath, 'utf8')
129
+ : params.bundleConfigContent;
130
+ if (!bundleConfig) {
131
+ throw new Error('bundle.drop.config.js is required before Expo configuration can be planned.');
132
+ }
133
+ const updatedBundleConfig = updateBundleDropConfig(bundleConfig);
134
+ if (!bundleConfigExists || updatedBundleConfig !== bundleConfig) {
135
+ changes.push({
136
+ file: 'bundle.drop.config.js',
137
+ original: bundleConfigExists ? bundleConfig : null,
138
+ updated: updatedBundleConfig,
139
+ reason: 'Persist the Expo project type while preserving Bundle Drop runtime authority.',
140
+ });
141
+ }
142
+ if (params.migrateExpoUpdates) {
143
+ const packagePath = path_1.default.join(params.projectRoot, 'package.json');
144
+ const packageJson = fs_extra_1.default.readFileSync(packagePath, 'utf8');
145
+ const updatedPackageJson = updatePackageJson(packageJson);
146
+ if (updatedPackageJson !== packageJson) {
147
+ changes.push({
148
+ file: 'package.json',
149
+ original: packageJson,
150
+ updated: updatedPackageJson,
151
+ reason: 'Remove the direct expo-updates dependency after explicit migration approval.',
152
+ });
153
+ }
154
+ }
155
+ const fingerprintIgnorePath = path_1.default.join(params.projectRoot, '.fingerprintignore');
156
+ const fingerprintIgnore = fs_extra_1.default.existsSync(fingerprintIgnorePath)
157
+ ? fs_extra_1.default.readFileSync(fingerprintIgnorePath, 'utf8')
158
+ : '';
159
+ if (EXPO_RUNTIME_SOURCE_PATTERN.test(updatedBundleConfig) &&
160
+ !fingerprintIgnore.split(/\r?\n/).includes(TRANSIENT_GRADLE_KOTLIN_FINGERPRINT_PATTERN)) {
161
+ changes.push({
162
+ file: '.fingerprintignore',
163
+ original: fs_extra_1.default.existsSync(fingerprintIgnorePath) ? fingerprintIgnore : null,
164
+ updated: `${fingerprintIgnore.trimEnd()}${fingerprintIgnore.trim() ? '\n' : ''}` +
165
+ `${TRANSIENT_GRADLE_KOTLIN_FINGERPRINT_PATTERN}\n`,
166
+ reason: 'Exclude transient Gradle Kotlin compiler sessions from Expo runtime fingerprints.',
167
+ });
168
+ }
169
+ const gitignorePath = path_1.default.join(params.projectRoot, '.gitignore');
170
+ const gitignore = fs_extra_1.default.existsSync(gitignorePath) ? fs_extra_1.default.readFileSync(gitignorePath, 'utf8') : '';
171
+ if (!gitignore.split(/\r?\n/).includes('.bundle-drop/')) {
172
+ changes.push({
173
+ file: '.gitignore',
174
+ original: fs_extra_1.default.existsSync(gitignorePath) ? gitignore : null,
175
+ updated: `${gitignore.trimEnd()}${gitignore.trim() ? '\n' : ''}.bundle-drop/\n`,
176
+ reason: 'Ignore generated build identity and Metro configuration artifacts.',
177
+ });
178
+ }
179
+ return changes;
180
+ }
181
+ function setupChangeHash(change) {
182
+ return sha256(change.original || '');
183
+ }
184
+ function hasDynamicExpoConfig(projectRoot) {
185
+ return Boolean(findFirstExisting(projectRoot, [
186
+ 'app.config.js',
187
+ 'app.config.ts',
188
+ 'app.config.cjs',
189
+ 'app.config.mjs',
190
+ ]));
191
+ }
192
+ const assertSetupPathAllowed = (file) => {
193
+ const allowed = file === 'package.json' ||
194
+ file === '.fingerprintignore' ||
195
+ file === '.gitignore' ||
196
+ file === 'bundle.drop.config.js' ||
197
+ file === 'app.json' ||
198
+ /^app\.config\.(js|ts|cjs|mjs)$/.test(file) ||
199
+ /^metro\.config\.(js|ts|cjs|mjs)$/.test(file);
200
+ if (!allowed || path_1.default.isAbsolute(file) || file.includes('\\') || file.split('/').includes('..')) {
201
+ throw new Error(`Refusing to modify a file outside the Expo setup allowlist: ${file}`);
202
+ }
203
+ };
204
+ function restoreExpoConfiguration(result) {
205
+ for (const changed of [...result.changedFiles].reverse()) {
206
+ const targetPath = path_1.default.join(result.projectRoot, changed.file);
207
+ const backupPath = path_1.default.join(result.backupDir, changed.file);
208
+ if (changed.existed) {
209
+ fs_extra_1.default.copyFileSync(backupPath, targetPath);
210
+ }
211
+ else if (fs_extra_1.default.existsSync(targetPath)) {
212
+ fs_extra_1.default.unlinkSync(targetPath);
213
+ }
214
+ }
215
+ if (result.buildReceiptInvalidated) {
216
+ const receiptFile = path_1.default.join('.bundle-drop', 'build-identity.json');
217
+ const targetPath = path_1.default.join(result.projectRoot, receiptFile);
218
+ const backupPath = path_1.default.join(result.backupDir, receiptFile);
219
+ fs_extra_1.default.ensureDirSync(path_1.default.dirname(targetPath));
220
+ fs_extra_1.default.copyFileSync(backupPath, targetPath);
221
+ }
222
+ }
223
+ function applyExpoConfigurationChanges(params) {
224
+ const result = {
225
+ projectRoot: params.projectRoot,
226
+ backupDir: path_1.default.join(params.projectRoot, '.bundledrop-backup', new Date().toISOString().replace(/[:.]/g, '-')),
227
+ changedFiles: [],
228
+ buildReceiptInvalidated: false,
229
+ };
230
+ try {
231
+ const receiptFile = path_1.default.join('.bundle-drop', 'build-identity.json');
232
+ const receiptPath = path_1.default.join(params.projectRoot, receiptFile);
233
+ if (fs_extra_1.default.existsSync(receiptPath)) {
234
+ const backupPath = path_1.default.join(result.backupDir, receiptFile);
235
+ fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
236
+ fs_extra_1.default.copyFileSync(receiptPath, backupPath);
237
+ fs_extra_1.default.unlinkSync(receiptPath);
238
+ result.buildReceiptInvalidated = true;
239
+ }
240
+ for (const change of params.changes) {
241
+ assertSetupPathAllowed(change.file);
242
+ const targetPath = path_1.default.join(params.projectRoot, change.file);
243
+ const exists = fs_extra_1.default.existsSync(targetPath);
244
+ if (exists !== (change.original !== null)) {
245
+ throw new Error(`File existence changed since Expo setup preview: ${change.file}`);
246
+ }
247
+ if (exists) {
248
+ const current = fs_extra_1.default.readFileSync(targetPath, 'utf8');
249
+ if (sha256(current) !== sha256(change.original || '')) {
250
+ throw new Error(`File changed since Expo setup preview: ${change.file}`);
251
+ }
252
+ const backupPath = path_1.default.join(result.backupDir, change.file);
253
+ fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
254
+ fs_extra_1.default.copyFileSync(targetPath, backupPath);
255
+ }
256
+ result.changedFiles.push({ file: change.file, existed: exists });
257
+ fs_extra_1.default.ensureDirSync(path_1.default.dirname(targetPath));
258
+ const temporaryPath = `${targetPath}.bundledrop-tmp`;
259
+ fs_extra_1.default.writeFileSync(temporaryPath, change.updated, 'utf8');
260
+ fs_extra_1.default.renameSync(temporaryPath, targetPath);
261
+ }
262
+ return result;
263
+ }
264
+ catch (error) {
265
+ restoreExpoConfiguration(result);
266
+ throw error;
267
+ }
268
+ }
@@ -0,0 +1,22 @@
1
+ import type { ExpoBuildIdentity, MobilePlatform } from '../../../expo';
2
+ import type { ExpoEasBuildProof } from '../../../expo/buildReceipt';
3
+ export type ResolvedOfficialEasBuild = {
4
+ buildId: string;
5
+ identity: ExpoBuildIdentity;
6
+ };
7
+ /**
8
+ * Resolves a concrete identity from authenticated official EAS metadata and
9
+ * the exact clean source commit. This proof does not claim to inspect or embed
10
+ * data in the remote application artifact.
11
+ */
12
+ export declare function resolveOfficialEasBuild(params: {
13
+ projectRoot: string;
14
+ platform: MobilePlatform;
15
+ easBuildId: string;
16
+ }): Promise<ResolvedOfficialEasBuild>;
17
+ export declare function resolveOfficialEasBuildIdentity(params: {
18
+ projectRoot: string;
19
+ platform: MobilePlatform;
20
+ receiptIdentity: ExpoBuildIdentity;
21
+ proof: ExpoEasBuildProof;
22
+ }): Promise<ExpoBuildIdentity>;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveOfficialEasBuild = resolveOfficialEasBuild;
7
+ exports.resolveOfficialEasBuildIdentity = resolveOfficialEasBuildIdentity;
8
+ const child_process_1 = __importDefault(require("child_process"));
9
+ const expo_1 = require("../../../expo");
10
+ const EAS_BUILD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
11
+ const run = (command, args, cwd) => child_process_1.default.spawnSync(command, args, {
12
+ cwd,
13
+ encoding: 'utf8',
14
+ shell: false,
15
+ });
16
+ const requiredString = (value, field) => {
17
+ if (typeof value !== 'string' || !value.trim()) {
18
+ throw new Error(`Official EAS build metadata is missing ${field}.`);
19
+ }
20
+ return value;
21
+ };
22
+ const readOfficialBuild = (projectRoot, buildId) => {
23
+ if (!EAS_BUILD_ID.test(buildId)) {
24
+ throw new Error('Bundle Drop EAS build proof contains an invalid build ID.');
25
+ }
26
+ const result = run('eas', ['build:view', buildId, '--json'], projectRoot);
27
+ if (result.error || result.status !== 0) {
28
+ throw new Error(`Bundle Drop could not authenticate and verify EAS build ${buildId}. ` +
29
+ 'Run `eas whoami` and retry from the exact build project. EAS output was omitted to protect credentials.');
30
+ }
31
+ try {
32
+ const value = JSON.parse(result.stdout || '');
33
+ if (!value || typeof value !== 'object' || Array.isArray(value))
34
+ throw new Error('not an object');
35
+ return value;
36
+ }
37
+ catch (error) {
38
+ throw new Error(`Official EAS build metadata is malformed: ${error.message}`);
39
+ }
40
+ };
41
+ const assertExactProjectCommit = (projectRoot, officialGitCommitHash) => {
42
+ const head = run('git', ['rev-parse', 'HEAD'], projectRoot);
43
+ if (head.error || head.status !== 0 || head.stdout.trim() !== officialGitCommitHash) {
44
+ throw new Error('The EAS build was not created from the current project commit. ' +
45
+ 'Check out the exact build commit before uploading.');
46
+ }
47
+ const status = run('git', ['status', '--porcelain'], projectRoot);
48
+ if (status.error || status.status !== 0 || status.stdout.trim()) {
49
+ throw new Error('EAS-proven uploads require a clean worktree at the exact build commit.');
50
+ }
51
+ };
52
+ const sdkMajor = (value) => value.split('.')[0];
53
+ /**
54
+ * Resolves a concrete identity from authenticated official EAS metadata and
55
+ * the exact clean source commit. This proof does not claim to inspect or embed
56
+ * data in the remote application artifact.
57
+ */
58
+ async function resolveOfficialEasBuild(params) {
59
+ const build = readOfficialBuild(params.projectRoot, params.easBuildId);
60
+ const buildId = requiredString(build.id, 'id');
61
+ const status = requiredString(build.status, 'status');
62
+ const platform = requiredString(build.platform, 'platform').toLowerCase();
63
+ const projectId = requiredString(build.project?.id, 'project.id');
64
+ const sdkVersion = requiredString(build.sdkVersion, 'sdkVersion');
65
+ const appVersion = requiredString(build.appVersion, 'appVersion');
66
+ const appBuildVersion = requiredString(build.appBuildVersion, 'appBuildVersion');
67
+ const runtimeVersion = requiredString(build.runtimeVersion, 'runtimeVersion');
68
+ const gitCommitHash = requiredString(build.gitCommitHash, 'gitCommitHash');
69
+ const fingerprintHash = requiredString(build.fingerprint?.hash, 'fingerprint.hash');
70
+ const artifactUrl = build.artifacts?.applicationArchiveUrl || build.artifacts?.buildUrl;
71
+ if (buildId !== params.easBuildId || status !== 'FINISHED') {
72
+ throw new Error('Bundle Drop accepts only the exact, finished EAS build requested by ID.');
73
+ }
74
+ if (platform !== params.platform) {
75
+ throw new Error(`EAS build ${buildId} is for ${platform}, not ${params.platform}.`);
76
+ }
77
+ if (typeof artifactUrl !== 'string' || !artifactUrl.trim()) {
78
+ throw new Error('The finished EAS build does not expose an application artifact.');
79
+ }
80
+ const localProjectId = (0, expo_1.evaluateExpoConfig)(params.projectRoot).exp.extra?.eas?.projectId;
81
+ if (typeof localProjectId !== 'string' || projectId !== localProjectId) {
82
+ throw new Error('The EAS build belongs to a different Expo project.');
83
+ }
84
+ assertExactProjectCommit(params.projectRoot, gitCommitHash);
85
+ const identity = await (0, expo_1.resolveExpoBuildIdentity)(params.projectRoot, params.platform, {
86
+ officialAppVersion: appVersion,
87
+ officialNativeBuildVersion: appBuildVersion,
88
+ });
89
+ if (identity.appVersion !== appVersion ||
90
+ identity.nativeVersion !== `${appVersion}(${appBuildVersion})` ||
91
+ identity.runtimeVersion !== runtimeVersion ||
92
+ sdkMajor(identity.expoSdkVersion) !== sdkMajor(sdkVersion)) {
93
+ throw new Error('The official EAS build metadata does not match the current Expo project identity.');
94
+ }
95
+ if (identity.runtimeVersionPolicy === 'fingerprint') {
96
+ const currentFingerprint = await (0, expo_1.resolveExpoProjectFingerprint)(params.projectRoot, params.platform);
97
+ if (currentFingerprint !== fingerprintHash) {
98
+ throw new Error('The official EAS build fingerprint does not match the current project.');
99
+ }
100
+ if (fingerprintHash !== identity.runtimeVersion) {
101
+ throw new Error('The official EAS build fingerprint does not match the Expo runtime identity.');
102
+ }
103
+ }
104
+ return { buildId, identity };
105
+ }
106
+ async function resolveOfficialEasBuildIdentity(params) {
107
+ const resolved = await resolveOfficialEasBuild({
108
+ projectRoot: params.projectRoot,
109
+ platform: params.platform,
110
+ easBuildId: params.proof.easBuildId,
111
+ });
112
+ if (resolved.identity.identityHash !== params.receiptIdentity.identityHash) {
113
+ throw new Error('The official EAS build metadata does not match the receipt and current Expo project identity.');
114
+ }
115
+ return resolved.identity;
116
+ }
@@ -0,0 +1,11 @@
1
+ export type SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
2
+ export declare function detectPackageManager(projectRoot: string): SupportedPackageManager;
3
+ export declare function expoUpdatesRemovalCommand(manager: SupportedPackageManager): string[];
4
+ export type DependencyMigrationBackup = {
5
+ projectRoot: string;
6
+ backupDir: string;
7
+ files: string[];
8
+ possibleCreatedFiles: string[];
9
+ };
10
+ export declare function restoreDependencyMigration(backup: DependencyMigrationBackup): void;
11
+ export declare function removeExpoUpdatesWithPackageManager(projectRoot: string): DependencyMigrationBackup;
@@ -0,0 +1,84 @@
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.detectPackageManager = detectPackageManager;
7
+ exports.expoUpdatesRemovalCommand = expoUpdatesRemovalCommand;
8
+ exports.restoreDependencyMigration = restoreDependencyMigration;
9
+ exports.removeExpoUpdatesWithPackageManager = removeExpoUpdatesWithPackageManager;
10
+ const fs_extra_1 = __importDefault(require("fs-extra"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const child_process_1 = require("child_process");
13
+ const LOCKFILES = {
14
+ npm: ['package-lock.json', 'npm-shrinkwrap.json'],
15
+ yarn: ['yarn.lock'],
16
+ pnpm: ['pnpm-lock.yaml'],
17
+ bun: ['bun.lock', 'bun.lockb'],
18
+ };
19
+ function detectPackageManager(projectRoot) {
20
+ const packageJson = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(projectRoot, 'package.json'), 'utf8'));
21
+ const declared = packageJson.packageManager?.split('@')[0];
22
+ if (declared && declared in LOCKFILES)
23
+ return declared;
24
+ for (const manager of ['pnpm', 'yarn', 'bun', 'npm']) {
25
+ if (LOCKFILES[manager].some(lockfile => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, lockfile)))) {
26
+ return manager;
27
+ }
28
+ }
29
+ return 'npm';
30
+ }
31
+ function expoUpdatesRemovalCommand(manager) {
32
+ return manager === 'npm'
33
+ ? ['npm', 'uninstall', 'expo-updates', '--legacy-peer-deps']
34
+ : [manager, 'remove', 'expo-updates'];
35
+ }
36
+ function restoreDependencyMigration(backup) {
37
+ for (const file of backup.files) {
38
+ fs_extra_1.default.copyFileSync(path_1.default.join(backup.backupDir, file), path_1.default.join(backup.projectRoot, file));
39
+ }
40
+ for (const file of backup.possibleCreatedFiles) {
41
+ const targetPath = path_1.default.join(backup.projectRoot, file);
42
+ if (!backup.files.includes(file) && fs_extra_1.default.existsSync(targetPath)) {
43
+ fs_extra_1.default.unlinkSync(targetPath);
44
+ }
45
+ }
46
+ }
47
+ function removeExpoUpdatesWithPackageManager(projectRoot) {
48
+ const manager = detectPackageManager(projectRoot);
49
+ const command = expoUpdatesRemovalCommand(manager);
50
+ const files = ['package.json', ...LOCKFILES[manager]].filter(file => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, file)));
51
+ const backup = {
52
+ projectRoot,
53
+ backupDir: path_1.default.join(projectRoot, '.bundledrop-backup', `expo-updates-${new Date().toISOString().replace(/[:.]/g, '-')}`),
54
+ files,
55
+ possibleCreatedFiles: LOCKFILES[manager],
56
+ };
57
+ for (const file of files) {
58
+ const backupPath = path_1.default.join(backup.backupDir, file);
59
+ fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
60
+ fs_extra_1.default.copyFileSync(path_1.default.join(projectRoot, file), backupPath);
61
+ }
62
+ const result = (0, child_process_1.spawnSync)(command[0], command.slice(1), {
63
+ cwd: projectRoot,
64
+ stdio: 'inherit',
65
+ shell: false,
66
+ });
67
+ if (result.error || result.status !== 0) {
68
+ restoreDependencyMigration(backup);
69
+ throw new Error(`Failed to remove expo-updates with ${manager}. Package files were restored; ` +
70
+ 'run your package manager install if node_modules needs repair.');
71
+ }
72
+ const packageJson = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(projectRoot, 'package.json'), 'utf8'));
73
+ const stillDeclared = [
74
+ packageJson.dependencies,
75
+ packageJson.devDependencies,
76
+ packageJson.optionalDependencies,
77
+ packageJson.peerDependencies,
78
+ ].some(dependencies => Boolean(dependencies?.['expo-updates']));
79
+ if (stillDeclared) {
80
+ restoreDependencyMigration(backup);
81
+ throw new Error(`${manager} completed but expo-updates is still declared in package.json.`);
82
+ }
83
+ return backup;
84
+ }
@@ -0,0 +1,25 @@
1
+ import type { MobilePlatform } from '../../../expo';
2
+ type WriteBuildReceiptOptions = {
3
+ projectRoot: string;
4
+ platform: MobilePlatform;
5
+ artifactPath: string;
6
+ androidSdkRoot?: string;
7
+ officialAppVersion?: string;
8
+ officialNativeBuildVersion?: string;
9
+ };
10
+ type WriteAndroidBuildCandidateOptions = {
11
+ projectRoot: string;
12
+ outputPath: string;
13
+ officialAppVersion?: string;
14
+ officialNativeBuildVersion?: string;
15
+ };
16
+ /**
17
+ * Creates the deterministic Android asset that Gradle packages before signing.
18
+ * Receipt creation later accepts only the exact candidate extracted from the
19
+ * signed APK/AAB, so changing project config after the build cannot forge proof.
20
+ */
21
+ export declare function writeAndroidBuildIdentityCandidate(options: WriteAndroidBuildCandidateOptions): Promise<string>;
22
+ export declare function writeExpoBuildReceipt(options: WriteBuildReceiptOptions): Promise<string>;
23
+ export declare const parseBuildReceiptArguments: (argv: string[]) => WriteBuildReceiptOptions;
24
+ export declare const parseAndroidBuildCandidateArguments: (argv: string[]) => WriteAndroidBuildCandidateOptions;
25
+ export {};