@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.
- package/BundleDropExpo.podspec +21 -0
- package/README.md +250 -124
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +33 -3
- package/app.plugin.js +3 -0
- package/expo/android/build.gradle +159 -0
- package/expo/android/src/main/AndroidManifest.xml +1 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoConfiguration.kt +35 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoIdentityModule.kt +30 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoPackage.kt +29 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoReactNativeHostHandler.kt +16 -0
- package/expo/bundle-drop-expo-gradle-plugin/build.gradle +31 -0
- package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/BundleDropExpoPlugin.groovy +83 -0
- package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/GenerateBundleDropBuildIdentityTask.groovy +57 -0
- package/expo/ios/Sources/BundleDropExpoIdentity.m +31 -0
- package/expo/ios/Sources/BundleDropExpoReactDelegateHandler.swift +24 -0
- package/expo-module.config.json +19 -0
- package/ios/BundleDropLocator.swift +7 -1
- package/lib/CLI/cli.d.ts +1 -2
- package/lib/CLI/cli.js +151 -56
- package/lib/CLI/logo.js +1 -1
- package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
- package/lib/CLI/scripts/aipowered/{apply-plan.js → apply-setup-plan.js} +24 -19
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +4 -4
- package/lib/CLI/scripts/aipowered/backend-client.js +7 -7
- package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
- package/lib/CLI/scripts/aipowered/init-project-config.js +418 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -3
- package/lib/CLI/scripts/aipowered/scanner.js +225 -201
- package/lib/CLI/scripts/aipowered/types.d.ts +37 -33
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +9 -2
- package/lib/CLI/scripts/aipowered/validate-plan.js +70 -119
- package/lib/CLI/scripts/bare-metro-config.d.ts +7 -0
- package/lib/CLI/scripts/{init-metro-config.js → bare-metro-config.js} +16 -30
- package/lib/CLI/scripts/doctor.d.ts +17 -0
- package/lib/CLI/scripts/doctor.js +410 -0
- package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
- package/lib/CLI/scripts/expo/build-receipt.js +223 -0
- package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
- package/lib/CLI/scripts/expo/configure-expo.js +268 -0
- package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
- package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
- package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
- package/lib/CLI/scripts/expo/package-manager.js +84 -0
- package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
- package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
- package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
- package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
- package/lib/CLI/scripts/init-config.d.ts +18 -1
- package/lib/CLI/scripts/init-config.js +29 -8
- package/lib/CLI/scripts/login-cli.js +21 -3
- package/lib/CLI/scripts/native-setup-contract.d.ts +7 -0
- package/lib/CLI/scripts/native-setup-contract.js +101 -0
- package/lib/CLI/scripts/post-init.d.ts +6 -1
- package/lib/CLI/scripts/post-init.js +6 -33
- package/lib/CLI/scripts/upload-cli.d.ts +1 -0
- package/lib/CLI/scripts/upload-cli.js +106 -36
- package/lib/context.d.ts +0 -2
- package/lib/context.js +18 -2
- package/lib/expo/buildIdentity.d.ts +15 -0
- package/lib/expo/buildIdentity.js +201 -0
- package/lib/expo/buildReceipt.d.ts +42 -0
- package/lib/expo/buildReceipt.js +272 -0
- package/lib/expo/config.d.ts +7 -0
- package/lib/expo/config.js +43 -0
- package/lib/expo/configCache.d.ts +1 -0
- package/lib/expo/configCache.js +20 -0
- package/lib/expo/errors.d.ts +6 -0
- package/lib/expo/errors.js +11 -0
- package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
- package/lib/expo/expoUpdatesOwnership.js +22 -0
- package/lib/expo/exportExpoProject.d.ts +21 -0
- package/lib/expo/exportExpoProject.js +125 -0
- package/lib/expo/exportValidation.d.ts +11 -0
- package/lib/expo/exportValidation.js +115 -0
- package/lib/expo/index.d.ts +18 -0
- package/lib/expo/index.js +25 -0
- package/lib/expo/localModules.d.ts +4 -0
- package/lib/expo/localModules.js +51 -0
- package/lib/expo/nativeIdentity.d.ts +1 -0
- package/lib/expo/nativeIdentity.js +17 -0
- package/lib/expo/projectType.d.ts +7 -0
- package/lib/expo/projectType.js +200 -0
- package/lib/expo/runtimeVersion.d.ts +13 -0
- package/lib/expo/runtimeVersion.js +45 -0
- package/lib/expo/types.d.ts +15 -0
- package/lib/expo/types.js +2 -0
- package/lib/fs/userProperties.d.ts +0 -2
- package/lib/fs/userProperties.js +0 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -2
- package/lib/loadConfig.d.ts +15 -7
- package/lib/loadConfig.js +2 -19
- package/lib/metro.d.ts +17 -0
- package/lib/metro.js +57 -0
- package/lib/native/bundleDropNative.d.ts +2 -0
- package/lib/native/bundleDropNative.js +9 -1
- package/lib/runtime/service.js +12 -1
- package/lib/scripts/bundle.d.ts +2 -2
- package/lib/scripts/bundle.js +10 -97
- package/lib/scripts/canonicalArtifact.d.ts +30 -0
- package/lib/scripts/canonicalArtifact.js +212 -0
- package/lib/scripts/exportProject.d.ts +41 -0
- package/lib/scripts/exportProject.js +82 -0
- package/package.json +51 -46
- package/plugin/constants.js +9 -0
- package/plugin/expoUpdates.js +131 -0
- package/plugin/index.js +11 -0
- package/plugin/markers.js +31 -0
- package/plugin/withBundleDrop.js +36 -0
- package/plugin/xcodeBuildPhase.js +77 -0
- package/react-native.config.js +15 -0
- package/lib/CLI/scripts/aipowered/apply-plan.d.ts +0 -10
- package/lib/CLI/scripts/aipowered/init-native-config.d.ts +0 -2
- package/lib/CLI/scripts/aipowered/init-native-config.js +0 -131
- package/lib/CLI/scripts/init-metro-config.d.ts +0 -2
|
@@ -0,0 +1,418 @@
|
|
|
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.initProjectConfigAi = initProjectConfigAi;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const expo_1 = require("../../../expo");
|
|
14
|
+
const bare_metro_config_1 = require("../bare-metro-config");
|
|
15
|
+
const doctor_1 = require("../doctor");
|
|
16
|
+
const configure_expo_1 = require("../expo/configure-expo");
|
|
17
|
+
const package_manager_1 = require("../expo/package-manager");
|
|
18
|
+
const apply_setup_plan_1 = require("./apply-setup-plan");
|
|
19
|
+
const backend_client_1 = require("./backend-client");
|
|
20
|
+
const diff_preview_1 = require("./diff-preview");
|
|
21
|
+
const scanner_1 = require("./scanner");
|
|
22
|
+
const validate_plan_1 = require("./validate-plan");
|
|
23
|
+
const ui_1 = require("../../utils/ui");
|
|
24
|
+
const PACKAGE_NAME = '@gfean/react-native-bundle-drop';
|
|
25
|
+
const EXPO_RUNTIME_AUTHORITY_PATTERN = /runtimeVersion\s*:\s*\{\s*source\s*:\s*['"]expo['"]\s*\}/;
|
|
26
|
+
const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
27
|
+
const shouldApplyAiChange = (change) => change.confidence !== 'low' &&
|
|
28
|
+
(change.decisionType === 'safe_auto_patch' || change.decisionType === 'review_only_patch');
|
|
29
|
+
const hasCleanGitStatus = (projectRoot, command) => {
|
|
30
|
+
try {
|
|
31
|
+
const status = (0, child_process_1.execSync)(command, {
|
|
32
|
+
cwd: projectRoot,
|
|
33
|
+
encoding: 'utf8',
|
|
34
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
35
|
+
});
|
|
36
|
+
return status.trim() === '';
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const usesStrictExpoRuntimeAuthority = (projectRoot, virtualConfig) => {
|
|
43
|
+
const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
|
|
44
|
+
const configContent = fs_extra_1.default.existsSync(configPath)
|
|
45
|
+
? fs_extra_1.default.readFileSync(configPath, 'utf8')
|
|
46
|
+
: virtualConfig?.content;
|
|
47
|
+
return Boolean(configContent && EXPO_RUNTIME_AUTHORITY_PATTERN.test(configContent));
|
|
48
|
+
};
|
|
49
|
+
const hasCleanGitWorktree = (projectRoot) => hasCleanGitStatus(projectRoot, 'git status --porcelain');
|
|
50
|
+
const restoreNativePrebuild = (backup, reason) => {
|
|
51
|
+
for (const directory of ['ios', 'android']) {
|
|
52
|
+
const current = path_1.default.join(backup.projectRoot, directory);
|
|
53
|
+
const failed = path_1.default.join(backup.backupDir, reason, directory);
|
|
54
|
+
if (fs_extra_1.default.existsSync(current)) {
|
|
55
|
+
fs_extra_1.default.ensureDirSync(path_1.default.dirname(failed));
|
|
56
|
+
fs_extra_1.default.moveSync(current, failed, { overwrite: true });
|
|
57
|
+
}
|
|
58
|
+
if (backup.existingDirectories.includes(directory)) {
|
|
59
|
+
fs_extra_1.default.copySync(path_1.default.join(backup.backupDir, directory), current, { preserveTimestamps: true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const runLayeredPrebuild = (projectRoot) => {
|
|
64
|
+
const expoCli = require.resolve('expo/bin/cli', { paths: [projectRoot] });
|
|
65
|
+
const backupDir = path_1.default.join(projectRoot, '.bundledrop-backup', `prebuild-${new Date().toISOString().replace(/[:.]/g, '-')}`);
|
|
66
|
+
const existingDirectories = ['ios', 'android'].filter(directory => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, directory)));
|
|
67
|
+
const backup = { projectRoot, backupDir, existingDirectories };
|
|
68
|
+
for (const directory of existingDirectories) {
|
|
69
|
+
fs_extra_1.default.copySync(path_1.default.join(projectRoot, directory), path_1.default.join(backupDir, directory), {
|
|
70
|
+
preserveTimestamps: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
(0, child_process_1.execFileSync)(process.execPath, [expoCli, 'prebuild', '--no-install'], {
|
|
75
|
+
cwd: projectRoot,
|
|
76
|
+
stdio: 'inherit',
|
|
77
|
+
env: { ...process.env, BUNDLE_DROP_PREBUILD: '1' },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
restoreNativePrebuild(backup, 'failed-generated');
|
|
82
|
+
throw new Error(`Expo prebuild failed. Original native directories were restored; failed output is in ${backupDir}. ` +
|
|
83
|
+
`${error.message}`);
|
|
84
|
+
}
|
|
85
|
+
return backup;
|
|
86
|
+
};
|
|
87
|
+
const hasBundleDropPlugin = (exp) => {
|
|
88
|
+
const plugins = (exp.plugins || []).map((plugin) => typeof plugin === 'string' ? plugin : Array.isArray(plugin) ? plugin[0] : null);
|
|
89
|
+
return plugins.includes(PACKAGE_NAME);
|
|
90
|
+
};
|
|
91
|
+
const assertBundleDropPluginPresent = (projectRoot) => {
|
|
92
|
+
if (!hasBundleDropPlugin((0, expo_1.evaluateExpoConfig)(projectRoot).exp)) {
|
|
93
|
+
throw new Error('Evaluated Expo config does not include the Bundle Drop plugin. ' +
|
|
94
|
+
'For dynamic config, keep the AI-proposed app.config patch and try again.');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const isSummarizedSetupContext = (kind) => kind === 'package_manifest' || kind === 'bundle_drop_config';
|
|
98
|
+
const authoritativeDynamicExpoConfigFile = (projectRoot, candidate = (0, expo_1.evaluateExpoConfig)(projectRoot).dynamicConfigPath) => {
|
|
99
|
+
if (typeof candidate !== 'string' || !candidate.trim()) {
|
|
100
|
+
throw new Error('Expo did not identify the authoritative dynamic app config path. No files changed.');
|
|
101
|
+
}
|
|
102
|
+
const absolutePath = path_1.default.isAbsolute(candidate) ? candidate : path_1.default.resolve(projectRoot, candidate);
|
|
103
|
+
const relativePath = path_1.default.relative(projectRoot, absolutePath).split(path_1.default.sep).join('/');
|
|
104
|
+
if (relativePath.startsWith('../') ||
|
|
105
|
+
path_1.default.isAbsolute(relativePath) ||
|
|
106
|
+
!/^app\.config\.(js|ts|cjs|mjs)$/.test(relativePath)) {
|
|
107
|
+
throw new Error(`Expo reported an unsafe dynamic app config path: ${candidate}. No files changed.`);
|
|
108
|
+
}
|
|
109
|
+
return relativePath;
|
|
110
|
+
};
|
|
111
|
+
const describeAiDestination = (serverUrl) => {
|
|
112
|
+
const parsed = new URL(serverUrl);
|
|
113
|
+
const isLocal = ['localhost', '127.0.0.1', '::1', '[::1]', '10.0.2.2'].includes(parsed.hostname);
|
|
114
|
+
const destinationType = isLocal
|
|
115
|
+
? 'local development AI server'
|
|
116
|
+
: (0, scanner_1.isBundleDropHostedAiPlanningServer)(parsed.origin)
|
|
117
|
+
? 'external Bundle Drop AI service'
|
|
118
|
+
: 'external AI planning server';
|
|
119
|
+
return `${parsed.origin} (${destinationType})`;
|
|
120
|
+
};
|
|
121
|
+
async function requestContextConsent(files, serverUrl, yes) {
|
|
122
|
+
console.log(chalk_1.default.gray(`AI setup destination: ${describeAiDestination(serverUrl)}`));
|
|
123
|
+
console.log(chalk_1.default.gray('Files proposed for AI setup planning:'));
|
|
124
|
+
files.forEach(file => {
|
|
125
|
+
const disclosure = isSummarizedSetupContext(file.kind) ? 'summary only' : 'full content';
|
|
126
|
+
console.log(chalk_1.default.gray(` - ${file.path} (${file.kind}, ${disclosure})`));
|
|
127
|
+
});
|
|
128
|
+
if (yes)
|
|
129
|
+
return true;
|
|
130
|
+
const answer = await (0, prompts_1.default)({
|
|
131
|
+
type: 'confirm',
|
|
132
|
+
name: 'send',
|
|
133
|
+
message: 'Share the listed full-content and summarized context with this AI destination?',
|
|
134
|
+
initial: true,
|
|
135
|
+
});
|
|
136
|
+
return Boolean(answer.send);
|
|
137
|
+
}
|
|
138
|
+
const assertSetupOwnershipCompatible = (projectType, expoUpdatesStatus) => {
|
|
139
|
+
if (projectType !== 'bare' || expoUpdatesStatus !== 'active')
|
|
140
|
+
return;
|
|
141
|
+
throw new Error('Active expo-updates was detected in this bare React Native project. ' +
|
|
142
|
+
'Bundle Drop cannot safely choose the native startup authority. Remove or explicitly disable ' +
|
|
143
|
+
'expo-updates, create a new native binary, and retry. No context was shared and no files were changed.');
|
|
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
|
+
};
|
|
158
|
+
async function initProjectConfigAi(options = {}) {
|
|
159
|
+
const projectRoot = (0, scanner_1.findProjectRoot)(process.cwd());
|
|
160
|
+
const projectType = (0, expo_1.detectProjectType)({ projectRoot, explicitType: options.projectType });
|
|
161
|
+
const scan = (0, scanner_1.scanProjectForAiSetup)(projectType, projectRoot, options.virtualConfig);
|
|
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
|
+
}
|
|
168
|
+
console.log(chalk_1.default.cyan(`🧠 Bundle Drop AI setup (${projectType})`));
|
|
169
|
+
if (!(await requestContextConsent(scan.request.files, scan.serverUrl, options.yes))) {
|
|
170
|
+
console.log(chalk_1.default.gray('No context sent. No files changed.'));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const loading = (0, ui_1.startLoadingStatus)('Requesting typed AI setup plan');
|
|
174
|
+
let plan;
|
|
175
|
+
try {
|
|
176
|
+
plan = await (0, backend_client_1.requestAiSetupPlan)({
|
|
177
|
+
serverUrl: scan.serverUrl,
|
|
178
|
+
authToken: scan.authToken,
|
|
179
|
+
request: scan.request,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
loading.stop();
|
|
184
|
+
}
|
|
185
|
+
console.log(chalk_1.default.cyan('\nSetup summary:'));
|
|
186
|
+
console.log(plan.summary);
|
|
187
|
+
plan.warnings.forEach(warning => console.log(chalk_1.default.yellow(`⚠️ ${warning}`)));
|
|
188
|
+
plan.actions.forEach(action => {
|
|
189
|
+
const confirmation = action.requiresConfirmation ? ' (confirmation required)' : '';
|
|
190
|
+
console.log(chalk_1.default.gray(` - ${action.type}${confirmation}: ${action.reason}`));
|
|
191
|
+
});
|
|
192
|
+
if (plan.confidence === 'low') {
|
|
193
|
+
console.log(chalk_1.default.yellow('AI confidence is low. No files changed.'));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (projectType === 'expo' && scan.request.detected.expoUpdatesStatus === 'active') {
|
|
197
|
+
if (!options.migrateExpoUpdates && !options.yes) {
|
|
198
|
+
const migrationAnswer = await (0, prompts_1.default)({
|
|
199
|
+
type: 'confirm',
|
|
200
|
+
name: 'migrate',
|
|
201
|
+
message: 'Remove active expo-updates and require a new native binary?',
|
|
202
|
+
initial: false,
|
|
203
|
+
});
|
|
204
|
+
options.migrateExpoUpdates = Boolean(migrationAnswer.migrate);
|
|
205
|
+
}
|
|
206
|
+
if (!options.migrateExpoUpdates) {
|
|
207
|
+
throw new Error('Active expo-updates blocks Bundle Drop setup. Re-run with --migrate-expo-updates ' +
|
|
208
|
+
'after reviewing the plan; a new native binary will be required.');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const action of plan.actions.filter(action => action.requiresConfirmation && action.type !== 'migrate_expo_updates')) {
|
|
212
|
+
if (options.yes)
|
|
213
|
+
continue;
|
|
214
|
+
const actionAnswer = await (0, prompts_1.default)({
|
|
215
|
+
type: 'confirm',
|
|
216
|
+
name: 'proceed',
|
|
217
|
+
message: `Proceed with ${action.type}? ${action.reason}`,
|
|
218
|
+
initial: false,
|
|
219
|
+
});
|
|
220
|
+
if (!actionAnswer.proceed) {
|
|
221
|
+
console.log(chalk_1.default.gray('Required setup action declined. No files changed.'));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const aiChanges = plan.changes.filter(shouldApplyAiChange);
|
|
226
|
+
const originals = new Map(scan.request.files.map(file => [file.path, file.content]));
|
|
227
|
+
(0, validate_plan_1.validateSetupChangesBeforeApply)({ projectType, originals, changes: aiChanges });
|
|
228
|
+
if (projectType === 'bare') {
|
|
229
|
+
const metroChange = (0, bare_metro_config_1.planBareMetroConfig)(projectRoot);
|
|
230
|
+
const bundleConfigPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
|
|
231
|
+
const bundleConfigExists = fs_extra_1.default.existsSync(bundleConfigPath);
|
|
232
|
+
const bundleConfig = bundleConfigExists
|
|
233
|
+
? fs_extra_1.default.readFileSync(bundleConfigPath, 'utf8')
|
|
234
|
+
: options.virtualConfig?.content;
|
|
235
|
+
const updatedBundleConfig = bundleConfig
|
|
236
|
+
? (0, configure_expo_1.setBundleDropProjectType)(bundleConfig, 'bare')
|
|
237
|
+
: null;
|
|
238
|
+
const bundleConfigChange = updatedBundleConfig &&
|
|
239
|
+
(!bundleConfigExists || updatedBundleConfig !== bundleConfig)
|
|
240
|
+
? {
|
|
241
|
+
file: 'bundle.drop.config.js',
|
|
242
|
+
original: bundleConfigExists ? bundleConfig : null,
|
|
243
|
+
updated: updatedBundleConfig,
|
|
244
|
+
reason: 'Persist the reviewed bare React Native project type.',
|
|
245
|
+
}
|
|
246
|
+
: null;
|
|
247
|
+
const localChanges = [metroChange, bundleConfigChange].filter((change) => Boolean(change));
|
|
248
|
+
if (!aiChanges.length && !localChanges.length) {
|
|
249
|
+
console.log(chalk_1.default.gray('No bare native changes are required.'));
|
|
250
|
+
if (!options.dryRun)
|
|
251
|
+
await (0, doctor_1.runDoctor)({ projectType: 'bare', cwd: projectRoot });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const bareOriginals = new Map(originals);
|
|
255
|
+
const previewChanges = [...aiChanges];
|
|
256
|
+
for (const localChange of localChanges) {
|
|
257
|
+
bareOriginals.set(localChange.file, localChange.original || '');
|
|
258
|
+
previewChanges.push({
|
|
259
|
+
file: localChange.file,
|
|
260
|
+
originalSha256: sha256(localChange.original || ''),
|
|
261
|
+
updated: localChange.updated,
|
|
262
|
+
reason: localChange.reason,
|
|
263
|
+
confidence: 'high',
|
|
264
|
+
decisionType: 'safe_auto_patch',
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
console.log(chalk_1.default.cyan('\nProposed changes:'));
|
|
268
|
+
console.log((0, diff_preview_1.colorizeUnifiedDiff)((0, diff_preview_1.buildUnifiedDiff)({
|
|
269
|
+
projectRoot,
|
|
270
|
+
originals: bareOriginals,
|
|
271
|
+
changes: previewChanges,
|
|
272
|
+
})));
|
|
273
|
+
if (options.dryRun) {
|
|
274
|
+
console.log(chalk_1.default.gray('Dry run complete. No files changed.'));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const answer = options.yes ? { apply: true } : await (0, prompts_1.default)({
|
|
278
|
+
type: 'confirm', name: 'apply', message: 'Apply these setup changes?', initial: true,
|
|
279
|
+
});
|
|
280
|
+
if (!answer.apply) {
|
|
281
|
+
console.log(chalk_1.default.gray('No files changed.'));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const result = (0, apply_setup_plan_1.applySetupPatchPlans)({ projectRoot, projectType, changes: aiChanges });
|
|
285
|
+
let metroResult;
|
|
286
|
+
try {
|
|
287
|
+
(0, validate_plan_1.validateAppliedSetupChanges)({ projectRoot, projectType, changes: aiChanges });
|
|
288
|
+
if (localChanges.length) {
|
|
289
|
+
metroResult = (0, configure_expo_1.applyExpoConfigurationChanges)({
|
|
290
|
+
projectRoot,
|
|
291
|
+
changes: localChanges,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
await (0, doctor_1.runDoctor)({ projectType: 'bare', cwd: projectRoot });
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
if (metroResult)
|
|
298
|
+
(0, configure_expo_1.restoreExpoConfiguration)(metroResult);
|
|
299
|
+
(0, apply_setup_plan_1.restoreSetupBackups)(result);
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
console.log(chalk_1.default.green(`✅ Bare React Native setup complete. Backups: ${result.backupDir}`));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const hasNativeDirectories = scan.request.detected.hasNativeDirectories;
|
|
306
|
+
const usesStrictRuntimeAuthority = usesStrictExpoRuntimeAuthority(projectRoot, options.virtualConfig);
|
|
307
|
+
if (hasNativeDirectories && usesStrictRuntimeAuthority && !hasCleanGitWorktree(projectRoot)) {
|
|
308
|
+
throw new Error('Strict Expo runtime authority requires a clean Git worktree before layered native prebuild.');
|
|
309
|
+
}
|
|
310
|
+
const deterministic = (0, configure_expo_1.planExpoProjectConfiguration)({
|
|
311
|
+
projectRoot,
|
|
312
|
+
migrateExpoUpdates: Boolean(options.migrateExpoUpdates),
|
|
313
|
+
bundleConfigContent: options.virtualConfig?.content,
|
|
314
|
+
});
|
|
315
|
+
const deterministicPaths = new Set(deterministic.map(change => change.file));
|
|
316
|
+
const unusualAiChanges = aiChanges.filter(change => !deterministicPaths.has(change.file));
|
|
317
|
+
if ((0, configure_expo_1.hasDynamicExpoConfig)(projectRoot)) {
|
|
318
|
+
const evaluatedConfig = (0, expo_1.evaluateExpoConfig)(projectRoot);
|
|
319
|
+
const dynamicConfigFile = authoritativeDynamicExpoConfigFile(projectRoot, evaluatedConfig.dynamicConfigPath);
|
|
320
|
+
if (!hasBundleDropPlugin(evaluatedConfig.exp) &&
|
|
321
|
+
!unusualAiChanges.some(change => change.file === dynamicConfigFile)) {
|
|
322
|
+
throw new Error(`Dynamic Expo config requires an allowlisted AI patch for its evaluated root config ` +
|
|
323
|
+
`(${dynamicConfigFile}); no safe patch was proposed.`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const combinedChanges = [
|
|
327
|
+
...deterministic,
|
|
328
|
+
...unusualAiChanges.map(change => ({
|
|
329
|
+
file: change.file,
|
|
330
|
+
original: originals.get(change.file) ?? null,
|
|
331
|
+
updated: change.updated,
|
|
332
|
+
reason: change.reason,
|
|
333
|
+
})),
|
|
334
|
+
];
|
|
335
|
+
const combinedOriginals = new Map(combinedChanges.map(change => [change.file, change.original || '']));
|
|
336
|
+
const combinedPatchPlans = combinedChanges.map(change => ({
|
|
337
|
+
file: change.file,
|
|
338
|
+
originalSha256: sha256(change.original || ''),
|
|
339
|
+
updated: change.updated,
|
|
340
|
+
reason: change.reason,
|
|
341
|
+
confidence: 'high',
|
|
342
|
+
decisionType: 'safe_auto_patch',
|
|
343
|
+
}));
|
|
344
|
+
console.log(chalk_1.default.cyan('\nProposed changes:'));
|
|
345
|
+
console.log((0, diff_preview_1.colorizeUnifiedDiff)((0, diff_preview_1.buildUnifiedDiff)({
|
|
346
|
+
projectRoot,
|
|
347
|
+
originals: combinedOriginals,
|
|
348
|
+
changes: combinedPatchPlans,
|
|
349
|
+
})));
|
|
350
|
+
if (options.migrateExpoUpdates) {
|
|
351
|
+
const command = (0, package_manager_1.expoUpdatesRemovalCommand)((0, package_manager_1.detectPackageManager)(projectRoot));
|
|
352
|
+
console.log(chalk_1.default.yellow(`Dependency migration command: ${command.join(' ')}`));
|
|
353
|
+
}
|
|
354
|
+
if (hasNativeDirectories) {
|
|
355
|
+
console.log(chalk_1.default.yellow(`Layered prebuild command: ${process.execPath} <project-local expo> prebuild --no-install`));
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
console.log(chalk_1.default.gray('Managed/CNG project: native directories will remain absent.'));
|
|
359
|
+
}
|
|
360
|
+
if (options.dryRun) {
|
|
361
|
+
console.log(chalk_1.default.gray('Dry run complete. No files changed.'));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const applyAnswer = options.yes ? { apply: true } : await (0, prompts_1.default)({
|
|
365
|
+
type: 'confirm', name: 'apply', message: 'Apply the complete Expo setup plan?', initial: true,
|
|
366
|
+
});
|
|
367
|
+
if (!applyAnswer.apply) {
|
|
368
|
+
console.log(chalk_1.default.gray('No files changed.'));
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (hasNativeDirectories && !options.prebuild) {
|
|
372
|
+
const prebuildAnswer = options.yes ? { prebuild: false } : await (0, prompts_1.default)({
|
|
373
|
+
type: 'confirm',
|
|
374
|
+
name: 'prebuild',
|
|
375
|
+
message: 'Run the previewed layered Expo prebuild after applying configuration?',
|
|
376
|
+
initial: true,
|
|
377
|
+
});
|
|
378
|
+
if (!prebuildAnswer.prebuild) {
|
|
379
|
+
console.log(chalk_1.default.gray('Prebuild declined. No files changed.'));
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
options.prebuild = true;
|
|
383
|
+
}
|
|
384
|
+
let dependencyBackup;
|
|
385
|
+
let applyResult;
|
|
386
|
+
let prebuildBackup;
|
|
387
|
+
try {
|
|
388
|
+
if (options.migrateExpoUpdates) {
|
|
389
|
+
dependencyBackup = (0, package_manager_1.removeExpoUpdatesWithPackageManager)(projectRoot);
|
|
390
|
+
}
|
|
391
|
+
applyResult = (0, configure_expo_1.applyExpoConfigurationChanges)({
|
|
392
|
+
projectRoot,
|
|
393
|
+
changes: combinedChanges.filter(change => change.file !== 'package.json'),
|
|
394
|
+
});
|
|
395
|
+
assertBundleDropPluginPresent(projectRoot);
|
|
396
|
+
if (hasNativeDirectories && options.prebuild) {
|
|
397
|
+
prebuildBackup = runLayeredPrebuild(projectRoot);
|
|
398
|
+
console.log(chalk_1.default.gray(`Native prebuild backup: ${prebuildBackup.backupDir}`));
|
|
399
|
+
}
|
|
400
|
+
await (0, doctor_1.runDoctor)({ projectType: 'expo', cwd: projectRoot });
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (prebuildBackup)
|
|
404
|
+
restoreNativePrebuild(prebuildBackup, 'failed-validation');
|
|
405
|
+
if (applyResult)
|
|
406
|
+
(0, configure_expo_1.restoreExpoConfiguration)(applyResult);
|
|
407
|
+
if (dependencyBackup) {
|
|
408
|
+
(0, package_manager_1.restoreDependencyMigration)(dependencyBackup);
|
|
409
|
+
console.log(chalk_1.default.yellow('Package files were restored; reinstall dependencies to repair node_modules.'));
|
|
410
|
+
}
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
console.log(chalk_1.default.green(`✅ Expo setup complete. Backups: ${applyResult.backupDir}`));
|
|
414
|
+
if (!hasNativeDirectories) {
|
|
415
|
+
console.log(chalk_1.default.gray('Run expo run:*, explicit prebuild/manual build, or EAS Build to generate native integration.'));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
exports.default = initProjectConfigAi;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { AiSetupProjectType, AiSetupScannerResult } from './types';
|
|
2
|
+
export declare const findCredentialLikeLiteral: (content: string) => string | null;
|
|
3
3
|
export declare const isTrustedAiPlanningServer: (serverUrl: string) => boolean;
|
|
4
|
+
export declare const isBundleDropHostedAiPlanningServer: (serverUrl: string) => boolean;
|
|
4
5
|
export declare function findProjectRoot(startDir?: string): string;
|
|
5
|
-
export declare function
|
|
6
|
+
export declare function scanProjectForAiSetup(projectType: AiSetupProjectType, startDir?: string, virtualConfig?: {
|
|
7
|
+
content: string;
|
|
8
|
+
serverUrl: string;
|
|
9
|
+
orgSlug: string;
|
|
10
|
+
projectSlug: string;
|
|
11
|
+
authToken: string;
|
|
12
|
+
}): AiSetupScannerResult;
|