@gfean/react-native-bundle-drop 0.12.0 → 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.
Files changed (56) hide show
  1. package/README.md +74 -829
  2. package/lib/CLI/cli.js +9 -2
  3. package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +2 -0
  4. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +6 -3
  5. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -4
  6. package/lib/CLI/scripts/aipowered/backend-client.js +5 -1
  7. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +1 -1
  8. package/lib/CLI/scripts/aipowered/code-push-residue.js +11 -5
  9. package/lib/CLI/scripts/aipowered/init-project-config.js +47 -36
  10. package/lib/CLI/scripts/aipowered/native-setup-context.d.ts +20 -0
  11. package/lib/CLI/scripts/aipowered/native-setup-context.js +242 -0
  12. package/lib/CLI/scripts/aipowered/native-setup-metadata.d.ts +16 -0
  13. package/lib/CLI/scripts/aipowered/native-setup-metadata.js +104 -0
  14. package/lib/CLI/scripts/aipowered/scanner.d.ts +7 -3
  15. package/lib/CLI/scripts/aipowered/scanner.js +96 -30
  16. package/lib/CLI/scripts/aipowered/setup-v2.d.ts +3 -0
  17. package/lib/CLI/scripts/aipowered/setup-v2.js +53 -0
  18. package/lib/CLI/scripts/aipowered/types.d.ts +11 -1
  19. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -1
  20. package/lib/CLI/scripts/aipowered/validate-plan.js +10 -4
  21. package/lib/CLI/scripts/doctor.js +18 -6
  22. package/lib/CLI/scripts/expo/eas-build-proof.js +8 -2
  23. package/lib/CLI/scripts/expo/package-manager.d.ts +1 -0
  24. package/lib/CLI/scripts/expo/package-manager.js +7 -3
  25. package/lib/CLI/scripts/ios-scene-target.d.ts +9 -0
  26. package/lib/CLI/scripts/ios-scene-target.js +193 -0
  27. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +1 -0
  28. package/lib/CLI/scripts/native-entrypoint-authority.js +24 -0
  29. package/lib/CLI/scripts/native-setup-contract.d.ts +4 -0
  30. package/lib/CLI/scripts/native-setup-contract.js +28 -14
  31. package/lib/CLI/scripts/native-startup-validator.d.ts +4 -1
  32. package/lib/CLI/scripts/native-startup-validator.js +83 -6
  33. package/lib/CLI/scripts/safe-file-transaction.d.ts +1 -1
  34. package/lib/CLI/scripts/safe-file-transaction.js +3 -3
  35. package/lib/CLI/utils/read-xml-plist.d.ts +2 -1
  36. package/lib/CLI/utils/read-xml-plist.js +7 -3
  37. package/lib/api/types.d.ts +4 -1
  38. package/lib/expo/buildIdentity.js +1 -1
  39. package/lib/index.d.ts +1 -1
  40. package/lib/injectImageResolver.js +7 -2
  41. package/lib/manager/downloadAndInstall.d.ts +2 -0
  42. package/lib/manager/downloadAndInstall.js +10 -1
  43. package/lib/manager/updateCheck.js +18 -1
  44. package/lib/manager/updateState.d.ts +1 -1
  45. package/lib/manager/updateState.js +2 -1
  46. package/lib/runtime/service.d.ts +2 -0
  47. package/lib/runtime/service.js +33 -13
  48. package/lib/runtime-delivery/localResolver.d.ts +3 -0
  49. package/lib/runtime-delivery/localResolver.js +11 -0
  50. package/lib/runtime-delivery/runtimeDelivery.d.ts +4 -0
  51. package/lib/runtime-delivery/runtimeDelivery.js +3 -1
  52. package/lib/types.d.ts +2 -0
  53. package/lib/useBundleDrop.d.ts +3 -0
  54. package/lib/useBundleDrop.js +1 -0
  55. package/package.json +9 -25
  56. package/third_party/expo-fingerprint/scheme-1-contract.json +1 -1
