@gfean/react-native-bundle-drop 0.12.1 → 0.13.0
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 +1 -1
- package/lib/CLI/cli.js +9 -2
- package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +2 -0
- package/lib/CLI/scripts/aipowered/apply-setup-plan.js +6 -3
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -4
- package/lib/CLI/scripts/aipowered/backend-client.js +5 -1
- package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +1 -1
- package/lib/CLI/scripts/aipowered/code-push-residue.js +11 -5
- package/lib/CLI/scripts/aipowered/init-project-config.js +47 -36
- package/lib/CLI/scripts/aipowered/native-setup-context.d.ts +20 -0
- package/lib/CLI/scripts/aipowered/native-setup-context.js +242 -0
- package/lib/CLI/scripts/aipowered/native-setup-metadata.d.ts +16 -0
- package/lib/CLI/scripts/aipowered/native-setup-metadata.js +104 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +7 -3
- package/lib/CLI/scripts/aipowered/scanner.js +96 -30
- package/lib/CLI/scripts/aipowered/setup-v2.d.ts +3 -0
- package/lib/CLI/scripts/aipowered/setup-v2.js +53 -0
- package/lib/CLI/scripts/aipowered/types.d.ts +11 -1
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -1
- package/lib/CLI/scripts/aipowered/validate-plan.js +10 -4
- package/lib/CLI/scripts/doctor.js +18 -6
- package/lib/CLI/scripts/expo/eas-build-proof.js +8 -2
- package/lib/CLI/scripts/expo/package-manager.d.ts +1 -0
- package/lib/CLI/scripts/expo/package-manager.js +7 -3
- package/lib/CLI/scripts/ios-scene-target.d.ts +9 -0
- package/lib/CLI/scripts/ios-scene-target.js +193 -0
- package/lib/CLI/scripts/native-entrypoint-authority.d.ts +1 -0
- package/lib/CLI/scripts/native-entrypoint-authority.js +24 -0
- package/lib/CLI/scripts/native-setup-contract.d.ts +4 -0
- package/lib/CLI/scripts/native-setup-contract.js +28 -14
- package/lib/CLI/scripts/native-startup-validator.d.ts +4 -1
- package/lib/CLI/scripts/native-startup-validator.js +83 -6
- package/lib/CLI/scripts/safe-file-transaction.d.ts +1 -1
- package/lib/CLI/scripts/safe-file-transaction.js +3 -3
- package/lib/CLI/utils/read-xml-plist.d.ts +2 -1
- package/lib/CLI/utils/read-xml-plist.js +7 -3
- package/lib/expo/buildIdentity.js +1 -1
- package/lib/injectImageResolver.js +7 -2
- package/package.json +2 -2
- package/third_party/expo-fingerprint/scheme-1-contract.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
| Requirement | Supported |
|
|
17
17
|
| --- | --- |
|
|
18
|
-
| Expo | SDK 54–
|
|
18
|
+
| Expo | SDK 54–58 |
|
|
19
19
|
| Bare React Native | 0.71+ |
|
|
20
20
|
| Platforms | iOS and Android, including legacy and New Architecture |
|
|
21
21
|
| Node.js | 20.19.4+ for package installation and CLI use |
|
package/lib/CLI/cli.js
CHANGED
|
@@ -213,6 +213,13 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
213
213
|
.option('--yes', 'Approve ordinary setup changes noninteractively')
|
|
214
214
|
.description('Configure Bundle Drop for Expo or bare React Native')
|
|
215
215
|
.action(async (options) => {
|
|
216
|
+
const setupFlags = {
|
|
217
|
+
dryRun: options.dryRun,
|
|
218
|
+
migrateCodePush: options.migrateCodePush,
|
|
219
|
+
migrateExpoUpdates: options.migrateExpoUpdates,
|
|
220
|
+
prebuild: options.prebuild,
|
|
221
|
+
yes: options.yes,
|
|
222
|
+
};
|
|
216
223
|
if (options.token) {
|
|
217
224
|
const { detectProjectType } = require('../expo');
|
|
218
225
|
const projectType = detectProjectType({
|
|
@@ -237,7 +244,7 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
237
244
|
});
|
|
238
245
|
await runSetupWithManualFallback({
|
|
239
246
|
options: {
|
|
240
|
-
...
|
|
247
|
+
...setupFlags,
|
|
241
248
|
projectType,
|
|
242
249
|
...(configResult?.bootstrapContent
|
|
243
250
|
? { runtimeDeliveryBootstrap: { content: configResult.bootstrapContent } }
|
|
@@ -302,7 +309,7 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
302
309
|
});
|
|
303
310
|
await runSetupWithManualFallback({
|
|
304
311
|
options: {
|
|
305
|
-
...
|
|
312
|
+
...setupFlags,
|
|
306
313
|
projectType,
|
|
307
314
|
...(configResult?.bootstrapContent
|
|
308
315
|
? { runtimeDeliveryBootstrap: { content: configResult.bootstrapContent } }
|
|
@@ -9,9 +9,9 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
9
9
|
const validate_plan_1 = require("./validate-plan");
|
|
10
10
|
const safe_file_transaction_1 = require("../safe-file-transaction");
|
|
11
11
|
const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
12
|
-
const isAllowedSetupFile = (projectType, filePath) => projectType === 'expo'
|
|
12
|
+
const isAllowedSetupFile = (projectType, filePath, iosSceneEntrypoint) => projectType === 'expo'
|
|
13
13
|
? (0, validate_plan_1.isPatchableExpoConfig)(filePath)
|
|
14
|
-
: (0, validate_plan_1.isPatchableNativeEntrypoint)(filePath);
|
|
14
|
+
: (0, validate_plan_1.isPatchableNativeEntrypoint)(filePath, iosSceneEntrypoint);
|
|
15
15
|
function restoreSetupBackups(result) {
|
|
16
16
|
for (const relativePath of result.changedFiles) {
|
|
17
17
|
(0, safe_file_transaction_1.restoreProjectFile)(result.projectRoot, result.backupDir, relativePath);
|
|
@@ -25,7 +25,10 @@ function applySetupPatchPlans(params) {
|
|
|
25
25
|
};
|
|
26
26
|
try {
|
|
27
27
|
for (const change of params.changes) {
|
|
28
|
-
if (!(0, validate_plan_1.isSafeRelativePath)(change.file) ||
|
|
28
|
+
if (!(0, validate_plan_1.isSafeRelativePath)(change.file) ||
|
|
29
|
+
!(params.verifiedNativePaths
|
|
30
|
+
? params.projectType === 'bare' && params.verifiedNativePaths.has(change.file)
|
|
31
|
+
: isAllowedSetupFile(params.projectType, change.file, params.iosSceneEntrypoint))) {
|
|
29
32
|
throw new Error(`Refusing to write AI setup plan outside its allowlist: ${change.file}`);
|
|
30
33
|
}
|
|
31
34
|
const target = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, change.file);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { AiSetupPlanRequest, AiSetupPlanResponse } from './types';
|
|
2
|
-
|
|
1
|
+
import { AiSetupPlanRequest, AiSetupPlanRequestV2, AiSetupPlanResponse } from './types';
|
|
2
|
+
type SetupPlanRequestOptions = {
|
|
3
3
|
serverUrl: string;
|
|
4
4
|
authToken: string;
|
|
5
|
-
request: AiSetupPlanRequest;
|
|
6
|
-
}
|
|
5
|
+
request: AiSetupPlanRequest | AiSetupPlanRequestV2;
|
|
6
|
+
};
|
|
7
|
+
export declare function requestAiSetupPlan(params: SetupPlanRequestOptions): Promise<AiSetupPlanResponse>;
|
|
8
|
+
export {};
|
|
@@ -34,17 +34,21 @@ const resolveTimeoutMs = () => {
|
|
|
34
34
|
};
|
|
35
35
|
async function requestAiSetupPlan(params) {
|
|
36
36
|
try {
|
|
37
|
-
const response = await axios_1.default.post(`${params.serverUrl}/ai/setup-plan`, params.request, {
|
|
37
|
+
const response = await axios_1.default.post(`${params.serverUrl}/ai/setup-plan${params.request.schemaVersion === 2 ? '/v2' : ''}`, params.request, {
|
|
38
38
|
headers: {
|
|
39
39
|
Accept: 'application/json',
|
|
40
40
|
Authorization: `Bearer ${params.authToken}`,
|
|
41
41
|
},
|
|
42
|
+
...(params.request.schemaVersion === 2 ? { maxRedirects: 0 } : {}),
|
|
42
43
|
timeout: resolveTimeoutMs(),
|
|
43
44
|
});
|
|
44
45
|
return response.data;
|
|
45
46
|
}
|
|
46
47
|
catch (error) {
|
|
47
48
|
const raw = error?.response?.data;
|
|
49
|
+
if (params.request.schemaVersion === 2 && error?.response?.status === 404 && !raw?.code) {
|
|
50
|
+
throw new Error('This server does not support this CLI’s native AI setup. Try a compatible Bundle Drop backend or follow manual setup.');
|
|
51
|
+
}
|
|
48
52
|
if (error?.code === 'ECONNABORTED' || /timeout/i.test(String(error?.message || ''))) {
|
|
49
53
|
throw new Error('AI setup planning timed out. Try again, or increase BUNDLE_DROP_AI_INIT_TIMEOUT_MS.');
|
|
50
54
|
}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Finds CodePush ownership outside package files and provider-patched native entrypoints.
|
|
3
3
|
* Only relative paths are returned; file contents never leave this local validation boundary.
|
|
4
4
|
*/
|
|
5
|
-
export declare function findCodePushResiduePaths(projectRoot: string): string[];
|
|
5
|
+
export declare function findCodePushResiduePaths(projectRoot: string, iosSceneEntrypoint?: string, verifiedNativePaths?: ReadonlySet<string>): string[];
|
|
@@ -29,18 +29,24 @@ const SKIPPED_DIRECTORIES = new Set([
|
|
|
29
29
|
const JS_SOURCE_EXTENSION = /\.(?:cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
30
30
|
const CODE_PUSH_REFERENCE = /\b(?:react-native-code-push|code[\s_.-]*push|com\.microsoft\.codepush\.react)/i;
|
|
31
31
|
const toPosix = (filePath) => filePath.split(path_1.default.sep).join('/');
|
|
32
|
-
const isCodePushResidueCandidate = (relativePath) => {
|
|
32
|
+
const isCodePushResidueCandidate = (relativePath, iosSceneEntrypoint, verifiedNativePaths) => {
|
|
33
33
|
const parts = relativePath.split('/');
|
|
34
34
|
const basename = parts[parts.length - 1];
|
|
35
35
|
if (JS_SOURCE_EXTENSION.test(basename))
|
|
36
36
|
return true;
|
|
37
37
|
if (parts[0] === 'android') {
|
|
38
|
-
if (
|
|
38
|
+
if (verifiedNativePaths
|
|
39
|
+
? verifiedNativePaths.has(relativePath)
|
|
40
|
+
: /^MainApplication\.(?:java|kt)$/i.test(basename))
|
|
39
41
|
return false;
|
|
40
42
|
return /\.(?:gradle|gradle\.kts|java|kt|properties|xml)$/i.test(basename);
|
|
41
43
|
}
|
|
42
44
|
if (parts[0] === 'ios') {
|
|
43
|
-
if (
|
|
45
|
+
if (verifiedNativePaths
|
|
46
|
+
? verifiedNativePaths.has(relativePath)
|
|
47
|
+
: iosSceneEntrypoint
|
|
48
|
+
? relativePath === iosSceneEntrypoint
|
|
49
|
+
: /^AppDelegate\.(?:m|mm|swift)$/i.test(basename))
|
|
44
50
|
return false;
|
|
45
51
|
return basename === 'Podfile' ||
|
|
46
52
|
/\.(?:h|m|mm|pbxproj|plist|podspec|swift|xcconfig)$/i.test(basename);
|
|
@@ -53,7 +59,7 @@ const scanLimitError = (detail) => new Error(`CodePush residue validation could
|
|
|
53
59
|
* Finds CodePush ownership outside package files and provider-patched native entrypoints.
|
|
54
60
|
* Only relative paths are returned; file contents never leave this local validation boundary.
|
|
55
61
|
*/
|
|
56
|
-
function findCodePushResiduePaths(projectRoot) {
|
|
62
|
+
function findCodePushResiduePaths(projectRoot, iosSceneEntrypoint, verifiedNativePaths) {
|
|
57
63
|
const pendingDirectories = [''];
|
|
58
64
|
const residuePaths = [];
|
|
59
65
|
let visitedEntries = 0;
|
|
@@ -98,7 +104,7 @@ function findCodePushResiduePaths(projectRoot) {
|
|
|
98
104
|
if (!stat.isFile())
|
|
99
105
|
continue;
|
|
100
106
|
const posixPath = toPosix(relativePath);
|
|
101
|
-
if (!isCodePushResidueCandidate(posixPath))
|
|
107
|
+
if (!isCodePushResidueCandidate(posixPath, iosSceneEntrypoint, verifiedNativePaths))
|
|
102
108
|
continue;
|
|
103
109
|
candidateFiles += 1;
|
|
104
110
|
if (candidateFiles > MAX_CANDIDATE_FILES) {
|
|
@@ -22,6 +22,7 @@ const diff_preview_1 = require("./diff-preview");
|
|
|
22
22
|
const terminal_safety_1 = require("./terminal-safety");
|
|
23
23
|
const scanner_1 = require("./scanner");
|
|
24
24
|
const validate_plan_1 = require("./validate-plan");
|
|
25
|
+
const setup_v2_1 = require("./setup-v2");
|
|
25
26
|
const ui_1 = require("../../utils/ui");
|
|
26
27
|
const safe_file_transaction_1 = require("../safe-file-transaction");
|
|
27
28
|
const bootstrapConfig_1 = require("../../../runtime-delivery/bootstrapConfig");
|
|
@@ -179,7 +180,8 @@ const assertBundleDropPluginPresent = (projectRoot) => {
|
|
|
179
180
|
'For dynamic config, keep the AI-proposed app.config patch and try again.');
|
|
180
181
|
}
|
|
181
182
|
};
|
|
182
|
-
const isSummarizedSetupContext = (file) => file.kind === '
|
|
183
|
+
const isSummarizedSetupContext = (file) => file.kind === 'native_support' ||
|
|
184
|
+
file.kind === 'package_manifest' ||
|
|
183
185
|
file.kind === 'bundle_drop_config' ||
|
|
184
186
|
file.kind === 'metro_config' ||
|
|
185
187
|
file.path === 'app.json';
|
|
@@ -193,14 +195,16 @@ const describeAiDestination = (serverUrl) => {
|
|
|
193
195
|
: 'external AI planning server';
|
|
194
196
|
return `${parsed.origin} (${destinationType})`;
|
|
195
197
|
};
|
|
196
|
-
async function requestContextConsent(files, serverUrl, yes) {
|
|
198
|
+
async function requestContextConsent(files, serverUrl, yes, nativeEditCandidates) {
|
|
197
199
|
console.log(chalk_1.default.gray(`AI setup destination: ${describeAiDestination(serverUrl)}`));
|
|
198
200
|
const contextSize = files.reduce((total, file) => total + Buffer.byteLength(file.content, 'utf8'), 0);
|
|
199
201
|
console.log(chalk_1.default.gray(`Provider context size: ${contextSize} bytes.`));
|
|
200
202
|
console.log(chalk_1.default.gray('Files proposed for AI setup planning:'));
|
|
201
203
|
files.forEach(file => {
|
|
202
204
|
const disclosure = isSummarizedSetupContext(file) ? 'summary only' : 'full content';
|
|
203
|
-
|
|
205
|
+
const role = file.kind === 'native_support' ? ', read-only build metadata'
|
|
206
|
+
: nativeEditCandidates?.has(file.path) ? ', potential native edit' : '';
|
|
207
|
+
console.log(chalk_1.default.gray(` - ${file.path} (${file.kind}, ${disclosure}${role})`));
|
|
204
208
|
});
|
|
205
209
|
if (yes)
|
|
206
210
|
return true;
|
|
@@ -232,8 +236,8 @@ const existingSetupPassesDoctor = async (projectRoot, projectType, detected) =>
|
|
|
232
236
|
return false;
|
|
233
237
|
}
|
|
234
238
|
};
|
|
235
|
-
const assertNoCodePushMigrationResidue = (projectRoot) => {
|
|
236
|
-
const residuePaths = (0, code_push_residue_1.findCodePushResiduePaths)(projectRoot);
|
|
239
|
+
const assertNoCodePushMigrationResidue = (projectRoot, verifiedNativePaths) => {
|
|
240
|
+
const residuePaths = (0, code_push_residue_1.findCodePushResiduePaths)(projectRoot, undefined, verifiedNativePaths);
|
|
237
241
|
if (!residuePaths.length)
|
|
238
242
|
return;
|
|
239
243
|
const displayedPaths = residuePaths.slice(0, 20).map(filePath => ` - ${filePath}`);
|
|
@@ -248,11 +252,15 @@ const assertNoCodePushMigrationResidue = (projectRoot) => {
|
|
|
248
252
|
async function initProjectConfigAi(options = {}) {
|
|
249
253
|
const projectRoot = (0, scanner_1.findProjectRoot)(process.cwd());
|
|
250
254
|
const projectType = (0, expo_1.detectProjectType)({ projectRoot, explicitType: options.projectType });
|
|
251
|
-
const
|
|
255
|
+
const nativeScan = projectType === 'bare'
|
|
256
|
+
? await (0, scanner_1.scanProjectForAiSetupV2)(projectRoot, options.virtualConfig)
|
|
257
|
+
: undefined;
|
|
258
|
+
const scan = nativeScan ?? (0, scanner_1.scanProjectForAiSetup)(projectType, projectRoot, options.virtualConfig);
|
|
252
259
|
const bootstrapChange = planRuntimeDeliveryBootstrap(projectRoot, options.runtimeDeliveryBootstrap);
|
|
253
260
|
const bootstrapGitignoreChange = planRuntimeDeliveryGitignore(projectRoot, options.runtimeDeliveryBootstrap);
|
|
254
261
|
assertSetupOwnershipCompatible(projectType, scan.request.detected.expoUpdatesStatus);
|
|
255
|
-
if (!
|
|
262
|
+
if (!nativeScan &&
|
|
263
|
+
!bootstrapChange &&
|
|
256
264
|
!bootstrapGitignoreChange &&
|
|
257
265
|
await existingSetupPassesDoctor(projectRoot, projectType, scan.request.detected)) {
|
|
258
266
|
console.log(chalk_1.default.green('✅ Bundle Drop setup is already complete. No AI planning is required.'));
|
|
@@ -261,7 +269,7 @@ async function initProjectConfigAi(options = {}) {
|
|
|
261
269
|
return;
|
|
262
270
|
}
|
|
263
271
|
console.log(chalk_1.default.cyan(`🧠 Bundle Drop AI setup (${projectType})`));
|
|
264
|
-
if (!(await requestContextConsent(scan.request.files, scan.serverUrl, options.yes))) {
|
|
272
|
+
if (!(await requestContextConsent(scan.request.files, scan.serverUrl, options.yes, nativeScan && new Set(nativeScan.request.nativeEditPaths)))) {
|
|
265
273
|
console.log(chalk_1.default.gray('No context sent. No files changed.'));
|
|
266
274
|
return;
|
|
267
275
|
}
|
|
@@ -278,6 +286,7 @@ async function initProjectConfigAi(options = {}) {
|
|
|
278
286
|
loading.stop();
|
|
279
287
|
}
|
|
280
288
|
(0, terminal_safety_1.assertSafeProviderPlan)(plan);
|
|
289
|
+
const verifiedNativePaths = nativeScan ? (0, setup_v2_1.verifyNativeSetupPlan)(nativeScan, plan) : undefined;
|
|
281
290
|
console.log(chalk_1.default.cyan('\nSetup summary:'));
|
|
282
291
|
console.log((0, terminal_safety_1.escapeTerminalControls)(plan.summary));
|
|
283
292
|
plan.warnings.forEach(warning => console.log(chalk_1.default.yellow(`⚠️ ${(0, terminal_safety_1.escapeTerminalControls)(warning)}`)));
|
|
@@ -314,12 +323,16 @@ async function initProjectConfigAi(options = {}) {
|
|
|
314
323
|
'after reviewing the plan; a new native binary will be required.');
|
|
315
324
|
}
|
|
316
325
|
}
|
|
317
|
-
|
|
326
|
+
const migrateCodePush = nativeScan && (scan.request.detected.codePushDetected ||
|
|
327
|
+
plan.actions.some(action => action.type === 'migrate_codepush'));
|
|
328
|
+
if (migrateCodePush) {
|
|
318
329
|
if (!options.migrateCodePush && !options.yes) {
|
|
319
330
|
const migrationAnswer = await (0, prompts_1.default)({
|
|
320
331
|
type: 'confirm',
|
|
321
332
|
name: 'migrate',
|
|
322
|
-
message:
|
|
333
|
+
message: scan.request.detected.codePushDetected
|
|
334
|
+
? 'Remove react-native-code-push and migrate native startup ownership to Bundle Drop?'
|
|
335
|
+
: 'Replace the remaining native CodePush startup references with Bundle Drop?',
|
|
323
336
|
initial: false,
|
|
324
337
|
});
|
|
325
338
|
options.migrateCodePush = Boolean(migrationAnswer.migrate);
|
|
@@ -329,11 +342,10 @@ async function initProjectConfigAi(options = {}) {
|
|
|
329
342
|
'the plan; a new native binary will be required.');
|
|
330
343
|
}
|
|
331
344
|
}
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
assertNoCodePushMigrationResidue(projectRoot);
|
|
345
|
+
const shouldRemoveCodePush = migrateCodePush && scan.request.detected.codePushDetected;
|
|
346
|
+
if (migrateCodePush && verifiedNativePaths) {
|
|
347
|
+
assertNoCodePushMigrationResidue(projectRoot, verifiedNativePaths);
|
|
348
|
+
}
|
|
337
349
|
for (const action of plan.actions.filter(action => action.requiresConfirmation &&
|
|
338
350
|
action.type !== 'migrate_expo_updates' &&
|
|
339
351
|
action.type !== 'migrate_codepush')) {
|
|
@@ -362,13 +374,15 @@ async function initProjectConfigAi(options = {}) {
|
|
|
362
374
|
return;
|
|
363
375
|
}
|
|
364
376
|
const aiChanges = plan.changes.filter(shouldApplyAiChange);
|
|
365
|
-
(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
377
|
+
if (!nativeScan) {
|
|
378
|
+
(0, validate_plan_1.validateSetupChangesBeforeApply)({
|
|
379
|
+
projectType,
|
|
380
|
+
originals,
|
|
381
|
+
changes: aiChanges,
|
|
382
|
+
migrateExpoUpdates: Boolean(options.migrateExpoUpdates),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
if (nativeScan && verifiedNativePaths) {
|
|
372
386
|
const metroChange = (0, bare_metro_config_1.planBareMetroConfig)(projectRoot);
|
|
373
387
|
const bundleConfigFile = inspectPlanningFile(projectRoot, 'bundle.drop.config.js');
|
|
374
388
|
const bundleConfigExists = bundleConfigFile.exists;
|
|
@@ -393,10 +407,9 @@ async function initProjectConfigAi(options = {}) {
|
|
|
393
407
|
bootstrapChange,
|
|
394
408
|
bootstrapGitignoreChange,
|
|
395
409
|
].filter((change) => Boolean(change));
|
|
396
|
-
if (!aiChanges.length && !localChanges.length && !
|
|
397
|
-
console.log(chalk_1.default.gray('
|
|
410
|
+
if (!aiChanges.length && !localChanges.length && !migrateCodePush) {
|
|
411
|
+
console.log(chalk_1.default.gray('The setup planner proposed no changes.'));
|
|
398
412
|
if (!options.dryRun) {
|
|
399
|
-
await (0, doctor_1.runDoctor)({ projectType: 'bare', cwd: projectRoot });
|
|
400
413
|
logRuntimeInitializationNextStep();
|
|
401
414
|
}
|
|
402
415
|
return;
|
|
@@ -420,7 +433,7 @@ async function initProjectConfigAi(options = {}) {
|
|
|
420
433
|
originals: bareOriginals,
|
|
421
434
|
changes: previewChanges,
|
|
422
435
|
})));
|
|
423
|
-
if (
|
|
436
|
+
if (shouldRemoveCodePush) {
|
|
424
437
|
const command = (0, package_manager_1.codePushRemovalCommand)((0, package_manager_1.detectPackageManager)(projectRoot));
|
|
425
438
|
console.log(chalk_1.default.yellow(`Dependency migration command: ${command.join(' ')}`));
|
|
426
439
|
}
|
|
@@ -439,24 +452,21 @@ async function initProjectConfigAi(options = {}) {
|
|
|
439
452
|
let result;
|
|
440
453
|
let metroResult;
|
|
441
454
|
try {
|
|
442
|
-
|
|
455
|
+
(0, setup_v2_1.assertNativeSetupSnapshot)(nativeScan);
|
|
456
|
+
if (shouldRemoveCodePush) {
|
|
443
457
|
dependencyBackup = (0, package_manager_1.removeCodePushWithPackageManager)(projectRoot);
|
|
458
|
+
(0, setup_v2_1.assertNativeSetupSnapshot)(nativeScan, [], true);
|
|
444
459
|
}
|
|
445
|
-
result = (0, apply_setup_plan_1.applySetupPatchPlans)({ projectRoot, projectType, changes: aiChanges });
|
|
446
|
-
(0,
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
changes: aiChanges,
|
|
450
|
-
migrateExpoUpdates: false,
|
|
451
|
-
originals,
|
|
452
|
-
});
|
|
460
|
+
result = (0, apply_setup_plan_1.applySetupPatchPlans)({ projectRoot, projectType, changes: aiChanges, verifiedNativePaths });
|
|
461
|
+
(0, setup_v2_1.assertNativeSetupSnapshot)(nativeScan, aiChanges, Boolean(dependencyBackup));
|
|
462
|
+
if (migrateCodePush)
|
|
463
|
+
assertNoCodePushMigrationResidue(projectRoot, new Set());
|
|
453
464
|
if (localChanges.length) {
|
|
454
465
|
metroResult = (0, configure_expo_1.applyExpoConfigurationChanges)({
|
|
455
466
|
projectRoot,
|
|
456
467
|
changes: localChanges,
|
|
457
468
|
});
|
|
458
469
|
}
|
|
459
|
-
await (0, doctor_1.runDoctor)({ projectType: 'bare', cwd: projectRoot });
|
|
460
470
|
}
|
|
461
471
|
catch (error) {
|
|
462
472
|
if (metroResult)
|
|
@@ -472,6 +482,7 @@ async function initProjectConfigAi(options = {}) {
|
|
|
472
482
|
if (!result)
|
|
473
483
|
throw new Error('Bare setup transaction completed without a backup result.');
|
|
474
484
|
console.log(chalk_1.default.green(`✅ Bare React Native setup complete. Backups: ${result.backupDir}`));
|
|
485
|
+
console.log(chalk_1.default.cyan('Build and launch the native app to verify the Release bundle startup.'));
|
|
475
486
|
logRuntimeInitializationNextStep();
|
|
476
487
|
return;
|
|
477
488
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AiSetupFileKind } from './types';
|
|
2
|
+
type NativeSetupContextPath = {
|
|
3
|
+
path: string;
|
|
4
|
+
kind: Extract<AiSetupFileKind, 'ios_entrypoint' | 'android_entrypoint' | 'native_support'>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Collect only application-owned source paths and build metadata. The planning
|
|
8
|
+
* service decides which supplied sources own startup after the user's consent.
|
|
9
|
+
*/
|
|
10
|
+
export declare function listNativeSetupContext(projectRoot: string): NativeSetupContextPath[];
|
|
11
|
+
export declare function collectNativeSetupContext(projectRoot: string): Promise<{
|
|
12
|
+
inventory: string[];
|
|
13
|
+
sources: NativeSetupContextPath[];
|
|
14
|
+
support: {
|
|
15
|
+
path: string;
|
|
16
|
+
content: string;
|
|
17
|
+
}[];
|
|
18
|
+
metadataSnapshot: (readonly [string, string])[];
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,242 @@
|
|
|
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.listNativeSetupContext = listNativeSetupContext;
|
|
7
|
+
exports.collectNativeSetupContext = collectNativeSetupContext;
|
|
8
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const safe_file_transaction_1 = require("../safe-file-transaction");
|
|
12
|
+
const native_setup_metadata_1 = require("./native-setup-metadata");
|
|
13
|
+
const terminal_safety_1 = require("./terminal-safety");
|
|
14
|
+
const MAX_DIRECTORY_ENTRIES = 5000;
|
|
15
|
+
const MAX_SOURCE_FILES = 16;
|
|
16
|
+
const MAX_SOURCE_BYTES = 80 * 1024;
|
|
17
|
+
const MAX_SOURCE_CONTEXT_BYTES = 96 * 1024;
|
|
18
|
+
const MAX_SUPPORT_FILES = 8;
|
|
19
|
+
const MAX_SUPPORT_SUMMARY_BYTES = 24 * 1024;
|
|
20
|
+
const MAX_METADATA_INPUT_BYTES = 2 * 1024 * 1024;
|
|
21
|
+
const MAX_METADATA_INPUT_FILES = 48;
|
|
22
|
+
const EXCLUDED_DIRECTORIES = new Set([
|
|
23
|
+
'build', 'deriveddata', 'generated', 'node_modules', 'pods', 'test', 'tests',
|
|
24
|
+
'androidtest', 'testfixtures', 'unittest', 'vendor',
|
|
25
|
+
]);
|
|
26
|
+
const isExcludedDirectory = (name) => name.startsWith('.') || EXCLUDED_DIRECTORIES.has(name.toLowerCase()) || name.endsWith('Tests');
|
|
27
|
+
const assertSafeContextPath = (file) => {
|
|
28
|
+
if (file.length > 512 || file.includes('\\') || /[\t\r\n]/.test(file) || (0, terminal_safety_1.hasUnsafeTerminalControl)(file)) {
|
|
29
|
+
throw new Error('A native setup path has unsafe characters. Rename the path and retry.');
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Collect only application-owned source paths and build metadata. The planning
|
|
34
|
+
* service decides which supplied sources own startup after the user's consent.
|
|
35
|
+
*/
|
|
36
|
+
function listNativeSetupContext(projectRoot) {
|
|
37
|
+
const files = new Map();
|
|
38
|
+
let visited = 0;
|
|
39
|
+
const add = (file, kind) => {
|
|
40
|
+
assertSafeContextPath(file);
|
|
41
|
+
files.set(file, kind);
|
|
42
|
+
};
|
|
43
|
+
const addIfPresent = (file) => {
|
|
44
|
+
const stat = node_fs_1.default.lstatSync(node_path_1.default.join(projectRoot, file), { throwIfNoEntry: false });
|
|
45
|
+
if (!stat)
|
|
46
|
+
return;
|
|
47
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
48
|
+
throw new Error(`Refusing a non-regular native setup path: ${file}.`);
|
|
49
|
+
}
|
|
50
|
+
add(file, 'native_support');
|
|
51
|
+
};
|
|
52
|
+
const entries = (directory) => {
|
|
53
|
+
const children = node_fs_1.default.readdirSync(node_path_1.default.join(projectRoot, directory), { withFileTypes: true });
|
|
54
|
+
visited += children.length;
|
|
55
|
+
if (visited > MAX_DIRECTORY_ENTRIES) {
|
|
56
|
+
throw new Error('Native setup context exceeds the directory inspection limit.');
|
|
57
|
+
}
|
|
58
|
+
return children;
|
|
59
|
+
};
|
|
60
|
+
const walk = (root, visit, xcode) => {
|
|
61
|
+
const pending = [root];
|
|
62
|
+
while (pending.length) {
|
|
63
|
+
const directory = pending.pop();
|
|
64
|
+
for (const item of entries(directory)) {
|
|
65
|
+
if (isExcludedDirectory(item.name))
|
|
66
|
+
continue;
|
|
67
|
+
const file = node_path_1.default.posix.join(directory, item.name);
|
|
68
|
+
assertSafeContextPath(file);
|
|
69
|
+
if (item.isSymbolicLink()) {
|
|
70
|
+
throw new Error(`Refusing a symlinked native setup path: ${file}.`);
|
|
71
|
+
}
|
|
72
|
+
if (item.isFile()) {
|
|
73
|
+
visit(file, item.name);
|
|
74
|
+
}
|
|
75
|
+
else if (item.isDirectory()) {
|
|
76
|
+
if (xcode && item.name.endsWith('.xcodeproj'))
|
|
77
|
+
addIfPresent(file + '/project.pbxproj');
|
|
78
|
+
else if (!item.name.endsWith('.xcworkspace') && !item.name.endsWith('.xcassets'))
|
|
79
|
+
pending.push(file);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
if ((0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'ios')) {
|
|
85
|
+
walk('ios', (file, name) => {
|
|
86
|
+
const extension = node_path_1.default.posix.extname(name);
|
|
87
|
+
if (['.swift', '.m', '.mm'].includes(extension))
|
|
88
|
+
add(file, 'ios_entrypoint');
|
|
89
|
+
if (extension === '.plist')
|
|
90
|
+
add(file, 'native_support');
|
|
91
|
+
}, true);
|
|
92
|
+
}
|
|
93
|
+
if ((0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'android')) {
|
|
94
|
+
for (const module of entries('android')) {
|
|
95
|
+
if (isExcludedDirectory(module.name))
|
|
96
|
+
continue;
|
|
97
|
+
const directory = 'android/' + module.name;
|
|
98
|
+
assertSafeContextPath(directory);
|
|
99
|
+
if (!module.isDirectory() || !(0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, directory + '/src'))
|
|
100
|
+
continue;
|
|
101
|
+
addIfPresent(directory + '/build.gradle');
|
|
102
|
+
addIfPresent(directory + '/build.gradle.kts');
|
|
103
|
+
walk(directory + '/src', (file, name) => {
|
|
104
|
+
const extension = node_path_1.default.posix.extname(name);
|
|
105
|
+
if (extension === '.java' || extension === '.kt')
|
|
106
|
+
add(file, 'android_entrypoint');
|
|
107
|
+
if (name === 'AndroidManifest.xml')
|
|
108
|
+
add(file, 'native_support');
|
|
109
|
+
}, false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (![...files.values()].some(kind => kind !== 'native_support')) {
|
|
113
|
+
throw new Error('No app-owned native source files were found for Bundle Drop setup.');
|
|
114
|
+
}
|
|
115
|
+
return [...files].map(([file, kind]) => ({ path: file, kind }))
|
|
116
|
+
.sort((left, right) => left.path.localeCompare(right.path));
|
|
117
|
+
}
|
|
118
|
+
const metadataPriority = (file) => {
|
|
119
|
+
if (file.endsWith('project.pbxproj') || file.endsWith('/src/main/AndroidManifest.xml'))
|
|
120
|
+
return 0;
|
|
121
|
+
if (file.endsWith('/Info.plist') || /\/build\.gradle(?:\.kts)?$/.test(file))
|
|
122
|
+
return 1;
|
|
123
|
+
return 2;
|
|
124
|
+
};
|
|
125
|
+
async function readMetadata(projectRoot, inventory) {
|
|
126
|
+
const files = inventory.filter(file => file.kind === 'native_support')
|
|
127
|
+
.sort((left, right) => metadataPriority(left.path) - metadataPriority(right.path))
|
|
128
|
+
.slice(0, MAX_METADATA_INPUT_FILES);
|
|
129
|
+
const metadata = [];
|
|
130
|
+
for (const file of files) {
|
|
131
|
+
const localPath = node_path_1.default.join(projectRoot, file.path);
|
|
132
|
+
if (node_fs_1.default.lstatSync(localPath).size > MAX_METADATA_INPUT_BYTES)
|
|
133
|
+
continue;
|
|
134
|
+
const original = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file.path);
|
|
135
|
+
if (!original.exists)
|
|
136
|
+
throw new Error(`Native setup file changed during discovery: ${file.path}.`);
|
|
137
|
+
const facts = await (0, native_setup_metadata_1.projectNativeSetupMetadata)(file.path, original.content);
|
|
138
|
+
if (facts) {
|
|
139
|
+
metadata.push({
|
|
140
|
+
...file,
|
|
141
|
+
facts,
|
|
142
|
+
originalSha256: node_crypto_1.default.createHash('sha256').update(original.content).digest('hex'),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return metadata;
|
|
147
|
+
}
|
|
148
|
+
function prioritizeSources(inventory, metadata) {
|
|
149
|
+
const registeredClasses = new Set();
|
|
150
|
+
const appTargetSources = new Set();
|
|
151
|
+
for (const { facts } of metadata) {
|
|
152
|
+
if ('applicationClass' in facts && facts.applicationClass) {
|
|
153
|
+
registeredClasses.add(facts.applicationClass.split('.').pop());
|
|
154
|
+
}
|
|
155
|
+
else if ('sceneDelegateClasses' in facts) {
|
|
156
|
+
for (const name of facts.sceneDelegateClasses)
|
|
157
|
+
registeredClasses.add(name.split('.').pop());
|
|
158
|
+
}
|
|
159
|
+
else if ('targets' in facts) {
|
|
160
|
+
for (const target of facts.targets) {
|
|
161
|
+
for (const source of target.sourcePaths)
|
|
162
|
+
appTargetSources.add(source);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const priority = (file) => {
|
|
167
|
+
const name = node_path_1.default.posix.basename(file.path, node_path_1.default.posix.extname(file.path));
|
|
168
|
+
if (registeredClasses.has(name))
|
|
169
|
+
return 0;
|
|
170
|
+
if (['MainApplication', 'AppDelegate', 'SceneDelegate', 'main'].includes(name))
|
|
171
|
+
return 1;
|
|
172
|
+
if (appTargetSources.has(file.path))
|
|
173
|
+
return 2;
|
|
174
|
+
if (/\b(?:delegate|resolver|reacthost|nativehost|factory|startup)|Delegate$|Resolver$|Lifecycle$/i.test(name))
|
|
175
|
+
return 3;
|
|
176
|
+
return 4;
|
|
177
|
+
};
|
|
178
|
+
return inventory.filter(file => file.kind !== 'native_support')
|
|
179
|
+
.sort((left, right) => priority(left) - priority(right));
|
|
180
|
+
}
|
|
181
|
+
async function collectNativeSetupContext(projectRoot) {
|
|
182
|
+
const inventory = listNativeSetupContext(projectRoot);
|
|
183
|
+
const metadata = await readMetadata(projectRoot, inventory);
|
|
184
|
+
const ranked = prioritizeSources(inventory, metadata);
|
|
185
|
+
// Reserve space for each platform before considering additional source files.
|
|
186
|
+
const primary = ['android_entrypoint', 'ios_entrypoint'].flatMap(kind => {
|
|
187
|
+
const file = ranked.find(candidate => candidate.kind === kind);
|
|
188
|
+
return file ? [file] : [];
|
|
189
|
+
});
|
|
190
|
+
const sources = [];
|
|
191
|
+
let bytes = 0;
|
|
192
|
+
for (const file of [...primary, ...ranked.filter(candidate => !primary.includes(candidate))]) {
|
|
193
|
+
if (sources.length === MAX_SOURCE_FILES)
|
|
194
|
+
break;
|
|
195
|
+
const size = node_fs_1.default.lstatSync(node_path_1.default.join(projectRoot, file.path)).size;
|
|
196
|
+
if (size > MAX_SOURCE_BYTES || bytes + size > MAX_SOURCE_CONTEXT_BYTES) {
|
|
197
|
+
if (primary.includes(file)) {
|
|
198
|
+
throw new Error(`Native startup source exceeds the AI setup size limit: ${file.path}.`);
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
bytes += size;
|
|
203
|
+
sources.push(file);
|
|
204
|
+
}
|
|
205
|
+
const selectedPaths = new Set(sources.map(file => file.path));
|
|
206
|
+
const androidModules = new Set(sources.filter(file => file.kind === 'android_entrypoint')
|
|
207
|
+
.map(file => file.path.split('/')[1]));
|
|
208
|
+
const relevantPlists = new Set();
|
|
209
|
+
for (const { facts } of metadata) {
|
|
210
|
+
if (!('targets' in facts))
|
|
211
|
+
continue;
|
|
212
|
+
for (const target of facts.targets) {
|
|
213
|
+
if (target.sourcePaths.some(file => selectedPaths.has(file))) {
|
|
214
|
+
for (const plist of target.infoPlistPaths)
|
|
215
|
+
relevantPlists.add(plist);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const support = metadata
|
|
220
|
+
.filter(file => !file.path.startsWith('android/') || androidModules.has(file.path.split('/')[1]))
|
|
221
|
+
.filter(({ path: file, facts }) => !('sceneDelegateClasses' in facts) ||
|
|
222
|
+
relevantPlists.has(file) || facts.sceneDelegateClasses.length > 0 || file.endsWith('/Info.plist'))
|
|
223
|
+
.sort((left, right) => Number(relevantPlists.has(right.path)) - Number(relevantPlists.has(left.path)) ||
|
|
224
|
+
metadataPriority(left.path) - metadataPriority(right.path))
|
|
225
|
+
.slice(0, MAX_SUPPORT_FILES)
|
|
226
|
+
.map(({ path: relativePath, facts }) => {
|
|
227
|
+
const summary = 'targets' in facts ? {
|
|
228
|
+
targets: facts.targets.map(target => ({
|
|
229
|
+
...target,
|
|
230
|
+
sourcePaths: target.sourcePaths.filter(file => selectedPaths.has(file)),
|
|
231
|
+
})),
|
|
232
|
+
} : facts;
|
|
233
|
+
return { path: relativePath, content: JSON.stringify(summary) };
|
|
234
|
+
})
|
|
235
|
+
.filter(file => Buffer.byteLength(file.content) <= MAX_SUPPORT_SUMMARY_BYTES);
|
|
236
|
+
return {
|
|
237
|
+
inventory: inventory.map(file => file.path),
|
|
238
|
+
sources,
|
|
239
|
+
support,
|
|
240
|
+
metadataSnapshot: metadata.map(file => [file.path, file.originalSha256]),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type NativeSetupMetadata = {
|
|
2
|
+
applicationClass: string | null;
|
|
3
|
+
packageName: string | null;
|
|
4
|
+
} | {
|
|
5
|
+
namespace: string | null;
|
|
6
|
+
} | {
|
|
7
|
+
sceneDelegateClasses: string[];
|
|
8
|
+
} | {
|
|
9
|
+
targets: {
|
|
10
|
+
sourcePaths: string[];
|
|
11
|
+
infoPlistPaths: string[];
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
/** Extract allowlisted native authority facts without returning any raw metadata. */
|
|
15
|
+
export declare function projectNativeSetupMetadata(relativePath: string, source: string): Promise<NativeSetupMetadata | null>;
|
|
16
|
+
export {};
|