@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
@@ -3,18 +3,20 @@ 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.isTrustedAiPlanningServer = exports.isSummaryOnlyAiContextFile = void 0;
6
+ exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.findCredentialLikeLiteral = void 0;
7
7
  exports.findProjectRoot = findProjectRoot;
8
- exports.scanProjectForAiNativeInit = scanProjectForAiNativeInit;
8
+ exports.scanProjectForAiSetup = scanProjectForAiSetup;
9
9
  const crypto_1 = __importDefault(require("crypto"));
10
10
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
11
  const module_1 = require("module");
12
12
  const os_1 = __importDefault(require("os"));
13
13
  const path_1 = __importDefault(require("path"));
14
+ const expo_1 = require("../../../expo");
15
+ const native_setup_contract_1 = require("../native-setup-contract");
14
16
  const MAX_UP = 12;
15
17
  const MAX_FILE_BYTES = 80 * 1024;
16
18
  const MAX_TOTAL_BYTES = 350 * 1024;
17
- const PRODUCTION_AI_HOST = 'api.bundledrop.app';
19
+ const TRUSTED_BUNDLE_DROP_AI_HOSTS = new Set(['api.bundledrop.app']);
18
20
  const LOCAL_AI_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '10.0.2.2']);
19
21
  const SKIP_DIRS = new Set([
20
22
  'node_modules',
@@ -30,6 +32,44 @@ const sha256 = (content) => crypto_1.default.createHash('sha256').update(content
30
32
  const toPosix = (filePath) => filePath.split(path_1.default.sep).join('/');
31
33
  const normalizeServerUrl = (url) => url.replace(/\/+$/, '');
32
34
  const readJsonFile = (filePath) => JSON.parse(fs_extra_1.default.readFileSync(filePath, 'utf8'));
35
+ const CREDENTIAL_LITERAL_PATTERNS = [
36
+ {
37
+ name: 'credential-like property',
38
+ pattern: /["'`]?(?:api[_-]?key|access[_-]?key|auth[_-]?token|aws[_-]?secret[_-]?access[_-]?key|client[_-]?secret|deployment[_-]?key|password|passwd|private[_-]?key|secret[_-]?access[_-]?key|secret|token)["'`]?(?:\s*:\s*[A-Za-z_$][A-Za-z0-9_$?.<>,\[\] ]+)?\s*(?::|=|\()\s*@?(["'`])[^\r\n"'`]+\1/i,
39
+ },
40
+ {
41
+ name: 'authorization header',
42
+ pattern: /authorization["'`]?\s*(?::|=)\s*@?(["'`])\s*(?:bearer|basic)\s+[^\r\n"'`]+\1/i,
43
+ },
44
+ {
45
+ name: 'credential-bearing URL',
46
+ pattern: /https?:\/\/[^\s/@:]+:[^\s/@]+@|[?&](?:api[_-]?key|access[_-]?key|auth[_-]?token|password|secret|token)=[^&\s"'`]+/i,
47
+ },
48
+ {
49
+ name: 'private key',
50
+ pattern: /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/,
51
+ },
52
+ {
53
+ name: 'known access token format',
54
+ pattern: /\b(?:AKIA[0-9A-Z]{16}|github_pat_[A-Za-z0-9_]{20,}|gh[oprsu]_[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,})\b/,
55
+ },
56
+ ];
57
+ const findCredentialLikeLiteral = (content) => {
58
+ for (const candidate of CREDENTIAL_LITERAL_PATTERNS) {
59
+ if (candidate.pattern.test(content))
60
+ return candidate.name;
61
+ }
62
+ return null;
63
+ };
64
+ exports.findCredentialLikeLiteral = findCredentialLikeLiteral;
65
+ const assertSafeAiSetupContent = (relativePath, content) => {
66
+ const finding = (0, exports.findCredentialLikeLiteral)(content);
67
+ if (!finding)
68
+ return;
69
+ throw new Error(`Refusing AI setup because ${relativePath} contains a ${finding}. ` +
70
+ 'Move the value to an environment variable or configure this file manually, then retry. ' +
71
+ 'The file was not shared, and --yes cannot bypass this safety check.');
72
+ };
33
73
  const CONTEXT_SUMMARY_SIGNALS = [
34
74
  'react-native',
35
75
  '@gfean/react-native-bundle-drop',
@@ -54,15 +94,6 @@ const CONTEXT_SUMMARY_SIGNALS = [
54
94
  'use_react_native!',
55
95
  'use_native_modules!',
56
96
  ];
57
- const isSummaryOnlyAiContextFile = (relativePath) => relativePath === 'bundle.drop.config.js' ||
58
- relativePath === 'metro.config.js' ||
59
- relativePath.endsWith('.gradle') ||
60
- relativePath.endsWith('.gradle.kts') ||
61
- relativePath.endsWith('settings.gradle') ||
62
- relativePath.endsWith('settings.gradle.kts') ||
63
- relativePath.endsWith('Podfile') ||
64
- relativePath === 'package.json';
65
- exports.isSummaryOnlyAiContextFile = isSummaryOnlyAiContextFile;
66
97
  const summarizeContextContent = (relativePath, rawContent, sizeBytes) => {
67
98
  const matchedSignals = CONTEXT_SUMMARY_SIGNALS.filter(signal => rawContent.includes(signal));
68
99
  const signalLines = matchedSignals.length
@@ -70,83 +101,19 @@ const summarizeContextContent = (relativePath, rawContent, sizeBytes) => {
70
101
  : '- none detected';
71
102
  return [
72
103
  `BundleDrop context summary for ${relativePath}`,
73
- 'Full content omitted to reduce AI planning tokens; this context file is not patchable by init-native.',
104
+ 'Full content omitted to reduce setup-planning tokens; this context file is read-only.',
74
105
  `sizeBytes: ${sizeBytes}`,
75
106
  'signals:',
76
107
  signalLines,
77
108
  '',
78
109
  ].join('\n');
79
110
  };
80
- const codeLikeContent = (content) => {
81
- let result = '';
82
- let state = 'code';
83
- for (let i = 0; i < content.length; i++) {
84
- const char = content[i];
85
- const next = content[i + 1];
86
- if (state === 'line-comment') {
87
- if (char === '\n') {
88
- state = 'code';
89
- result += char;
90
- }
91
- continue;
92
- }
93
- if (state === 'block-comment') {
94
- if (char === '*' && next === '/') {
95
- state = 'code';
96
- i++;
97
- }
98
- continue;
99
- }
100
- if (state === 'single' || state === 'double' || state === 'template') {
101
- if (char === '\\') {
102
- i++;
103
- continue;
104
- }
105
- if ((state === 'single' && char === "'") ||
106
- (state === 'double' && char === '"') ||
107
- (state === 'template' && char === '`')) {
108
- state = 'code';
109
- }
110
- continue;
111
- }
112
- if (char === '/' && next === '/') {
113
- state = 'line-comment';
114
- i++;
115
- continue;
116
- }
117
- if (char === '/' && next === '*') {
118
- state = 'block-comment';
119
- i++;
120
- continue;
121
- }
122
- if (char === "'") {
123
- state = 'single';
124
- continue;
125
- }
126
- if (char === '"') {
127
- state = 'double';
128
- continue;
129
- }
130
- if (char === '`') {
131
- state = 'template';
132
- continue;
133
- }
134
- result += char;
135
- }
136
- return result;
137
- };
138
- const hasBundleDropResolverCall = (content) => {
139
- const code = codeLikeContent(content);
140
- return (code.includes('BundleDropModule.resolveJSBundleFile') ||
141
- code.includes('BundleDropLocator.bundleURL()') ||
142
- code.includes('[BundleDropLocator bundleURL]'));
143
- };
144
111
  const isTrustedAiPlanningServer = (serverUrl) => {
145
112
  if (process.env.BUNDLE_DROP_ALLOW_UNTRUSTED_AI_SERVER === '1')
146
113
  return true;
147
114
  try {
148
115
  const parsed = new URL(serverUrl);
149
- if (parsed.hostname === PRODUCTION_AI_HOST)
116
+ if (TRUSTED_BUNDLE_DROP_AI_HOSTS.has(parsed.hostname))
150
117
  return parsed.protocol === 'https:';
151
118
  if (LOCAL_AI_HOSTS.has(parsed.hostname)) {
152
119
  return parsed.protocol === 'http:' || parsed.protocol === 'https:';
@@ -158,6 +125,16 @@ const isTrustedAiPlanningServer = (serverUrl) => {
158
125
  return false;
159
126
  };
160
127
  exports.isTrustedAiPlanningServer = isTrustedAiPlanningServer;
128
+ const isBundleDropHostedAiPlanningServer = (serverUrl) => {
129
+ try {
130
+ const parsed = new URL(serverUrl);
131
+ return parsed.protocol === 'https:' && TRUSTED_BUNDLE_DROP_AI_HOSTS.has(parsed.hostname);
132
+ }
133
+ catch {
134
+ return false;
135
+ }
136
+ };
137
+ exports.isBundleDropHostedAiPlanningServer = isBundleDropHostedAiPlanningServer;
161
138
  const loadBundleDropConfig = (configPath) => {
162
139
  const moduleLike = { exports: {} };
163
140
  const content = fs_extra_1.default.readFileSync(configPath, 'utf8');
@@ -201,170 +178,217 @@ const findFilesByName = (root, names) => {
201
178
  }
202
179
  return matches.sort();
203
180
  };
204
- const maybeAddFile = (files, seen, projectRoot, filePath, totalBytes) => {
181
+ const readAuthToken = () => {
182
+ const authPath = path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
183
+ if (!fs_extra_1.default.existsSync(authPath)) {
184
+ throw new Error('Not authenticated. Please run `bundle-drop login` before `bundle-drop init`.');
185
+ }
186
+ try {
187
+ const parsed = readJsonFile(authPath);
188
+ if (typeof parsed.token !== 'string' || !parsed.token.trim()) {
189
+ throw new Error('Token missing');
190
+ }
191
+ return parsed.token.trim();
192
+ }
193
+ catch {
194
+ throw new Error('Failed to read CLI auth session. Please run `bundle-drop login` again.');
195
+ }
196
+ };
197
+ const SETUP_CONFIG_FILES = [
198
+ 'bundle.drop.config.js',
199
+ 'bundle.drop.config.cjs',
200
+ 'app.json',
201
+ 'app.config.js',
202
+ 'app.config.ts',
203
+ 'app.config.cjs',
204
+ 'app.config.mjs',
205
+ 'metro.config.js',
206
+ 'metro.config.ts',
207
+ 'metro.config.cjs',
208
+ 'metro.config.mjs',
209
+ ];
210
+ const setupFileKind = (relativePath) => {
211
+ if (relativePath === 'package.json')
212
+ return 'package_manifest';
213
+ if (relativePath.startsWith('bundle.drop.config.'))
214
+ return 'bundle_drop_config';
215
+ if (relativePath === 'app.json' || relativePath.startsWith('app.config.')) {
216
+ return 'expo_app_config';
217
+ }
218
+ if (relativePath.startsWith('metro.config.'))
219
+ return 'metro_config';
220
+ if (relativePath.includes('MainApplication.'))
221
+ return 'android_entrypoint';
222
+ return 'ios_entrypoint';
223
+ };
224
+ const readSetupFile = (projectRoot, relativePath) => {
225
+ const filePath = path_1.default.join(projectRoot, relativePath);
205
226
  if (!fs_extra_1.default.existsSync(filePath))
206
- return;
227
+ return null;
207
228
  const stat = fs_extra_1.default.lstatSync(filePath);
208
- if (stat.isSymbolicLink() || !stat.isFile())
209
- return;
210
- const relative = toPosix(path_1.default.relative(projectRoot, filePath));
211
- /* istanbul ignore next -- defensive guard in case discovery returns the same path twice */
212
- if (seen.has(relative))
213
- return;
214
- const bytes = stat.size;
229
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_FILE_BYTES)
230
+ return null;
215
231
  const rawContent = fs_extra_1.default.readFileSync(filePath, 'utf8');
216
- const content = (0, exports.isSummaryOnlyAiContextFile)(relative)
217
- ? summarizeContextContent(relative, rawContent, bytes)
232
+ const kind = setupFileKind(relativePath);
233
+ if (kind !== 'package_manifest' && kind !== 'bundle_drop_config') {
234
+ assertSafeAiSetupContent(relativePath, rawContent);
235
+ }
236
+ const content = kind === 'package_manifest' || kind === 'bundle_drop_config'
237
+ ? summarizeContextContent(relativePath, rawContent, stat.size)
218
238
  : rawContent;
219
- const contentBytes = Buffer.byteLength(content, 'utf8');
220
- if (contentBytes > MAX_FILE_BYTES || totalBytes.value + contentBytes > MAX_TOTAL_BYTES)
221
- return;
222
- totalBytes.value += contentBytes;
223
- seen.add(relative);
224
- files.push({ path: relative, content, sha256: sha256(content) });
239
+ return {
240
+ kind,
241
+ path: relativePath,
242
+ content,
243
+ sha256: sha256(content),
244
+ };
225
245
  };
226
- const collectFiles = (projectRoot) => {
227
- const files = [];
228
- const seen = new Set();
229
- const totalBytes = { value: 0 };
230
- const add = (relativePath) => maybeAddFile(files, seen, projectRoot, path_1.default.join(projectRoot, relativePath), totalBytes);
231
- add('package.json');
232
- add('bundle.drop.config.js');
233
- add('metro.config.js');
234
- add('android/build.gradle');
235
- add('android/build.gradle.kts');
236
- add('android/settings.gradle');
237
- add('android/settings.gradle.kts');
238
- add('android/app/build.gradle');
239
- add('android/app/build.gradle.kts');
240
- add('ios/Podfile');
241
- for (const srcDir of ['java', 'kotlin']) {
242
- for (const filePath of findFilesByName(path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', srcDir), new Set(['MainApplication.kt', 'MainApplication.java']))) {
243
- maybeAddFile(files, seen, projectRoot, filePath, totalBytes);
246
+ const collectSetupFiles = (projectRoot, projectType) => {
247
+ const relativePaths = ['package.json', ...SETUP_CONFIG_FILES];
248
+ if (projectType === 'bare') {
249
+ for (const srcDir of ['java', 'kotlin']) {
250
+ relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', srcDir), new Set(['MainApplication.kt', 'MainApplication.java'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
244
251
  }
252
+ relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'ios'), new Set(['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
245
253
  }
246
- for (const filePath of findFilesByName(path_1.default.join(projectRoot, 'ios'), new Set(['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m']))) {
247
- maybeAddFile(files, seen, projectRoot, filePath, totalBytes);
254
+ const files = [];
255
+ let totalBytes = 0;
256
+ for (const relativePath of relativePaths) {
257
+ const file = readSetupFile(projectRoot, relativePath);
258
+ if (!file)
259
+ continue;
260
+ const bytes = Buffer.byteLength(file.content, 'utf8');
261
+ if (totalBytes + bytes > MAX_TOTAL_BYTES)
262
+ continue;
263
+ totalBytes += bytes;
264
+ files.push(file);
248
265
  }
249
266
  return files;
250
267
  };
251
- const detectRnVersion = (projectRoot) => {
268
+ const readPackageSignals = (projectRoot) => {
252
269
  const packagePath = path_1.default.join(projectRoot, 'package.json');
253
- if (!fs_extra_1.default.existsSync(packagePath))
254
- return null;
270
+ const pkg = fs_extra_1.default.existsSync(packagePath) ? readJsonFile(packagePath) : {};
271
+ const dependencies = {
272
+ ...(pkg.dependencies || {}),
273
+ ...(pkg.devDependencies || {}),
274
+ ...(pkg.peerDependencies || {}),
275
+ };
276
+ return { pkg, dependencies };
277
+ };
278
+ const resolveInstalledPackageVersion = (projectRoot, packageName) => {
255
279
  try {
256
- const pkg = readJsonFile(packagePath);
257
- return (pkg.dependencies?.['react-native'] ||
258
- pkg.devDependencies?.['react-native'] ||
259
- pkg.peerDependencies?.['react-native'] ||
260
- null);
280
+ const projectRequire = (0, module_1.createRequire)(path_1.default.join(projectRoot, 'package.json'));
281
+ const manifest = readJsonFile(projectRequire.resolve(`${packageName}/package.json`));
282
+ return typeof manifest.version === 'string' ? manifest.version : null;
261
283
  }
262
284
  catch {
263
285
  return null;
264
286
  }
265
287
  };
266
- const detectSignals = (files) => {
267
- const allContent = files.map(file => file.content).join('\n');
268
- const androidEntrypoints = files.filter(file => /(^|\/)android\/(?:.*\/)?MainApplication\.(kt|java)$/.test(file.path));
269
- const iosEntrypoints = files.filter(file => /(^|\/)ios\/(?:.*\/)?AppDelegate\.(swift|m|mm)$/.test(file.path));
270
- const codeContent = files.map(file => codeLikeContent(file.content)).join('\n');
271
- const androidLanguage = files.some(file => file.path.endsWith('MainApplication.kt'))
272
- ? 'kotlin'
273
- : files.some(file => file.path.endsWith('MainApplication.java'))
274
- ? 'java'
275
- : 'unknown';
276
- const iosLanguage = files.some(file => file.path.endsWith('AppDelegate.swift'))
277
- ? 'swift'
278
- : files.some(file => file.path.endsWith('AppDelegate.m') || file.path.endsWith('AppDelegate.mm'))
279
- ? 'objc'
288
+ const detectSetupSignals = (projectRoot, projectType, files) => {
289
+ const { pkg, dependencies } = readPackageSignals(projectRoot);
290
+ const content = files.map(file => file.content).join('\n');
291
+ const expoVersion = dependencies.expo || null;
292
+ const hasBundleDropDependency = Boolean(dependencies['@gfean/react-native-bundle-drop'] || dependencies['react-native-bundle-drop']);
293
+ const hasBundleDropConfig = files.some(file => file.kind === 'bundle_drop_config');
294
+ const evaluatedExpoConfig = projectType === 'expo'
295
+ ? (0, expo_1.evaluateExpoConfig)(projectRoot).exp
296
+ : {};
297
+ const expoPlugins = (evaluatedExpoConfig.plugins || []).map((plugin) => typeof plugin === 'string' ? plugin : Array.isArray(plugin) ? plugin[0] : null);
298
+ const hasBundleDropExpoPlugin = expoPlugins.includes('@gfean/react-native-bundle-drop');
299
+ const nativeEntrypoints = files.filter(file => file.kind === 'android_entrypoint' || file.kind === 'ios_entrypoint');
300
+ const hasBareNativeIntegration = nativeEntrypoints.length > 0 && nativeEntrypoints.every(file => file.kind === 'android_entrypoint'
301
+ ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(file.content)
302
+ : (0, native_setup_contract_1.hasBareIosStartupIntegration)(file.path, file.content));
303
+ const hasBundleDropIntegration = projectType === 'expo'
304
+ ? hasBundleDropExpoPlugin
305
+ : hasBareNativeIntegration;
306
+ const expoUpdatesOwnership = (0, expo_1.inspectExpoUpdatesOwnership)(projectRoot, evaluatedExpoConfig);
307
+ const configuredEngine = /(?:["']jsEngine["']|\bjsEngine)\s*:\s*["']jsc["']/.test(content)
308
+ ? 'jsc'
309
+ : /(?:["']jsEngine["']|\bjsEngine)\s*:\s*["']hermes["']/.test(content)
310
+ ? 'hermes'
280
311
  : 'unknown';
281
312
  const signals = [
282
- 'ReactNativeHost',
283
- 'ReactHost',
284
- 'getDefaultReactHost',
285
- 'loadReactNative',
286
- 'getJSBundleFile',
287
- 'bundleURL',
288
- 'sourceURLForBridge',
289
- 'bundle-drop-config',
290
- ].filter(signal => allContent.includes(signal));
291
- if (androidEntrypoints.length > 1)
292
- signals.push('multipleAndroidEntrypoints');
293
- if (iosEntrypoints.length > 1)
294
- signals.push('multipleIosEntrypoints');
295
- // CodePush migration detection. The native bundle-resolution hooks CodePush
296
- // overrides (Android getJSBundleFile, iOS bundleURL/sourceURLForBridge) are the
297
- // exact seams BundleDrop rewrites, so surfacing these lets the planner migrate
298
- // them and flag the remaining CodePush cleanup.
299
- const hasCodePushDependency = allContent.includes('react-native-code-push');
300
- const hasCodePushAndroidOverride = codeContent.includes('CodePush.getJSBundleFile');
301
- const hasCodePushIosOverride = codeContent.includes('[CodePush bundleURL]') ||
302
- codeContent.includes('CodePush.bundleURL') ||
303
- codeContent.includes('CodePushConfig');
304
- if (hasCodePushDependency)
305
- signals.push('codePushDependency');
306
- if (hasCodePushAndroidOverride)
307
- signals.push('codePushAndroidBundleOverride');
308
- if (hasCodePushIosOverride)
309
- signals.push('codePushIosBundleOverride');
310
- if (hasCodePushDependency || hasCodePushAndroidOverride || hasCodePushIosOverride) {
311
- signals.push('codePushDetected');
312
- }
313
- return {
314
- rnVersion: null,
315
- androidLanguage,
316
- iosLanguage,
313
+ projectType === 'expo' ? 'expoProject' : 'bareProject',
314
+ fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ? 'iosDirectory' : '',
315
+ fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')) ? 'androidDirectory' : '',
316
+ expoUpdatesOwnership.packageIsInstalled || expoUpdatesOwnership.packageIsDeclared
317
+ ? 'expoUpdatesDependency'
318
+ : '',
319
+ dependencies['react-native-code-push'] ? 'codePushDependency' : '',
320
+ pkg.main === 'expo-router/entry' || dependencies['expo-router'] ? 'expoRouter' : '',
321
+ hasBundleDropExpoPlugin ? 'expoBundleDropPlugin' : '',
322
+ ].filter(Boolean);
323
+ const detected = {
324
+ rnVersion: resolveInstalledPackageVersion(projectRoot, 'react-native') ||
325
+ dependencies['react-native'] || null,
326
+ expoSdkVersion: projectType === 'expo'
327
+ ? resolveInstalledPackageVersion(projectRoot, 'expo') || expoVersion
328
+ : null,
329
+ bundleDropStatus: hasBundleDropDependency && hasBundleDropConfig && hasBundleDropIntegration
330
+ ? 'configured'
331
+ : 'partial',
332
+ hasNativeDirectories: fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ||
333
+ fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')),
334
+ usesExpoRouter: Boolean(pkg.main === 'expo-router/entry' || dependencies['expo-router']),
335
+ jsEngine: configuredEngine,
336
+ expoUpdatesStatus: expoUpdatesOwnership.state,
337
+ codePushDetected: Boolean(dependencies['react-native-code-push'] || /\bCodePush\b|codepush\.gradle/.test(content)),
317
338
  signals,
318
- existingBundleDrop: hasBundleDropResolverCall(codeContent),
319
339
  };
320
- };
321
- const readAuthToken = () => {
322
- const authPath = path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
323
- if (!fs_extra_1.default.existsSync(authPath)) {
324
- throw new Error('Not authenticated. Please run `bundle-drop login` before `bundle-drop init-native`.');
325
- }
326
- try {
327
- const parsed = readJsonFile(authPath);
328
- if (typeof parsed.token !== 'string' || !parsed.token.trim()) {
329
- throw new Error('Token missing');
330
- }
331
- return parsed.token.trim();
332
- }
333
- catch {
334
- throw new Error('Failed to read CLI auth session. Please run `bundle-drop login` again.');
340
+ if (projectType === 'expo') {
341
+ const exp = evaluatedExpoConfig;
342
+ const iosEngine = exp.ios?.jsEngine ?? exp.jsEngine ?? 'hermes';
343
+ const androidEngine = exp.android?.jsEngine ?? exp.jsEngine ?? 'hermes';
344
+ detected.jsEngine = iosEngine === androidEngine && ['hermes', 'jsc'].includes(iosEngine)
345
+ ? iosEngine
346
+ : 'unknown';
335
347
  }
348
+ return detected;
336
349
  };
337
- function scanProjectForAiNativeInit(startDir = process.cwd()) {
350
+ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualConfig) {
338
351
  const projectRoot = findProjectRoot(startDir);
339
352
  const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
340
- if (!fs_extra_1.default.existsSync(configPath)) {
353
+ if (!fs_extra_1.default.existsSync(configPath) && !virtualConfig) {
341
354
  throw new Error('bundle.drop.config.js not found; run `bundle-drop init` first.');
342
355
  }
343
- const config = loadBundleDropConfig(configPath);
344
- const serverUrl = typeof config.serverUrl === 'string' ? normalizeServerUrl(config.serverUrl) : '';
345
- const orgSlug = typeof config.org?.slug === 'string' ? config.org.slug.trim() : '';
346
- const projectSlug = typeof config.project?.slug === 'string' ? config.project.slug.trim() : '';
356
+ const config = virtualConfig ? null : loadBundleDropConfig(configPath);
357
+ const serverUrl = virtualConfig
358
+ ? normalizeServerUrl(virtualConfig.serverUrl)
359
+ : typeof config?.serverUrl === 'string' ? normalizeServerUrl(config.serverUrl) : '';
360
+ const orgSlug = virtualConfig?.orgSlug ||
361
+ (typeof config?.org?.slug === 'string' ? config.org.slug.trim() : '');
362
+ const projectSlug = virtualConfig?.projectSlug ||
363
+ (typeof config?.project?.slug === 'string' ? config.project.slug.trim() : '');
347
364
  if (!serverUrl || !orgSlug || !projectSlug) {
348
365
  throw new Error('Missing "serverUrl", "org.slug" or "project.slug" in bundle.drop.config.js.');
349
366
  }
350
367
  if (!(0, exports.isTrustedAiPlanningServer)(serverUrl)) {
351
- throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}. ` +
352
- 'Use https://api.bundledrop.app or a local development server.');
368
+ throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}.`);
369
+ }
370
+ const files = collectSetupFiles(projectRoot, projectType);
371
+ if (virtualConfig && !files.some(file => file.kind === 'bundle_drop_config')) {
372
+ const summarizedConfig = summarizeContextContent('bundle.drop.config.js', virtualConfig.content, Buffer.byteLength(virtualConfig.content, 'utf8'));
373
+ files.push({
374
+ kind: 'bundle_drop_config',
375
+ path: 'bundle.drop.config.js',
376
+ content: summarizedConfig,
377
+ sha256: sha256(summarizedConfig),
378
+ });
353
379
  }
354
- const files = collectFiles(projectRoot);
355
- const detected = detectSignals(files);
356
- detected.rnVersion = detectRnVersion(projectRoot);
357
380
  return {
358
381
  projectRoot,
359
382
  serverUrl,
360
383
  orgSlug,
361
384
  projectSlug,
362
- authToken: readAuthToken(),
385
+ authToken: virtualConfig?.authToken || readAuthToken(),
363
386
  request: {
364
387
  schemaVersion: 1,
365
388
  orgSlug,
366
389
  projectSlug,
367
- detected,
390
+ projectType,
391
+ detected: detectSetupSignals(projectRoot, projectType, files),
368
392
  files,
369
393
  },
370
394
  };
@@ -1,53 +1,57 @@
1
- export type AiInitConfidence = 'high' | 'medium' | 'low';
2
- export type AiInitDecisionType = 'safe_auto_patch' | 'review_only_patch' | 'manual_fallback' | 'skip';
3
- export type AiInitDetected = {
1
+ export type AiSetupConfidence = 'high' | 'medium' | 'low';
2
+ export type AiSetupDecisionType = 'safe_auto_patch' | 'review_only_patch' | 'manual_fallback' | 'skip';
3
+ export type AiPatchPlan = {
4
+ file: string;
5
+ originalSha256: string;
6
+ updated: string;
7
+ reason: string;
8
+ confidence: AiSetupConfidence;
9
+ decisionType: AiSetupDecisionType;
10
+ };
11
+ export type AiSetupProjectType = 'expo' | 'bare';
12
+ export type AiSetupFileKind = 'package_manifest' | 'bundle_drop_config' | 'expo_app_config' | 'metro_config' | 'android_entrypoint' | 'ios_entrypoint';
13
+ export type AiSetupDetected = {
4
14
  rnVersion: string | null;
5
- androidLanguage: 'kotlin' | 'java' | 'unknown';
6
- iosLanguage: 'swift' | 'objc' | 'unknown';
15
+ expoSdkVersion: string | null;
16
+ bundleDropStatus: 'absent' | 'partial' | 'configured';
17
+ hasNativeDirectories: boolean;
18
+ usesExpoRouter: boolean;
19
+ jsEngine: 'hermes' | 'jsc' | 'unknown';
20
+ expoUpdatesStatus: 'absent' | 'disabled' | 'active';
21
+ codePushDetected: boolean;
7
22
  signals: string[];
8
- existingBundleDrop: boolean;
9
23
  };
10
- export type AiInitPlanFile = {
24
+ export type AiSetupPlanFile = {
11
25
  path: string;
12
26
  content: string;
13
27
  sha256: string;
28
+ kind: AiSetupFileKind;
14
29
  };
15
- export type AiInitPlanRequest = {
30
+ export type AiSetupPlanRequest = {
16
31
  schemaVersion: 1;
17
32
  orgSlug: string;
18
33
  projectSlug: string;
19
- detected: AiInitDetected;
20
- files: AiInitPlanFile[];
21
- };
22
- export type AiPatchPlan = {
23
- file: string;
24
- originalSha256: string;
25
- updated: string;
26
- reason: string;
27
- confidence: AiInitConfidence;
28
- decisionType: AiInitDecisionType;
29
- };
30
- export type AiInitQuestion = {
31
- id: string;
32
- severity: 'info' | 'warning' | 'risky';
33
- file?: string | null;
34
- message: string;
35
- prompt: string;
36
- recommendedChoice: 'yes' | 'no';
37
- yesAction?: AiPatchPlan | null;
38
- noAction?: AiPatchPlan | 'manual_fallback' | 'skip' | null;
34
+ projectType: AiSetupProjectType;
35
+ detected: AiSetupDetected;
36
+ files: AiSetupPlanFile[];
39
37
  };
40
- export type AiInitPlanResponse = {
41
- confidence: AiInitConfidence;
38
+ export type AiSetupActionType = 'register_expo_plugin' | 'configure_bundle_drop' | 'preserve_expo_metro' | 'migrate_expo_updates' | 'configure_bare_native' | 'migrate_codepush' | 'require_native_rebuild' | 'run_doctor';
39
+ export type AiSetupPlanResponse = {
40
+ confidence: AiSetupConfidence;
42
41
  summary: string;
42
+ actions: Array<{
43
+ type: AiSetupActionType;
44
+ reason: string;
45
+ requiresConfirmation: boolean;
46
+ }>;
43
47
  changes: AiPatchPlan[];
44
- questions: AiInitQuestion[];
48
+ warnings: string[];
45
49
  };
46
- export type AiScannerResult = {
50
+ export type AiSetupScannerResult = {
47
51
  projectRoot: string;
48
52
  serverUrl: string;
49
53
  orgSlug: string;
50
54
  projectSlug: string;
51
55
  authToken: string;
52
- request: AiInitPlanRequest;
56
+ request: AiSetupPlanRequest;
53
57
  };
@@ -1,8 +1,15 @@
1
1
  import { AiPatchPlan } from './types';
2
+ import { AiSetupProjectType } from './types';
2
3
  export declare const isSafeRelativePath: (value: string) => boolean;
3
4
  export declare const isPatchableNativeEntrypoint: (filePath: string) => boolean;
4
- export declare function validateChangesBeforeApply(params: {
5
+ export declare const isPatchableExpoConfig: (filePath: string) => boolean;
6
+ export declare function validateSetupChangesBeforeApply(params: {
7
+ projectType: AiSetupProjectType;
5
8
  originals: Map<string, string>;
6
9
  changes: AiPatchPlan[];
7
10
  }): void;
8
- export declare function validateAppliedChanges(projectRoot: string, changes: AiPatchPlan[]): void;
11
+ export declare function validateAppliedSetupChanges(params: {
12
+ projectRoot: string;
13
+ projectType: AiSetupProjectType;
14
+ changes: AiPatchPlan[];
15
+ }): void;