@@ -0,0 +1,104 @@
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.projectNativeSetupMetadata = projectNativeSetupMetadata;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const read_xml_plist_1 = require("../../utils/read-xml-plist");
9
+ const ios_scene_target_1 = require("../ios-scene-target");
10
+ const native_setup_contract_1 = require("../native-setup-contract");
11
+ const terminal_safety_1 = require("./terminal-safety");
12
+ const MAX_METADATA_SOURCE_BYTES = 2 * 1024 * 1024;
13
+ const MAX_METADATA_ENTRIES = 8;
14
+ const dottedIdentifier = (value, allowLeadingDot = false) => {
15
+ if (typeof value !== 'string')
16
+ return null;
17
+ const identifier = value.trim();
18
+ return identifier.length <= 240 &&
19
+ (allowLeadingDot || !identifier.startsWith('.')) &&
20
+ /^\.?[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(identifier)
21
+ ? identifier
22
+ : null;
23
+ };
24
+ const xmlAttribute = (tag, name) => {
25
+ const attributes = tag.matchAll(/(?:^|\s)([A-Za-z_][\w:.-]*)\s*=\s*(["'])([\s\S]*?)\2/g);
26
+ const matches = [...attributes].filter(match => match[1] === name);
27
+ return matches.length === 1 ? matches[0][3] : null;
28
+ };
29
+ const projectAndroidManifest = (source) => {
30
+ const xml = source.replace(/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)/g, '');
31
+ const manifest = /^\s*(?:<\?xml[^>]*>\s*)?<manifest\b((?:[^<>"']|"[^<"]*"|'[^<']*')*)>/.exec(xml);
32
+ if (!manifest)
33
+ return null;
34
+ const applications = [...xml.matchAll(/<application\b((?:[^<>"']|"[^<"]*"|'[^<']*')*)>/g)];
35
+ return {
36
+ applicationClass: applications.length === 1
37
+ ? dottedIdentifier(xmlAttribute(applications[0][1], 'android:name'), true)
38
+ : null,
39
+ packageName: dottedIdentifier(xmlAttribute(manifest[1], 'package')),
40
+ };
41
+ };
42
+ const projectGradleNamespace = (source) => {
43
+ const matches = (0, native_setup_contract_1.stripComments)(source).matchAll(/(?:^|[;{\n])[ \t]*namespace[ \t]*([=(])?[ \t]*(["'])([^"'\r\n]+)\2[ \t]*(\))?[ \t]*(?=[;\r\n}]|$)/g);
44
+ const values = [...new Set([...matches].map(match => (match[1] === '(') === Boolean(match[4]) ? dottedIdentifier(match[3]) : null))];
45
+ return { namespace: values.length === 1 ? values[0] : null };
46
+ };
47
+ const dictionary = (value) => value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype
48
+ ? value
49
+ : {};
50
+ const projectScenePlist = async (source) => {
51
+ const plist = await (0, read_xml_plist_1.parseXmlPlist)(source);
52
+ const manifest = dictionary(plist.UIApplicationSceneManifest);
53
+ const roles = dictionary(manifest.UISceneConfigurations);
54
+ const application = roles.UIWindowSceneSessionRoleApplication;
55
+ if (!Array.isArray(application))
56
+ return { sceneDelegateClasses: [] };
57
+ const classes = application.flatMap(configuration => {
58
+ const name = dictionary(configuration).UISceneDelegateClassName;
59
+ if (typeof name !== 'string')
60
+ return [];
61
+ const identifier = dottedIdentifier(name.replace(/^\$(?:\(PRODUCT_MODULE_NAME\)|\{PRODUCT_MODULE_NAME\})\./, ''));
62
+ return identifier ? [identifier] : [];
63
+ });
64
+ return { sceneDelegateClasses: [...new Set(classes)].slice(0, MAX_METADATA_ENTRIES) };
65
+ };
66
+ const isIosMetadataPath = (file) => file.startsWith('ios/') &&
67
+ file.length <= 512 &&
68
+ !/[\\\t\r\n]/.test(file) &&
69
+ !(0, terminal_safety_1.hasUnsafeTerminalControl)(file) &&
70
+ file.split('/').every(part => part && !part.startsWith('.') &&
71
+ !['node_modules', 'Pods', 'build', 'DerivedData'].includes(part));
72
+ const projectXcode = async (relativePath, source) => {
73
+ const { parseOpenStep } = await import('plist');
74
+ const directory = node_path_1.default.posix.dirname(node_path_1.default.posix.dirname(relativePath));
75
+ const targets = (0, ios_scene_target_1.readXcodeApplicationTargets)(parseOpenStep(source), directory).map(target => ({
76
+ sourcePaths: [...new Set(target.sourcePaths.filter(file => isIosMetadataPath(file) && /\.(?:swift|m|mm)$/.test(file)))].sort(),
77
+ infoPlistPaths: [...new Set(target.infoPlistPaths.filter(isIosMetadataPath))]
78
+ .sort().slice(0, MAX_METADATA_ENTRIES),
79
+ }));
80
+ return { targets };
81
+ };
82
+ /** Extract allowlisted native authority facts without returning any raw metadata. */
83
+ async function projectNativeSetupMetadata(relativePath, source) {
84
+ if (Buffer.byteLength(source, 'utf8') > MAX_METADATA_SOURCE_BYTES)
85
+ return null;
86
+ try {
87
+ if (/^android\/[^/]+\/src\/(?:.*\/)?AndroidManifest\.xml$/.test(relativePath)) {
88
+ return projectAndroidManifest(source);
89
+ }
90
+ if (/^android\/[^/]+\/build\.gradle(?:\.kts)?$/.test(relativePath)) {
91
+ return projectGradleNamespace(source);
92
+ }
93
+ if (!isIosMetadataPath(relativePath))
94
+ return null;
95
+ if (relativePath.endsWith('.plist'))
96
+ return await projectScenePlist(source);
97
+ if (/\.xcodeproj\/project\.pbxproj$/.test(relativePath))
98
+ return await projectXcode(relativePath, source);
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ return null;
104
+ }
@@ -1,13 +1,17 @@
1
- import { AiSetupProjectType, AiSetupScannerResult } from './types';
1
+ import { AiSetupProjectType, AiSetupScannerResult, AiSetupScannerResultV2 } from './types';
2
+ export declare const MAX_SETUP_FILE_BYTES: number;
2
3
  export declare const findCredentialLikeLiteral: (content: string) => string | null;
3
4
  export declare const isTrustedAiPlanningServer: (serverUrl: string) => boolean;
4
5
  export declare const isBundleDropHostedAiPlanningServer: (serverUrl: string) => boolean;
5
6
  export declare function findProjectRoot(startDir?: string): string;
6
7
  export declare const authoritativeDynamicExpoConfigFile: (projectRoot: string, candidate: unknown) => string | null;
7
- export declare function scanProjectForAiSetup(projectType: AiSetupProjectType, startDir?: string, virtualConfig?: {
8
+ type VirtualSetupConfig = {
8
9
  content: string;
9
10
  serverUrl: string;
10
11
  orgSlug: string;
11
12
  projectSlug: string;
12
13
  authToken: string;
13
- }): AiSetupScannerResult;
14
+ };
15
+ export declare function scanProjectForAiSetup(projectType: AiSetupProjectType, startDir?: string, virtualConfig?: VirtualSetupConfig, iosSceneEntrypoint?: string): AiSetupScannerResult;
16
+ export declare function scanProjectForAiSetupV2(projectRoot: string, virtualConfig?: VirtualSetupConfig): Promise<AiSetupScannerResultV2>;
17
+ export {};
@@ -3,9 +3,10 @@ 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.authoritativeDynamicExpoConfigFile = exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.findCredentialLikeLiteral = void 0;
6
+ exports.authoritativeDynamicExpoConfigFile = exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.findCredentialLikeLiteral = exports.MAX_SETUP_FILE_BYTES = void 0;
7
7
  exports.findProjectRoot = findProjectRoot;
8
8
  exports.scanProjectForAiSetup = scanProjectForAiSetup;
9
+ exports.scanProjectForAiSetupV2 = scanProjectForAiSetupV2;
9
10
  const crypto_1 = __importDefault(require("crypto"));
10
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
12
  const module_1 = require("module");
@@ -15,10 +16,11 @@ const expo_1 = require("../../../expo");
15
16
  const native_setup_contract_1 = require("../native-setup-contract");
16
17
  const safe_file_transaction_1 = require("../safe-file-transaction");
17
18
  const native_entrypoint_authority_1 = require("../native-entrypoint-authority");
19
+ const native_setup_context_1 = require("./native-setup-context");
18
20
  const terminal_safety_1 = require("./terminal-safety");
19
21
  const credential_safety_1 = require("./credential-safety");
20
22
  const MAX_UP = 12;
21
- const MAX_FILE_BYTES = 80 * 1024;
23
+ exports.MAX_SETUP_FILE_BYTES = 80 * 1024;
22
24
  const MAX_SUMMARIZED_SOURCE_BYTES = 1024 * 1024;
23
25
  const MAX_TOTAL_BYTES = 128 * 1024;
24
26
  const MAX_NATIVE_SCAN_ENTRIES = 5000;
@@ -294,7 +296,7 @@ const authoritativeDynamicExpoConfigFile = (projectRoot, candidate) => {
294
296
  return relativePath;
295
297
  };
296
298
  exports.authoritativeDynamicExpoConfigFile = authoritativeDynamicExpoConfigFile;
297
- const readSetupFile = (projectRoot, relativePath) => {
299
+ const readSetupFile = (projectRoot, relativePath, nativeKind, snapshot) => {
298
300
  let inspected;
299
301
  try {
300
302
  inspected = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath);
@@ -302,24 +304,28 @@ const readSetupFile = (projectRoot, relativePath) => {
302
304
  catch {
303
305
  throw setupContextLimitError(relativePath, 'the path is not a regular project file');
304
306
  }
305
- if (!inspected.exists)
307
+ if (!inspected.exists) {
308
+ if (nativeKind)
309
+ throw setupContextLimitError(relativePath, 'it changed during discovery');
306
310
  return null;
311
+ }
307
312
  const sizeBytes = Buffer.byteLength(inspected.content, 'utf8');
308
- const summarized = isSummarizedSetupFile(relativePath);
309
- if (sizeBytes > (summarized ? MAX_SUMMARIZED_SOURCE_BYTES : MAX_FILE_BYTES)) {
310
- if (isRequiredPatchableSetupFile(relativePath)) {
311
- throw setupContextLimitError(relativePath, `it exceeds the ${MAX_FILE_BYTES}-byte per-file limit`);
313
+ const summarized = !nativeKind && isSummarizedSetupFile(relativePath);
314
+ if (sizeBytes > (summarized ? MAX_SUMMARIZED_SOURCE_BYTES : exports.MAX_SETUP_FILE_BYTES)) {
315
+ if (nativeKind || isRequiredPatchableSetupFile(relativePath)) {
316
+ throw setupContextLimitError(relativePath, `it exceeds the ${exports.MAX_SETUP_FILE_BYTES}-byte per-file limit`);
312
317
  }
313
318
  return null;
314
319
  }
315
320
  const rawContent = inspected.content;
316
- const kind = setupFileKind(relativePath);
321
+ const kind = nativeKind || setupFileKind(relativePath);
317
322
  if (!summarized) {
318
323
  assertSafeAiSetupContent(relativePath, rawContent);
319
324
  }
320
325
  const content = summarized
321
326
  ? summarizeContextContent(relativePath, rawContent, sizeBytes)
322
327
  : rawContent;
328
+ snapshot?.set(relativePath, sha256(rawContent));
323
329
  return {
324
330
  kind,
325
331
  path: relativePath,
@@ -327,7 +333,8 @@ const readSetupFile = (projectRoot, relativePath) => {
327
333
  sha256: sha256(content),
328
334
  };
329
335
  };
330
- const collectSetupFiles = (projectRoot, projectType, dynamicExpoConfigFile) => {
336
+ const collectSetupFiles = (projectRoot, projectType, dynamicExpoConfigFile, iosSceneEntrypoint, nativeContext) => {
337
+ const snapshot = nativeContext?.snapshot;
331
338
  const relativePaths = [
332
339
  'package.json',
333
340
  ...SETUP_CONFIG_FILES.filter(relativePath => projectType === 'expo'
@@ -338,16 +345,20 @@ const collectSetupFiles = (projectRoot, projectType, dynamicExpoConfigFile) => {
338
345
  if (projectType === 'expo' && dynamicExpoConfigFile) {
339
346
  relativePaths.push(dynamicExpoConfigFile);
340
347
  }
341
- if (projectType === 'bare') {
348
+ if (projectType === 'bare' && !snapshot) {
342
349
  for (const srcDir of ['java', 'kotlin']) {
343
350
  relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', srcDir), new Set(['MainApplication.kt', 'MainApplication.java'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
344
351
  }
345
- relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'ios'), new Set(['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
352
+ if (iosSceneEntrypoint)
353
+ relativePaths.push(iosSceneEntrypoint);
354
+ else {
355
+ relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'ios'), new Set(['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
356
+ }
346
357
  }
347
358
  const files = [];
348
359
  let totalBytes = 0;
349
360
  for (const relativePath of [...new Set(relativePaths)]) {
350
- const file = readSetupFile(projectRoot, relativePath);
361
+ const file = readSetupFile(projectRoot, relativePath, undefined, snapshot);
351
362
  if (!file)
352
363
  continue;
353
364
  const bytes = Buffer.byteLength(file.content, 'utf8');
@@ -355,11 +366,32 @@ const collectSetupFiles = (projectRoot, projectType, dynamicExpoConfigFile) => {
355
366
  if (isRequiredPatchableSetupFile(relativePath)) {
356
367
  throw setupContextLimitError(relativePath, `including it would exceed the ${MAX_TOTAL_BYTES}-byte total context limit`);
357
368
  }
369
+ snapshot?.delete(relativePath);
358
370
  continue;
359
371
  }
360
372
  totalBytes += bytes;
361
373
  files.push(file);
362
374
  }
375
+ if (nativeContext) {
376
+ for (const source of nativeContext.sources) {
377
+ const file = readSetupFile(projectRoot, source.path, source.kind, snapshot);
378
+ if (!file)
379
+ throw setupContextLimitError(source.path, 'it changed during discovery');
380
+ totalBytes += Buffer.byteLength(file.content, 'utf8');
381
+ if (totalBytes > MAX_TOTAL_BYTES) {
382
+ throw setupContextLimitError(file.path, 'the native setup context exceeds the size limit');
383
+ }
384
+ files.push(file);
385
+ }
386
+ for (const { path, content } of nativeContext.support) {
387
+ const bytes = Buffer.byteLength(content, 'utf8');
388
+ if (totalBytes + bytes > MAX_TOTAL_BYTES)
389
+ continue;
390
+ assertSafeAiSetupContent(path, content);
391
+ files.push({ kind: 'native_support', path, content, sha256: sha256(content) });
392
+ totalBytes += bytes;
393
+ }
394
+ }
363
395
  return files;
364
396
  };
365
397
  const readPackageSignals = (projectRoot) => {
@@ -383,9 +415,9 @@ const resolveInstalledPackageVersion = (projectRoot, packageName) => {
383
415
  return null;
384
416
  }
385
417
  };
386
- const detectSetupSignals = (projectRoot, projectType, files) => {
418
+ const detectSetupSignals = (projectRoot, projectType, files, nativePlanningV2) => {
387
419
  const { pkg, dependencies } = readPackageSignals(projectRoot);
388
- const content = files.map(file => file.content).join('\n');
420
+ const content = nativePlanningV2 ? '' : files.map(file => file.content).join('\n');
389
421
  const expoVersion = dependencies.expo || null;
390
422
  const hasBundleDropDependency = Boolean(dependencies['@gfean/react-native-bundle-drop'] || dependencies['react-native-bundle-drop']);
391
423
  const hasBundleDropConfig = files.some(file => file.kind === 'bundle_drop_config');
@@ -397,14 +429,16 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
397
429
  const nativeEntrypoints = files.filter(file => file.kind === 'android_entrypoint' || file.kind === 'ios_entrypoint');
398
430
  const androidEntrypoints = nativeEntrypoints.filter(file => file.kind === 'android_entrypoint');
399
431
  const iosEntrypoints = nativeEntrypoints.filter(file => file.kind === 'ios_entrypoint');
400
- const hasAndroidDirectory = (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'android');
401
- const hasIosDirectory = (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'ios');
402
- const hasBareNativeIntegration = (hasAndroidDirectory || hasIosDirectory) &&
432
+ const hasAndroidDirectory = nativePlanningV2
433
+ ? androidEntrypoints.length > 0 : (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'android');
434
+ const hasIosDirectory = nativePlanningV2
435
+ ? iosEntrypoints.length > 0 : (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'ios');
436
+ const hasBareNativeIntegration = !nativePlanningV2 && ((hasAndroidDirectory || hasIosDirectory) &&
403
437
  (!hasAndroidDirectory || androidEntrypoints.length === 1) &&
404
438
  (!hasIosDirectory || iosEntrypoints.length === 1) &&
405
439
  nativeEntrypoints.every(file => file.kind === 'android_entrypoint'
406
440
  ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(file.content)
407
- : (0, native_setup_contract_1.hasBareIosStartupIntegration)(file.path, file.content));
441
+ : (0, native_setup_contract_1.hasBareIosStartupIntegration)(file.path, file.content)));
408
442
  const hasBundleDropIntegration = projectType === 'expo'
409
443
  ? hasBundleDropExpoPlugin
410
444
  : hasBareNativeIntegration;
@@ -414,6 +448,7 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
414
448
  : /(?:["']jsEngine["']|\bjsEngine)\s*:\s*["']hermes["']/.test(content)
415
449
  ? 'hermes'
416
450
  : 'unknown';
451
+ const declaresCodePush = Boolean(dependencies['react-native-code-push']);
417
452
  const signals = [
418
453
  projectType === 'expo' ? 'expoProject' : 'bareProject',
419
454
  hasIosDirectory ? 'iosDirectory' : '',
@@ -421,7 +456,7 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
421
456
  expoUpdatesOwnership.packageIsInstalled || expoUpdatesOwnership.packageIsDeclared
422
457
  ? 'expoUpdatesDependency'
423
458
  : '',
424
- dependencies['react-native-code-push'] ? 'codePushDependency' : '',
459
+ declaresCodePush ? 'codePushDependency' : '',
425
460
  pkg.main === 'expo-router/entry' || dependencies['expo-router'] ? 'expoRouter' : '',
426
461
  hasBundleDropExpoPlugin ? 'expoBundleDropPlugin' : '',
427
462
  ].filter(Boolean);
@@ -431,14 +466,16 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
431
466
  expoSdkVersion: projectType === 'expo'
432
467
  ? resolveInstalledPackageVersion(projectRoot, 'expo') || expoVersion
433
468
  : null,
434
- bundleDropStatus: hasBundleDropDependency && hasBundleDropConfig && hasBundleDropIntegration
435
- ? 'configured'
436
- : 'partial',
469
+ bundleDropStatus: nativePlanningV2 && !hasBundleDropDependency && !hasBundleDropConfig
470
+ ? 'absent'
471
+ : hasBundleDropDependency && hasBundleDropConfig && hasBundleDropIntegration
472
+ ? 'configured'
473
+ : 'partial',
437
474
  hasNativeDirectories: hasIosDirectory || hasAndroidDirectory,
438
475
  usesExpoRouter: Boolean(pkg.main === 'expo-router/entry' || dependencies['expo-router']),
439
476
  jsEngine: configuredEngine,
440
477
  expoUpdatesStatus: expoUpdatesOwnership.state,
441
- codePushDetected: Boolean(dependencies['react-native-code-push'] || /\bCodePush\b|codepush\.gradle/.test(content)),
478
+ codePushDetected: Boolean(declaresCodePush || /\bCodePush\b|codepush\.gradle/.test(content)),
442
479
  signals,
443
480
  };
444
481
  if (projectType === 'expo') {
@@ -451,8 +488,7 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
451
488
  }
452
489
  return detected;
453
490
  };
454
- function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualConfig) {
455
- const projectRoot = findProjectRoot(startDir);
491
+ function readAiSetupConnection(projectRoot, virtualConfig) {
456
492
  const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
457
493
  const configFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'bundle.drop.config.js');
458
494
  if (!configFile.exists && !virtualConfig) {
@@ -472,6 +508,11 @@ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualCon
472
508
  if (!(0, exports.isTrustedAiPlanningServer)(serverUrl)) {
473
509
  throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}.`);
474
510
  }
511
+ return { serverUrl, orgSlug, projectSlug, authToken: virtualConfig?.authToken || readAuthToken() };
512
+ }
513
+ function buildSetupScan(projectType, projectRoot, virtualConfig, iosSceneEntrypoint, nativeContext) {
514
+ const snapshot = nativeContext?.snapshot;
515
+ const { serverUrl, orgSlug, projectSlug, authToken } = readAiSetupConnection(projectRoot, virtualConfig);
475
516
  if (projectType === 'expo') {
476
517
  for (const relativePath of ['package.json', 'app.json', ...SETUP_CONFIG_FILES.filter(file => file.startsWith('app.config.'))]) {
477
518
  (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath);
@@ -485,9 +526,11 @@ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualCon
485
526
  throw new Error('Expo config evaluation did not identify the authoritative dynamic app.config.* file. ' +
486
527
  'No context was shared and no files were changed.');
487
528
  }
488
- const files = collectSetupFiles(projectRoot, projectType, dynamicExpoConfigFile);
489
- if (projectType === 'bare') {
529
+ const files = collectSetupFiles(projectRoot, projectType, dynamicExpoConfigFile, iosSceneEntrypoint, nativeContext);
530
+ if (projectType === 'bare' && !snapshot) {
490
531
  for (const platform of ['android', 'ios']) {
532
+ if (platform === 'ios' && iosSceneEntrypoint)
533
+ continue;
491
534
  const kind = platform === 'android' ? 'android_entrypoint' : 'ios_entrypoint';
492
535
  const entrypoints = files.filter(file => file.kind === kind).map(file => file.path);
493
536
  if (entrypoints.length > 1)
@@ -501,6 +544,7 @@ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualCon
501
544
  }
502
545
  }
503
546
  if (virtualConfig && !files.some(file => file.kind === 'bundle_drop_config')) {
547
+ snapshot?.set('bundle.drop.config.js', null);
504
548
  const summarizedConfig = summarizeContextContent('bundle.drop.config.js', virtualConfig.content, Buffer.byteLength(virtualConfig.content, 'utf8'));
505
549
  files.push({
506
550
  kind: 'bundle_drop_config',
@@ -514,14 +558,36 @@ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualCon
514
558
  serverUrl,
515
559
  orgSlug,
516
560
  projectSlug,
517
- authToken: virtualConfig?.authToken || readAuthToken(),
561
+ authToken,
518
562
  request: {
519
563
  schemaVersion: 1,
520
564
  orgSlug,
521
565
  projectSlug,
522
566
  projectType,
523
- detected: detectSetupSignals(projectRoot, projectType, files),
567
+ detected: detectSetupSignals(projectRoot, projectType, files, Boolean(snapshot)),
524
568
  files,
525
569
  },
526
570
  };
527
571
  }
572
+ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualConfig, iosSceneEntrypoint) {
573
+ return buildSetupScan(projectType, findProjectRoot(startDir), virtualConfig, iosSceneEntrypoint);
574
+ }
575
+ async function scanProjectForAiSetupV2(projectRoot, virtualConfig) {
576
+ const nativeContext = await (0, native_setup_context_1.collectNativeSetupContext)(projectRoot);
577
+ const snapshot = new Map(nativeContext.metadataSnapshot);
578
+ const scan = buildSetupScan('bare', projectRoot, virtualConfig, undefined, { ...nativeContext, snapshot });
579
+ const nativeEditPaths = scan.request.files
580
+ .filter(file => file.kind === 'android_entrypoint' || file.kind === 'ios_entrypoint')
581
+ .map(file => file.path);
582
+ return {
583
+ ...scan,
584
+ snapshot,
585
+ nativeInventory: nativeContext.inventory,
586
+ request: {
587
+ ...scan.request,
588
+ schemaVersion: 2,
589
+ projectType: 'bare',
590
+ nativeEditPaths,
591
+ },
592
+ };
593
+ }
@@ -0,0 +1,3 @@
1
+ import type { AiPatchPlan, AiSetupPlanResponse, AiSetupScannerResultV2 } from './types';
2
+ export declare function verifyNativeSetupPlan(scan: AiSetupScannerResultV2, plan: AiSetupPlanResponse): Set<string>;
3
+ export declare function assertNativeSetupSnapshot(scan: AiSetupScannerResultV2, changes?: AiPatchPlan[], packageWasMigrated?: boolean): void;
@@ -0,0 +1,53 @@
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.verifyNativeSetupPlan = verifyNativeSetupPlan;
7
+ exports.assertNativeSetupSnapshot = assertNativeSetupSnapshot;
8
+ const node_crypto_1 = __importDefault(require("node:crypto"));
9
+ const safe_file_transaction_1 = require("../safe-file-transaction");
10
+ const native_setup_context_1 = require("./native-setup-context");
11
+ const scanner_1 = require("./scanner");
12
+ const PLAN_KEYS = ['confidence', 'summary', 'actions', 'changes', 'warnings'];
13
+ function verifyNativeSetupPlan(scan, plan) {
14
+ if (Object.keys(plan).length !== PLAN_KEYS.length ||
15
+ !PLAN_KEYS.every(key => Object.prototype.hasOwnProperty.call(plan, key)) ||
16
+ (plan.confidence === 'low' && plan.changes.length)) {
17
+ throw new Error('AI setup returned an invalid native plan. No files changed.');
18
+ }
19
+ const eligible = new Set(scan.request.nativeEditPaths);
20
+ const originals = new Map(scan.request.files.map(file => [file.path, file]));
21
+ const writes = new Set();
22
+ for (const change of plan.changes) {
23
+ const original = originals.get(change.file);
24
+ if (!eligible.has(change.file) || !original || writes.has(change.file) ||
25
+ change.originalSha256 !== original.sha256 ||
26
+ change.decisionType !== 'review_only_patch' || change.confidence === 'low' ||
27
+ change.updated === original.content || Buffer.byteLength(change.updated, 'utf8') > scanner_1.MAX_SETUP_FILE_BYTES ||
28
+ (0, scanner_1.findCredentialLikeLiteral)(change.updated)) {
29
+ throw new Error('AI setup returned a native edit outside the consented files or with invalid content. No files changed.');
30
+ }
31
+ writes.add(change.file);
32
+ }
33
+ return writes;
34
+ }
35
+ const sha256 = (contents) => node_crypto_1.default.createHash('sha256').update(contents).digest('hex');
36
+ function assertNativeSetupSnapshot(scan, changes = [], packageWasMigrated = false) {
37
+ const { projectRoot, snapshot, nativeInventory: expectedNative } = scan;
38
+ const currentNative = (0, native_setup_context_1.listNativeSetupContext)(projectRoot).map(file => file.path);
39
+ if (expectedNative.length !== currentNative.length ||
40
+ currentNative.some((file, index) => file !== expectedNative[index])) {
41
+ throw new Error('Native setup files changed during review. Rerun setup with the current project.');
42
+ }
43
+ const updates = new Map(changes.map(change => [change.file, sha256(change.updated)]));
44
+ for (const [file, originalHash] of snapshot) {
45
+ if (file === 'package.json' && packageWasMigrated)
46
+ continue;
47
+ const current = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file);
48
+ const currentHash = current.exists ? sha256(current.content) : null;
49
+ if (currentHash !== (updates.get(file) ?? originalHash)) {
50
+ throw new Error(`AI setup file changed during the transaction: ${file}. Rerun setup with the current project.`);
51
+ }
52
+ }
53
+ }
@@ -9,7 +9,7 @@ export type AiPatchPlan = {
9
9
  decisionType: AiSetupDecisionType;
10
10
  };
11
11
  export type AiSetupProjectType = 'expo' | 'bare';
12
- export type AiSetupFileKind = 'package_manifest' | 'bundle_drop_config' | 'expo_app_config' | 'metro_config' | 'android_entrypoint' | 'ios_entrypoint';
12
+ export type AiSetupFileKind = 'package_manifest' | 'bundle_drop_config' | 'expo_app_config' | 'metro_config' | 'android_entrypoint' | 'ios_entrypoint' | 'native_support';
13
13
  export type AiSetupDetected = {
14
14
  rnVersion: string | null;
15
15
  expoSdkVersion: string | null;
@@ -47,6 +47,11 @@ export type AiSetupPlanResponse = {
47
47
  changes: AiPatchPlan[];
48
48
  warnings: string[];
49
49
  };
50
+ export type AiSetupPlanRequestV2 = Omit<AiSetupPlanRequest, 'schemaVersion' | 'projectType'> & {
51
+ schemaVersion: 2;
52
+ projectType: 'bare';
53
+ nativeEditPaths: string[];
54
+ };
50
55
  export type AiSetupScannerResult = {
51
56
  projectRoot: string;
52
57
  serverUrl: string;
@@ -55,3 +60,8 @@ export type AiSetupScannerResult = {
55
60
  authToken: string;
56
61
  request: AiSetupPlanRequest;
57
62
  };
63
+ export type AiSetupScannerResultV2 = Omit<AiSetupScannerResult, 'request'> & {
64
+ request: AiSetupPlanRequestV2;
65
+ snapshot: ReadonlyMap<string, string | null>;
66
+ nativeInventory: readonly string[];
67
+ };
@@ -1,13 +1,14 @@
1
1
  import { AiPatchPlan } from './types';
2
2
  import { AiSetupProjectType } from './types';
3
3
  export declare const isSafeRelativePath: (value: string) => boolean;
4
- export declare const isPatchableNativeEntrypoint: (filePath: string) => boolean;
4
+ export declare const isPatchableNativeEntrypoint: (filePath: string, iosSceneEntrypoint?: string) => boolean;
5
5
  export declare const isPatchableExpoConfig: (filePath: string) => boolean;
6
6
  export declare function validateSetupChangesBeforeApply(params: {
7
7
  projectType: AiSetupProjectType;
8
8
  originals: Map<string, string>;
9
9
  changes: AiPatchPlan[];
10
10
  migrateExpoUpdates?: boolean;
11
+ iosSceneEntrypoint?: string;
11
12
  }): void;
12
13
  export declare function validateAppliedSetupChanges(params: {
13
14
  projectRoot: string;
@@ -15,4 +16,5 @@ export declare function validateAppliedSetupChanges(params: {
15
16
  changes: AiPatchPlan[];
16
17
  migrateExpoUpdates?: boolean;
17
18
  originals?: Map<string, string>;
19
+ iosSceneEntrypoint?: string;
18
20
  }): void;
@@ -19,8 +19,10 @@ const isSafeRelativePath = (value) => {
19
19
  return normalized === value && !normalized.split('/').includes('..');
20
20
  };
21
21
  exports.isSafeRelativePath = isSafeRelativePath;
22
- const isPatchableNativeEntrypoint = (filePath) => /(^|\/)android\/(?:.*\/)?MainApplication\.(kt|java)$/.test(filePath) ||
23
- /(^|\/)ios\/(?:.*\/)?AppDelegate\.(swift|m|mm)$/.test(filePath);
22
+ const isPatchableNativeEntrypoint = (filePath, iosSceneEntrypoint) => /(^|\/)android\/(?:.*\/)?MainApplication\.(kt|java)$/.test(filePath) ||
23
+ (iosSceneEntrypoint
24
+ ? filePath === iosSceneEntrypoint && /^ios\/(?:.*\/)?SceneDelegate\.swift$/.test(filePath)
25
+ : /(^|\/)ios\/(?:.*\/)?AppDelegate\.(swift|m|mm)$/.test(filePath));
24
26
  exports.isPatchableNativeEntrypoint = isPatchableNativeEntrypoint;
25
27
  const isPatchableExpoConfig = (filePath) => filePath === 'app.json' ||
26
28
  /^app\.config\.(js|ts|cjs|mjs)$/.test(filePath) ||
@@ -1121,7 +1123,7 @@ function validateSetupChangesBeforeApply(params) {
1121
1123
  }
1122
1124
  continue;
1123
1125
  }
1124
- if (!(0, exports.isPatchableNativeEntrypoint)(change.file)) {
1126
+ if (!(0, exports.isPatchableNativeEntrypoint)(change.file, params.iosSceneEntrypoint)) {
1125
1127
  throw new Error(`AI bare setup may not modify ${change.file}`);
1126
1128
  }
1127
1129
  if (change.decisionType !== 'review_only_patch') {
@@ -1130,7 +1132,7 @@ function validateSetupChangesBeforeApply(params) {
1130
1132
  if (change.file.includes('MainApplication.') && !hasAndroidBundleDropIntegration(change.updated)) {
1131
1133
  throw new Error(`AI plan Android update does not contain BundleDrop resolver: ${change.file}`);
1132
1134
  }
1133
- if (change.file.includes('AppDelegate.') &&
1135
+ if (/(^|\/)ios\//.test(change.file) &&
1134
1136
  !hasIosBundleDropIntegration(change.file, change.updated)) {
1135
1137
  throw new Error(`AI plan iOS update does not contain BundleDrop locator: ${change.file}`);
1136
1138
  }
@@ -1157,6 +1159,9 @@ function validateAppliedSetupChanges(params) {
1157
1159
  .filter(file => platform === 'android'
1158
1160
  ? file.includes('/android/') || file.startsWith('android/')
1159
1161
  : file.includes('/ios/') || file.startsWith('ios/'));
1162
+ if (platform === 'ios' && params.iosSceneEntrypoint && entrypoints.length === 1 &&
1163
+ entrypoints[0] === params.iosSceneEntrypoint)
1164
+ continue;
1160
1165
  const authorityIssue = (0, native_entrypoint_authority_1.findNativeEntrypointAuthorityIssue)(params.projectRoot, platform, entrypoints);
1161
1166
  if (authorityIssue) {
1162
1167
  throw new Error(`Applied ${platform} entrypoint authority is invalid: ${authorityIssue}`);
@@ -1165,6 +1170,7 @@ function validateAppliedSetupChanges(params) {
1165
1170
  }
1166
1171
  validateSetupChangesBeforeApply({
1167
1172
  projectType: params.projectType,
1173
+ iosSceneEntrypoint: params.iosSceneEntrypoint,
1168
1174
  originals,
1169
1175
  migrateExpoUpdates: params.migrateExpoUpdates,
1170
1176
  changes: params.changes.map(change => ({
@@ -430,15 +430,27 @@ const checkBareRuntimeIdentity = (projectRoot, platform) => {
430
430
  };
431
431
  }
432
432
  };
433
- const checkBareStartupIntegration = (projectRoot, platform) => {
433
+ const checkBareStartupIntegration = async (projectRoot, platform) => {
434
434
  const nativeRoot = path_1.default.join(projectRoot, platform);
435
435
  const entrypointNames = platform === 'android'
436
436
  ? ['MainApplication.kt', 'MainApplication.java']
437
437
  : ['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'];
438
438
  const entrypoints = entrypointNames.flatMap(name => findFiles(nativeRoot, name));
439
- const relativeEntrypoints = entrypoints.map(filePath => path_1.default.relative(projectRoot, filePath).split(path_1.default.sep).join('/'));
440
439
  let authorityIssue = null;
441
440
  try {
441
+ const scene = platform === 'ios' ? await (0, native_entrypoint_authority_1.findBareIosSceneEntrypoint)(projectRoot) : null;
442
+ if (scene) {
443
+ const file = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, scene);
444
+ const integrated = (0, native_setup_contract_1.hasBareIosStartupIntegration)(scene, file.content);
445
+ return {
446
+ name: 'ios OTA startup ownership',
447
+ status: integrated ? 'pass' : 'error',
448
+ message: integrated
449
+ ? 'The iOS scene delegate asks Bundle Drop for the cold-start bundle.'
450
+ : 'The iOS scene delegate does not hand cold-start bundle resolution to Bundle Drop.',
451
+ };
452
+ }
453
+ const relativeEntrypoints = entrypoints.map(filePath => path_1.default.relative(projectRoot, filePath).split(path_1.default.sep).join('/'));
442
454
  authorityIssue = (0, native_entrypoint_authority_1.findNativeEntrypointAuthorityIssue)(projectRoot, platform, relativeEntrypoints);
443
455
  }
444
456
  catch (error) {
@@ -447,7 +459,7 @@ const checkBareStartupIntegration = (projectRoot, platform) => {
447
459
  const hasIntegration = entrypoints.length === 1 && entrypoints.every(filePath => {
448
460
  const content = fs_1.default.readFileSync(filePath, 'utf8');
449
461
  return platform === 'android'
450
- ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(content)
462
+ ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(content, { checkInlineReactHost: true })
451
463
  : (0, native_setup_contract_1.hasBareIosStartupIntegration)(filePath, content);
452
464
  }) && !authorityIssue;
453
465
  return {
@@ -505,7 +517,7 @@ const checkBareNativeAutolinking = (projectRoot, platform) => {
505
517
  : 'Generated Android autolinking exists but does not include BundleDropPackage; rebuild Android.',
506
518
  };
507
519
  };
508
- function inspectBareProject(projectRoot, platforms) {
520
+ async function inspectBareProject(projectRoot, platforms) {
509
521
  const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
510
522
  const metro = inspectMetroConfig(projectRoot);
511
523
  const hasBareMetroWrapper = !metro.issue &&
@@ -530,7 +542,7 @@ function inspectBareProject(projectRoot, platforms) {
530
542
  ];
531
543
  for (const platform of platforms) {
532
544
  checks.push(checkBareRuntimeIdentity(projectRoot, platform));
533
- checks.push(checkBareStartupIntegration(projectRoot, platform));
545
+ checks.push(await checkBareStartupIntegration(projectRoot, platform));
534
546
  checks.push(checkBareNativeAutolinking(projectRoot, platform));
535
547
  }
536
548
  return checks;
@@ -544,7 +556,7 @@ async function inspectProject(options = {}) {
544
556
  const platforms = options.platform ? [options.platform] : ['ios', 'android'];
545
557
  const checks = projectType === 'expo'
546
558
  ? await inspectExpoProject(projectRoot, platforms)
547
- : inspectBareProject(projectRoot, platforms);
559
+ : await inspectBareProject(projectRoot, platforms);
548
560
  return { projectRoot, projectType, checks };
549
561
  }
550
562
  async function runDoctor(options = {}) {