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

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.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Bundle Drop
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/%40gfean%2Freact-native-bundle-drop?color=2b7fff&label=npm)](https://www.npmjs.com/package/@gfean/react-native-bundle-drop)
4
+ [![CI](https://github.com/GFean/react-native-bundle-drop/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/GFean/react-native-bundle-drop/actions/workflows/ci.yml)
4
5
  [![license](https://img.shields.io/badge/license-ISC-84cc16)](#license)
5
6
  [![website](https://img.shields.io/badge/website-bundledrop.app-2563eb)](https://bundledrop.app)
6
7
  [![docs](https://img.shields.io/badge/docs-bundledrop.app%2Fdocs-0f766e)](https://bundledrop.app/docs)
package/lib/CLI/cli.js CHANGED
@@ -20,6 +20,11 @@ const DEFAULT_SERVER_URL = 'https://api.bundledrop.app';
20
20
  const DOCS_CLI_URL = 'https://bundledrop.app/docs/cli';
21
21
  const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
22
22
  const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
23
+ const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
24
+ const setupErrorWithManualInstallation = (error) => {
25
+ const message = error instanceof Error ? error.message : String(error);
26
+ return new Error(`${message}\nManual installation: ${DOCS_INSTALLATION_URL}`);
27
+ };
23
28
  const getTokenPath = () => path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
24
29
  const normalizeServerUrl = (url) => url?.replace(/\/$/, '') || DEFAULT_SERVER_URL;
25
30
  const readStoredAuthData = () => {
@@ -83,7 +88,7 @@ const buildProgram = () => {
83
88
  .version(package_json_1.default.version || '0.0.0', '-v, --cli-version', 'Show CLI version');
84
89
  program.addHelpText('beforeAll', logo);
85
90
  program.addHelpText('before', `
86
- ${chalk_1.default.magentaBright('A blazing-fast OTA delivery system for React Native by GFean.\n')}
91
+ ${chalk_1.default.magentaBright('Ship OTA Updates with Confidence\n')}
87
92
  ${chalk_1.default.bold.cyan('Available Commands:')}
88
93
  `);
89
94
  program.addHelpText('afterAll', `
@@ -151,28 +156,87 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
151
156
  .option('--yes', 'Approve ordinary setup changes noninteractively')
152
157
  .description('Configure Bundle Drop for Expo or bare React Native')
153
158
  .action(async (options) => {
154
- if (options.projectType && !['expo', 'bare'].includes(options.projectType)) {
155
- throw new Error('--project-type must be expo or bare.');
156
- }
157
- if (options.token) {
159
+ try {
160
+ if (options.projectType && !['expo', 'bare'].includes(options.projectType)) {
161
+ throw new Error('--project-type must be expo or bare.');
162
+ }
163
+ if (options.token) {
164
+ const { detectProjectType } = require('../expo');
165
+ const projectType = detectProjectType({
166
+ projectRoot: process.cwd(),
167
+ explicitType: options.projectType,
168
+ });
169
+ const serverUrl = normalizeServerUrl(process.env.BUNDLE_DROP_SERVER_URL);
170
+ const tokenContext = await fetchFreshAuthContext({
171
+ serverUrl,
172
+ token: options.token,
173
+ });
174
+ const initConfigModule = require('../CLI/scripts/init-config');
175
+ const hadConfig = initConfigModule.hasExistingBundleDropConfig();
176
+ const configResult = await initConfigModule.initConfig({
177
+ serverUrl,
178
+ projects: tokenContext?.projects || [],
179
+ organizations: tokenContext?.organizations || [],
180
+ downloadApiKey: '',
181
+ authToken: options.token,
182
+ dryRun: true,
183
+ projectType,
184
+ });
185
+ await (0, post_init_1.runPostInitPrompts)({
186
+ ...options,
187
+ projectType,
188
+ ...(!hadConfig && configResult
189
+ ? {
190
+ virtualConfig: {
191
+ content: configResult.content,
192
+ serverUrl: configResult.serverUrl,
193
+ orgSlug: configResult.orgSlug,
194
+ projectSlug: configResult.projectSlug,
195
+ authToken: options.token,
196
+ },
197
+ }
198
+ : {}),
199
+ });
200
+ return;
201
+ }
202
+ const authState = readStoredAuthData();
203
+ if (!authState.exists) {
204
+ console.log('ℹ️ Not logged in. Please run `bundle-drop login` or use --token.\n' +
205
+ `CLI docs: ${DOCS_CLI_URL}\n` +
206
+ `CI/CD docs: ${DOCS_CI_CD_URL}`);
207
+ return;
208
+ }
209
+ if (authState.isInvalid || !authState.data) {
210
+ logInvalidAuthFile();
211
+ return;
212
+ }
213
+ const data = authState.data;
214
+ if (!data.token) {
215
+ logInvalidAuthFile();
216
+ return;
217
+ }
158
218
  const { detectProjectType } = require('../expo');
159
219
  const projectType = detectProjectType({
160
220
  projectRoot: process.cwd(),
161
221
  explicitType: options.projectType,
162
222
  });
163
- const serverUrl = normalizeServerUrl(process.env.BUNDLE_DROP_SERVER_URL);
164
- const tokenContext = await fetchFreshAuthContext({
223
+ const serverUrl = normalizeServerUrl(data.serverUrl || data.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
224
+ const freshContext = await fetchFreshAuthContext({
165
225
  serverUrl,
166
- token: options.token,
226
+ token: data.token,
167
227
  });
228
+ const initData = freshContext ? { ...data, ...freshContext } : data;
229
+ if (freshContext) {
230
+ writeStoredAuthData(authState.tokenPath, initData);
231
+ }
168
232
  const initConfigModule = require('../CLI/scripts/init-config');
169
233
  const hadConfig = initConfigModule.hasExistingBundleDropConfig();
170
234
  const configResult = await initConfigModule.initConfig({
171
235
  serverUrl,
172
- projects: tokenContext?.projects || [],
173
- organizations: tokenContext?.organizations || [],
174
- downloadApiKey: '',
175
- authToken: options.token,
236
+ projects: initData.projects || [],
237
+ organizations: initData.organizations || [],
238
+ downloadApiKey: data.downloadApiKey || '',
239
+ authToken: data.token,
176
240
  dryRun: true,
177
241
  projectType,
178
242
  });
@@ -186,86 +250,15 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
186
250
  serverUrl: configResult.serverUrl,
187
251
  orgSlug: configResult.orgSlug,
188
252
  projectSlug: configResult.projectSlug,
189
- authToken: options.token,
253
+ authToken: data.token,
190
254
  },
191
255
  }
192
256
  : {}),
193
257
  });
194
- return;
195
- }
196
- const authState = readStoredAuthData();
197
- if (!authState.exists) {
198
- console.log('ℹ️ Not logged in. Please run `bundle-drop login` or use --token.\n' +
199
- `CLI docs: ${DOCS_CLI_URL}\n` +
200
- `CI/CD docs: ${DOCS_CI_CD_URL}`);
201
- return;
202
- }
203
- if (authState.isInvalid || !authState.data) {
204
- logInvalidAuthFile();
205
- return;
206
- }
207
- const data = authState.data;
208
- if (!data.token) {
209
- logInvalidAuthFile();
210
- return;
211
258
  }
212
- const { detectProjectType } = require('../expo');
213
- const projectType = detectProjectType({
214
- projectRoot: process.cwd(),
215
- explicitType: options.projectType,
216
- });
217
- const serverUrl = normalizeServerUrl(data.serverUrl || data.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
218
- const freshContext = await fetchFreshAuthContext({
219
- serverUrl,
220
- token: data.token,
221
- });
222
- const initData = freshContext ? { ...data, ...freshContext } : data;
223
- if (freshContext) {
224
- writeStoredAuthData(authState.tokenPath, initData);
225
- }
226
- const initConfigModule = require('../CLI/scripts/init-config');
227
- const hadConfig = initConfigModule.hasExistingBundleDropConfig();
228
- const configResult = await initConfigModule.initConfig({
229
- serverUrl,
230
- projects: initData.projects || [],
231
- organizations: initData.organizations || [],
232
- downloadApiKey: data.downloadApiKey || '',
233
- authToken: data.token,
234
- dryRun: true,
235
- projectType,
236
- });
237
- await (0, post_init_1.runPostInitPrompts)({
238
- ...options,
239
- projectType,
240
- ...(!hadConfig && configResult
241
- ? {
242
- virtualConfig: {
243
- content: configResult.content,
244
- serverUrl: configResult.serverUrl,
245
- orgSlug: configResult.orgSlug,
246
- projectSlug: configResult.projectSlug,
247
- authToken: data.token,
248
- },
249
- }
250
- : {}),
251
- });
252
- });
253
- program
254
- .command('init-native')
255
- .description('Deprecated bare-only native setup escape hatch; use bundle-drop init')
256
- .action(async () => {
257
- const { detectProjectType } = require('../expo');
258
- if (detectProjectType({ projectRoot: process.cwd() }) === 'expo') {
259
- throw new Error('init-native is bare-only. Run `bundle-drop init` for Expo projects.');
259
+ catch (error) {
260
+ throw setupErrorWithManualInstallation(error);
260
261
  }
261
- console.log(chalk_1.default.yellow('init-native is deprecated; use `bundle-drop init --project-type bare`.'));
262
- await require('../CLI/scripts/aipowered/init-native-config').initNativeConfigAi();
263
- });
264
- program
265
- .command('init-metro')
266
- .description('Ensure Metro can resolve bundle.drop.config.js via extraNodeModules alias')
267
- .action(() => {
268
- require('../CLI/scripts/init-metro-config').initMetroConfig();
269
262
  });
270
263
  program
271
264
  .command('doctor')
package/lib/CLI/logo.js CHANGED
@@ -21,6 +21,6 @@ const buildBundleDropLogo = () => {
21
21
  ? exports.BUNDLE_DROP_LOGO_TRUECOLOR
22
22
  : chalk_1.default.cyanBright(exports.BUNDLE_DROP_LOGO_MONO);
23
23
  const title = chalk_1.default.bold.cyanBright(`${figures_1.default.star} React Native Bundle Drop CLI ${figures_1.default.star}`);
24
- return `\n${art}\n${title}`;
24
+ return `\n${art}\n\n${title}`;
25
25
  };
26
26
  exports.buildBundleDropLogo = buildBundleDropLogo;
@@ -1,9 +1,4 @@
1
- import { AiInitPlanRequest, AiInitPlanResponse, AiSetupPlanRequest, AiSetupPlanResponse } from './types';
2
- export declare function requestAiInitPlan(params: {
3
- serverUrl: string;
4
- authToken: string;
5
- request: AiInitPlanRequest;
6
- }): Promise<AiInitPlanResponse>;
1
+ import { AiSetupPlanRequest, AiSetupPlanResponse } from './types';
7
2
  export declare function requestAiSetupPlan(params: {
8
3
  serverUrl: string;
9
4
  authToken: string;
@@ -3,7 +3,6 @@ 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.requestAiInitPlan = requestAiInitPlan;
7
6
  exports.requestAiSetupPlan = requestAiSetupPlan;
8
7
  const axios_1 = __importDefault(require("axios"));
9
8
  const DEFAULT_AI_INIT_TIMEOUT_MS = 180000;
@@ -11,28 +10,6 @@ const resolveTimeoutMs = () => {
11
10
  const value = Number(process.env.BUNDLE_DROP_AI_INIT_TIMEOUT_MS || '');
12
11
  return Number.isFinite(value) && value > 0 ? value : DEFAULT_AI_INIT_TIMEOUT_MS;
13
12
  };
14
- async function requestAiInitPlan(params) {
15
- try {
16
- const response = await axios_1.default.post(`${params.serverUrl}/ai/init-plan`, params.request, {
17
- headers: {
18
- Accept: 'application/json',
19
- Authorization: `Bearer ${params.authToken}`,
20
- },
21
- timeout: resolveTimeoutMs(),
22
- });
23
- return response.data;
24
- }
25
- catch (error) {
26
- const raw = error?.response?.data;
27
- if (error?.code === 'ECONNABORTED' || /timeout/i.test(String(error?.message || ''))) {
28
- throw new Error('AI planning request timed out. Try again, or set BUNDLE_DROP_AI_INIT_TIMEOUT_MS to a larger value.');
29
- }
30
- const message = raw && typeof raw === 'object'
31
- ? raw.error || JSON.stringify(raw)
32
- : raw || error?.message || 'AI planning request failed';
33
- throw new Error(`AI planning request failed: ${message}`);
34
- }
35
- }
36
13
  async function requestAiSetupPlan(params) {
37
14
  try {
38
15
  const response = await axios_1.default.post(`${params.serverUrl}/ai/setup-plan`, params.request, {
@@ -11,7 +11,7 @@ const path_1 = __importDefault(require("path"));
11
11
  const prompts_1 = __importDefault(require("prompts"));
12
12
  const child_process_1 = require("child_process");
13
13
  const expo_1 = require("../../../expo");
14
- const init_metro_config_1 = require("../init-metro-config");
14
+ const bare_metro_config_1 = require("../bare-metro-config");
15
15
  const doctor_1 = require("../doctor");
16
16
  const configure_expo_1 = require("../expo/configure-expo");
17
17
  const package_manager_1 = require("../expo/package-manager");
@@ -142,11 +142,29 @@ const assertSetupOwnershipCompatible = (projectType, expoUpdatesStatus) => {
142
142
  'Bundle Drop cannot safely choose the native startup authority. Remove or explicitly disable ' +
143
143
  'expo-updates, create a new native binary, and retry. No context was shared and no files were changed.');
144
144
  };
145
+ const existingSetupPassesDoctor = async (projectRoot, projectType, detected) => {
146
+ if (detected.bundleDropStatus !== 'configured')
147
+ return false;
148
+ if (detected.expoUpdatesStatus === 'active' || detected.codePushDetected)
149
+ return false;
150
+ try {
151
+ const result = await (0, doctor_1.inspectProject)({ cwd: projectRoot, projectType });
152
+ return result.checks.every(check => check.status !== 'error');
153
+ }
154
+ catch {
155
+ return false;
156
+ }
157
+ };
145
158
  async function initProjectConfigAi(options = {}) {
146
159
  const projectRoot = (0, scanner_1.findProjectRoot)(process.cwd());
147
160
  const projectType = (0, expo_1.detectProjectType)({ projectRoot, explicitType: options.projectType });
148
161
  const scan = (0, scanner_1.scanProjectForAiSetup)(projectType, projectRoot, options.virtualConfig);
149
162
  assertSetupOwnershipCompatible(projectType, scan.request.detected.expoUpdatesStatus);
163
+ if (await existingSetupPassesDoctor(projectRoot, projectType, scan.request.detected)) {
164
+ console.log(chalk_1.default.green('✅ Bundle Drop setup is already complete. No AI planning is required.'));
165
+ await (0, doctor_1.runDoctor)({ projectType, cwd: projectRoot });
166
+ return;
167
+ }
150
168
  console.log(chalk_1.default.cyan(`🧠 Bundle Drop AI setup (${projectType})`));
151
169
  if (!(await requestContextConsent(scan.request.files, scan.serverUrl, options.yes))) {
152
170
  console.log(chalk_1.default.gray('No context sent. No files changed.'));
@@ -208,7 +226,7 @@ async function initProjectConfigAi(options = {}) {
208
226
  const originals = new Map(scan.request.files.map(file => [file.path, file.content]));
209
227
  (0, validate_plan_1.validateSetupChangesBeforeApply)({ projectType, originals, changes: aiChanges });
210
228
  if (projectType === 'bare') {
211
- const metroChange = (0, init_metro_config_1.planBareMetroConfig)(projectRoot);
229
+ const metroChange = (0, bare_metro_config_1.planBareMetroConfig)(projectRoot);
212
230
  const bundleConfigPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
213
231
  const bundleConfigExists = fs_extra_1.default.existsSync(bundleConfigPath);
214
232
  const bundleConfig = bundleConfigExists
@@ -1,10 +1,8 @@
1
- import { AiScannerResult, AiSetupProjectType, AiSetupScannerResult } from './types';
1
+ import { AiSetupProjectType, AiSetupScannerResult } from './types';
2
2
  export declare const findCredentialLikeLiteral: (content: string) => string | null;
3
- export declare const isSummaryOnlyAiContextFile: (relativePath: string) => boolean;
4
3
  export declare const isTrustedAiPlanningServer: (serverUrl: string) => boolean;
5
4
  export declare const isBundleDropHostedAiPlanningServer: (serverUrl: string) => boolean;
6
5
  export declare function findProjectRoot(startDir?: string): string;
7
- export declare function scanProjectForAiNativeInit(startDir?: string): AiScannerResult;
8
6
  export declare function scanProjectForAiSetup(projectType: AiSetupProjectType, startDir?: string, virtualConfig?: {
9
7
  content: string;
10
8
  serverUrl: string;
@@ -3,9 +3,8 @@ 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.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.isSummaryOnlyAiContextFile = exports.findCredentialLikeLiteral = void 0;
6
+ exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.findCredentialLikeLiteral = void 0;
7
7
  exports.findProjectRoot = findProjectRoot;
8
- exports.scanProjectForAiNativeInit = scanProjectForAiNativeInit;
9
8
  exports.scanProjectForAiSetup = scanProjectForAiSetup;
10
9
  const crypto_1 = __importDefault(require("crypto"));
11
10
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -13,6 +12,7 @@ const module_1 = require("module");
13
12
  const os_1 = __importDefault(require("os"));
14
13
  const path_1 = __importDefault(require("path"));
15
14
  const expo_1 = require("../../../expo");
15
+ const native_setup_contract_1 = require("../native-setup-contract");
16
16
  const MAX_UP = 12;
17
17
  const MAX_FILE_BYTES = 80 * 1024;
18
18
  const MAX_TOTAL_BYTES = 350 * 1024;
@@ -94,15 +94,6 @@ const CONTEXT_SUMMARY_SIGNALS = [
94
94
  'use_react_native!',
95
95
  'use_native_modules!',
96
96
  ];
97
- const isSummaryOnlyAiContextFile = (relativePath) => relativePath === 'bundle.drop.config.js' ||
98
- relativePath === 'metro.config.js' ||
99
- relativePath.endsWith('.gradle') ||
100
- relativePath.endsWith('.gradle.kts') ||
101
- relativePath.endsWith('settings.gradle') ||
102
- relativePath.endsWith('settings.gradle.kts') ||
103
- relativePath.endsWith('Podfile') ||
104
- relativePath === 'package.json';
105
- exports.isSummaryOnlyAiContextFile = isSummaryOnlyAiContextFile;
106
97
  const summarizeContextContent = (relativePath, rawContent, sizeBytes) => {
107
98
  const matchedSignals = CONTEXT_SUMMARY_SIGNALS.filter(signal => rawContent.includes(signal));
108
99
  const signalLines = matchedSignals.length
@@ -110,77 +101,13 @@ const summarizeContextContent = (relativePath, rawContent, sizeBytes) => {
110
101
  : '- none detected';
111
102
  return [
112
103
  `BundleDrop context summary for ${relativePath}`,
113
- '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.',
114
105
  `sizeBytes: ${sizeBytes}`,
115
106
  'signals:',
116
107
  signalLines,
117
108
  '',
118
109
  ].join('\n');
119
110
  };
120
- const codeLikeContent = (content) => {
121
- let result = '';
122
- let state = 'code';
123
- for (let i = 0; i < content.length; i++) {
124
- const char = content[i];
125
- const next = content[i + 1];
126
- if (state === 'line-comment') {
127
- if (char === '\n') {
128
- state = 'code';
129
- result += char;
130
- }
131
- continue;
132
- }
133
- if (state === 'block-comment') {
134
- if (char === '*' && next === '/') {
135
- state = 'code';
136
- i++;
137
- }
138
- continue;
139
- }
140
- if (state === 'single' || state === 'double' || state === 'template') {
141
- if (char === '\\') {
142
- i++;
143
- continue;
144
- }
145
- if ((state === 'single' && char === "'") ||
146
- (state === 'double' && char === '"') ||
147
- (state === 'template' && char === '`')) {
148
- state = 'code';
149
- }
150
- continue;
151
- }
152
- if (char === '/' && next === '/') {
153
- state = 'line-comment';
154
- i++;
155
- continue;
156
- }
157
- if (char === '/' && next === '*') {
158
- state = 'block-comment';
159
- i++;
160
- continue;
161
- }
162
- if (char === "'") {
163
- state = 'single';
164
- continue;
165
- }
166
- if (char === '"') {
167
- state = 'double';
168
- continue;
169
- }
170
- if (char === '`') {
171
- state = 'template';
172
- continue;
173
- }
174
- result += char;
175
- }
176
- return result;
177
- };
178
- const hasBundleDropResolverCall = (content) => {
179
- const code = codeLikeContent(content);
180
- return (code.includes('BundleDropModule.resolveJSBundleFile') ||
181
- code.includes('BundleDropLocator.bundleURL()') ||
182
- code.includes('[BundleDropLocator bundleURL]'));
183
- };
184
111
  const isTrustedAiPlanningServer = (serverUrl) => {
185
112
  if (process.env.BUNDLE_DROP_ALLOW_UNTRUSTED_AI_SERVER === '1')
186
113
  return true;
@@ -251,130 +178,10 @@ const findFilesByName = (root, names) => {
251
178
  }
252
179
  return matches.sort();
253
180
  };
254
- const maybeAddFile = (files, seen, projectRoot, filePath, totalBytes) => {
255
- if (!fs_extra_1.default.existsSync(filePath))
256
- return;
257
- const stat = fs_extra_1.default.lstatSync(filePath);
258
- if (stat.isSymbolicLink() || !stat.isFile())
259
- return;
260
- const relative = toPosix(path_1.default.relative(projectRoot, filePath));
261
- /* istanbul ignore next -- defensive guard in case discovery returns the same path twice */
262
- if (seen.has(relative))
263
- return;
264
- const bytes = stat.size;
265
- const rawContent = fs_extra_1.default.readFileSync(filePath, 'utf8');
266
- const summaryOnly = (0, exports.isSummaryOnlyAiContextFile)(relative);
267
- if (!summaryOnly)
268
- assertSafeAiSetupContent(relative, rawContent);
269
- const content = summaryOnly
270
- ? summarizeContextContent(relative, rawContent, bytes)
271
- : rawContent;
272
- const contentBytes = Buffer.byteLength(content, 'utf8');
273
- if (contentBytes > MAX_FILE_BYTES || totalBytes.value + contentBytes > MAX_TOTAL_BYTES)
274
- return;
275
- totalBytes.value += contentBytes;
276
- seen.add(relative);
277
- files.push({ path: relative, content, sha256: sha256(content) });
278
- };
279
- const collectFiles = (projectRoot) => {
280
- const files = [];
281
- const seen = new Set();
282
- const totalBytes = { value: 0 };
283
- const add = (relativePath) => maybeAddFile(files, seen, projectRoot, path_1.default.join(projectRoot, relativePath), totalBytes);
284
- add('package.json');
285
- add('bundle.drop.config.js');
286
- add('metro.config.js');
287
- add('android/build.gradle');
288
- add('android/build.gradle.kts');
289
- add('android/settings.gradle');
290
- add('android/settings.gradle.kts');
291
- add('android/app/build.gradle');
292
- add('android/app/build.gradle.kts');
293
- add('ios/Podfile');
294
- for (const srcDir of ['java', 'kotlin']) {
295
- for (const filePath of findFilesByName(path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', srcDir), new Set(['MainApplication.kt', 'MainApplication.java']))) {
296
- maybeAddFile(files, seen, projectRoot, filePath, totalBytes);
297
- }
298
- }
299
- for (const filePath of findFilesByName(path_1.default.join(projectRoot, 'ios'), new Set(['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m']))) {
300
- maybeAddFile(files, seen, projectRoot, filePath, totalBytes);
301
- }
302
- return files;
303
- };
304
- const detectRnVersion = (projectRoot) => {
305
- const packagePath = path_1.default.join(projectRoot, 'package.json');
306
- if (!fs_extra_1.default.existsSync(packagePath))
307
- return null;
308
- try {
309
- const pkg = readJsonFile(packagePath);
310
- return (pkg.dependencies?.['react-native'] ||
311
- pkg.devDependencies?.['react-native'] ||
312
- pkg.peerDependencies?.['react-native'] ||
313
- null);
314
- }
315
- catch {
316
- return null;
317
- }
318
- };
319
- const detectSignals = (files) => {
320
- const allContent = files.map(file => file.content).join('\n');
321
- const androidEntrypoints = files.filter(file => /(^|\/)android\/(?:.*\/)?MainApplication\.(kt|java)$/.test(file.path));
322
- const iosEntrypoints = files.filter(file => /(^|\/)ios\/(?:.*\/)?AppDelegate\.(swift|m|mm)$/.test(file.path));
323
- const codeContent = files.map(file => codeLikeContent(file.content)).join('\n');
324
- const androidLanguage = files.some(file => file.path.endsWith('MainApplication.kt'))
325
- ? 'kotlin'
326
- : files.some(file => file.path.endsWith('MainApplication.java'))
327
- ? 'java'
328
- : 'unknown';
329
- const iosLanguage = files.some(file => file.path.endsWith('AppDelegate.swift'))
330
- ? 'swift'
331
- : files.some(file => file.path.endsWith('AppDelegate.m') || file.path.endsWith('AppDelegate.mm'))
332
- ? 'objc'
333
- : 'unknown';
334
- const signals = [
335
- 'ReactNativeHost',
336
- 'ReactHost',
337
- 'getDefaultReactHost',
338
- 'loadReactNative',
339
- 'getJSBundleFile',
340
- 'bundleURL',
341
- 'sourceURLForBridge',
342
- 'bundle-drop-config',
343
- ].filter(signal => allContent.includes(signal));
344
- if (androidEntrypoints.length > 1)
345
- signals.push('multipleAndroidEntrypoints');
346
- if (iosEntrypoints.length > 1)
347
- signals.push('multipleIosEntrypoints');
348
- // CodePush migration detection. The native bundle-resolution hooks CodePush
349
- // overrides (Android getJSBundleFile, iOS bundleURL/sourceURLForBridge) are the
350
- // exact seams BundleDrop rewrites, so surfacing these lets the planner migrate
351
- // them and flag the remaining CodePush cleanup.
352
- const hasCodePushDependency = allContent.includes('react-native-code-push');
353
- const hasCodePushAndroidOverride = codeContent.includes('CodePush.getJSBundleFile');
354
- const hasCodePushIosOverride = codeContent.includes('[CodePush bundleURL]') ||
355
- codeContent.includes('CodePush.bundleURL') ||
356
- codeContent.includes('CodePushConfig');
357
- if (hasCodePushDependency)
358
- signals.push('codePushDependency');
359
- if (hasCodePushAndroidOverride)
360
- signals.push('codePushAndroidBundleOverride');
361
- if (hasCodePushIosOverride)
362
- signals.push('codePushIosBundleOverride');
363
- if (hasCodePushDependency || hasCodePushAndroidOverride || hasCodePushIosOverride) {
364
- signals.push('codePushDetected');
365
- }
366
- return {
367
- rnVersion: null,
368
- androidLanguage,
369
- iosLanguage,
370
- signals,
371
- existingBundleDrop: hasBundleDropResolverCall(codeContent),
372
- };
373
- };
374
181
  const readAuthToken = () => {
375
182
  const authPath = path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
376
183
  if (!fs_extra_1.default.existsSync(authPath)) {
377
- throw new Error('Not authenticated. Please run `bundle-drop login` before `bundle-drop init-native`.');
184
+ throw new Error('Not authenticated. Please run `bundle-drop login` before `bundle-drop init`.');
378
185
  }
379
186
  try {
380
187
  const parsed = readJsonFile(authPath);
@@ -387,41 +194,6 @@ const readAuthToken = () => {
387
194
  throw new Error('Failed to read CLI auth session. Please run `bundle-drop login` again.');
388
195
  }
389
196
  };
390
- function scanProjectForAiNativeInit(startDir = process.cwd()) {
391
- const projectRoot = findProjectRoot(startDir);
392
- const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
393
- if (!fs_extra_1.default.existsSync(configPath)) {
394
- throw new Error('bundle.drop.config.js not found; run `bundle-drop init` first.');
395
- }
396
- const config = loadBundleDropConfig(configPath);
397
- const serverUrl = typeof config.serverUrl === 'string' ? normalizeServerUrl(config.serverUrl) : '';
398
- const orgSlug = typeof config.org?.slug === 'string' ? config.org.slug.trim() : '';
399
- const projectSlug = typeof config.project?.slug === 'string' ? config.project.slug.trim() : '';
400
- if (!serverUrl || !orgSlug || !projectSlug) {
401
- throw new Error('Missing "serverUrl", "org.slug" or "project.slug" in bundle.drop.config.js.');
402
- }
403
- if (!(0, exports.isTrustedAiPlanningServer)(serverUrl)) {
404
- throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}. ` +
405
- 'Use the Bundle Drop production server, a local development server, or explicitly allow an untrusted server.');
406
- }
407
- const files = collectFiles(projectRoot);
408
- const detected = detectSignals(files);
409
- detected.rnVersion = detectRnVersion(projectRoot);
410
- return {
411
- projectRoot,
412
- serverUrl,
413
- orgSlug,
414
- projectSlug,
415
- authToken: readAuthToken(),
416
- request: {
417
- schemaVersion: 1,
418
- orgSlug,
419
- projectSlug,
420
- detected,
421
- files,
422
- },
423
- };
424
- }
425
197
  const SETUP_CONFIG_FILES = [
426
198
  'bundle.drop.config.js',
427
199
  'bundle.drop.config.cjs',
@@ -519,12 +291,18 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
519
291
  const expoVersion = dependencies.expo || null;
520
292
  const hasBundleDropDependency = Boolean(dependencies['@gfean/react-native-bundle-drop'] || dependencies['react-native-bundle-drop']);
521
293
  const hasBundleDropConfig = files.some(file => file.kind === 'bundle_drop_config');
522
- const hasBundleDropIntegration = content.includes('@gfean/react-native-bundle-drop') ||
523
- content.includes('bundle-drop-config') ||
524
- hasBundleDropResolverCall(content);
525
294
  const evaluatedExpoConfig = projectType === 'expo'
526
295
  ? (0, expo_1.evaluateExpoConfig)(projectRoot).exp
527
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;
528
306
  const expoUpdatesOwnership = (0, expo_1.inspectExpoUpdatesOwnership)(projectRoot, evaluatedExpoConfig);
529
307
  const configuredEngine = /(?:["']jsEngine["']|\bjsEngine)\s*:\s*["']jsc["']/.test(content)
530
308
  ? 'jsc'
@@ -540,6 +318,7 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
540
318
  : '',
541
319
  dependencies['react-native-code-push'] ? 'codePushDependency' : '',
542
320
  pkg.main === 'expo-router/entry' || dependencies['expo-router'] ? 'expoRouter' : '',
321
+ hasBundleDropExpoPlugin ? 'expoBundleDropPlugin' : '',
543
322
  ].filter(Boolean);
544
323
  const detected = {
545
324
  rnVersion: resolveInstalledPackageVersion(projectRoot, 'react-native') ||
@@ -549,9 +328,7 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
549
328
  : null,
550
329
  bundleDropStatus: hasBundleDropDependency && hasBundleDropConfig && hasBundleDropIntegration
551
330
  ? 'configured'
552
- : hasBundleDropDependency || hasBundleDropConfig || hasBundleDropIntegration
553
- ? 'partial'
554
- : 'absent',
331
+ : 'partial',
555
332
  hasNativeDirectories: fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ||
556
333
  fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')),
557
334
  usesExpoRouter: Boolean(pkg.main === 'expo-router/entry' || dependencies['expo-router']),