@gfean/react-native-bundle-drop 0.5.1 → 0.7.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 (127) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +194 -5
  3. package/android/build.gradle +66 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  8. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  9. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  10. package/ios/BundleDropBridge.m +45 -0
  11. package/ios/BundleDropLocator.swift +66 -4
  12. package/ios/BundleDropModule.swift +181 -3
  13. package/ios/BundleDropOtaResolver.swift +137 -29
  14. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  15. package/ios/BundleDropStartupRecovery.swift +1108 -0
  16. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  17. package/lib/CLI/cli.d.ts +1 -0
  18. package/lib/CLI/cli.js +57 -6
  19. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  20. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  21. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  22. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  23. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  24. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  25. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  29. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  30. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  31. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  33. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  34. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  35. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  36. package/lib/CLI/scripts/doctor.js +162 -22
  37. package/lib/CLI/scripts/expo/configure-expo.js +52 -60
  38. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  39. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  40. package/lib/CLI/scripts/init-config.d.ts +7 -7
  41. package/lib/CLI/scripts/init-config.js +198 -14
  42. package/lib/CLI/scripts/login-cli.js +31 -7
  43. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  44. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  45. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  46. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  47. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  48. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  49. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  50. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  51. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  52. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  53. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  54. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  55. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  56. package/lib/CLI/scripts/upload-cli.js +74 -11
  57. package/lib/CLI/serverUrl.d.ts +3 -0
  58. package/lib/CLI/serverUrl.js +31 -0
  59. package/lib/api/clientApi.d.ts +3 -1
  60. package/lib/api/clientApi.js +14 -0
  61. package/lib/api/types.d.ts +39 -0
  62. package/lib/bundleInfo.d.ts +2 -0
  63. package/lib/bundleInfo.js +16 -1
  64. package/lib/context.d.ts +1 -1
  65. package/lib/context.js +12 -2
  66. package/lib/fs/bundlePointer.d.ts +1 -17
  67. package/lib/fs/bundlePointer.js +5 -93
  68. package/lib/index.d.ts +2 -0
  69. package/lib/index.js +3 -1
  70. package/lib/install/bundleInstallShared.js +4 -4
  71. package/lib/install/installFromZip.d.ts +3 -0
  72. package/lib/install/installFromZip.js +10 -1
  73. package/lib/loadConfig.d.ts +17 -1
  74. package/lib/loadConfig.js +16 -0
  75. package/lib/manager/downloadAndInstall.d.ts +3 -2
  76. package/lib/manager/downloadAndInstall.js +134 -66
  77. package/lib/manager/reporting.d.ts +8 -1
  78. package/lib/manager/reporting.js +17 -22
  79. package/lib/manager/rollbackState.d.ts +18 -52
  80. package/lib/manager/rollbackState.js +115 -216
  81. package/lib/manager/updateCheck.d.ts +1 -0
  82. package/lib/manager/updateCheck.js +224 -78
  83. package/lib/manager/updateState.d.ts +2 -1
  84. package/lib/manager/updateState.js +59 -6
  85. package/lib/metro.d.ts +8 -1
  86. package/lib/metro.js +69 -19
  87. package/lib/native/bundleDropNative.d.ts +62 -0
  88. package/lib/native/bundleDropNative.js +268 -2
  89. package/lib/native/fs.d.ts +6 -0
  90. package/lib/native/fs.js +24 -0
  91. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  92. package/lib/patch-engine/installFromPatchSet.js +16 -5
  93. package/lib/patch-engine/patchTransport.d.ts +2 -0
  94. package/lib/patch-engine/patchTransport.js +9 -0
  95. package/lib/runtime/initState.d.ts +5 -0
  96. package/lib/runtime/initState.js +4 -0
  97. package/lib/runtime/service.js +82 -67
  98. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  99. package/lib/runtime-delivery/artifactCapability.js +32 -0
  100. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  101. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  102. package/lib/runtime-delivery/bootstrapConfig.d.ts +68 -0
  103. package/lib/runtime-delivery/bootstrapConfig.js +278 -0
  104. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  105. package/lib/runtime-delivery/diagnostics.js +58 -0
  106. package/lib/runtime-delivery/encoding.d.ts +5 -0
  107. package/lib/runtime-delivery/encoding.js +132 -0
  108. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  109. package/lib/runtime-delivery/heartbeat.js +88 -0
  110. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  111. package/lib/runtime-delivery/localResolver.js +81 -0
  112. package/lib/runtime-delivery/manifestState.d.ts +11 -0
  113. package/lib/runtime-delivery/manifestState.js +123 -0
  114. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  115. package/lib/runtime-delivery/manifestVerifier.js +335 -0
  116. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  117. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  118. package/lib/runtime-delivery/types.d.ts +87 -0
  119. package/lib/runtime-delivery/types.js +6 -0
  120. package/lib/scripts/bundle.d.ts +9 -2
  121. package/lib/scripts/bundle.js +68 -18
  122. package/lib/scripts/download-bundle.d.ts +1 -0
  123. package/lib/scripts/download-bundle.js +2 -2
  124. package/lib/scripts/resolveModule.d.ts +2 -0
  125. package/lib/scripts/resolveModule.js +5 -0
  126. package/package.json +5 -2
  127. package/plugin/xcodeBuildPhase.js +2 -1
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findKnownBundleDropCredential = void 0;
4
+ const BUNDLE_DROP_PROJECT_KEY = /\bbdp_proj_[A-Za-z0-9_-]{32,}\b/;
5
+ const BUNDLE_DROP_PERSONAL_ACCESS_TOKEN = /\bbdp_pat_[A-Za-z0-9_-]{32,}\b/;
6
+ const findKnownBundleDropCredential = (value) => {
7
+ if (BUNDLE_DROP_PROJECT_KEY.test(value))
8
+ return 'Bundle Drop project key';
9
+ if (BUNDLE_DROP_PERSONAL_ACCESS_TOKEN.test(value)) {
10
+ return 'Bundle Drop personal access token';
11
+ }
12
+ return null;
13
+ };
14
+ exports.findKnownBundleDropCredential = findKnownBundleDropCredential;
@@ -7,16 +7,24 @@ exports.buildUnifiedDiff = buildUnifiedDiff;
7
7
  exports.colorizeUnifiedDiff = colorizeUnifiedDiff;
8
8
  const diff_1 = require("diff");
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
+ const terminal_safety_1 = require("./terminal-safety");
11
+ const BUNDLE_DROP_CONFIG_PATH = /^bundle\.drop\.config\.(js|cjs)$/;
12
+ const API_KEY_LITERAL = /(\bapiKey\s*:\s*)(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
13
+ const redactPreviewSecrets = (file, content) => BUNDLE_DROP_CONFIG_PATH.test(file)
14
+ ? content.replace(API_KEY_LITERAL, '$1"<redacted>"')
15
+ : content;
10
16
  function buildUnifiedDiff(params) {
11
- return params.changes
17
+ const diff = params.changes
12
18
  .map(change => {
13
- const original = params.originals.get(change.file) ?? '';
14
- return (0, diff_1.createTwoFilesPatch)(`a/${change.file}`, `b/${change.file}`, original, change.updated, '', '', { context: 3 });
19
+ const original = redactPreviewSecrets(change.file, params.originals.get(change.file) ?? '');
20
+ const updated = redactPreviewSecrets(change.file, change.updated);
21
+ return (0, diff_1.createTwoFilesPatch)(`a/${change.file}`, `b/${change.file}`, original, updated, '', '', { context: 3 });
15
22
  })
16
23
  .join('\n');
24
+ return (0, terminal_safety_1.escapeTerminalControls)(diff);
17
25
  }
18
26
  function colorizeUnifiedDiff(diff) {
19
- return diff
27
+ return (0, terminal_safety_1.escapeTerminalControls)(diff)
20
28
  .split('\n')
21
29
  .map(line => {
22
30
  if (line.startsWith('+++') || line.startsWith('---'))
@@ -2,6 +2,7 @@ import type { ProjectType } from '../../../expo';
2
2
  export type InitProjectOptions = {
3
3
  projectType?: ProjectType;
4
4
  dryRun?: boolean;
5
+ migrateCodePush?: boolean;
5
6
  migrateExpoUpdates?: boolean;
6
7
  prebuild?: boolean;
7
8
  yes?: boolean;
@@ -12,6 +13,9 @@ export type InitProjectOptions = {
12
13
  projectSlug: string;
13
14
  authToken: string;
14
15
  };
16
+ runtimeDeliveryBootstrap?: {
17
+ content: string;
18
+ };
15
19
  };
16
20
  export declare function initProjectConfigAi(options?: InitProjectOptions): Promise<void>;
17
21
  export default initProjectConfigAi;
@@ -17,16 +17,93 @@ const configure_expo_1 = require("../expo/configure-expo");
17
17
  const package_manager_1 = require("../expo/package-manager");
18
18
  const apply_setup_plan_1 = require("./apply-setup-plan");
19
19
  const backend_client_1 = require("./backend-client");
20
+ const code_push_residue_1 = require("./code-push-residue");
20
21
  const diff_preview_1 = require("./diff-preview");
22
+ const terminal_safety_1 = require("./terminal-safety");
21
23
  const scanner_1 = require("./scanner");
22
24
  const validate_plan_1 = require("./validate-plan");
23
25
  const ui_1 = require("../../utils/ui");
26
+ const safe_file_transaction_1 = require("../safe-file-transaction");
27
+ const bootstrapConfig_1 = require("../../../runtime-delivery/bootstrapConfig");
24
28
  const PACKAGE_NAME = '@gfean/react-native-bundle-drop';
25
29
  const DOCS_MANUAL_SETUP_URL = 'https://bundledrop.app/docs/manual-setup';
30
+ const DOCS_RUNTIME_INITIALIZATION_URL = 'https://bundledrop.app/docs/installation#initialize-bundle-drop-in-javascript';
26
31
  const EXPO_RUNTIME_AUTHORITY_PATTERN = /runtimeVersion\s*:\s*\{\s*source\s*:\s*['"]expo['"]\s*\}/;
32
+ const logRuntimeInitializationNextStep = () => {
33
+ console.log(chalk_1.default.cyan('JavaScript entry point: call BundleDrop.init once before rendering your app. ' +
34
+ DOCS_RUNTIME_INITIALIZATION_URL));
35
+ };
27
36
  const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
37
+ const inspectPlanningFile = (projectRoot, relativePath) => {
38
+ if (!fs_extra_1.default.existsSync(projectRoot))
39
+ return { exists: false, content: '', mode: 0o666 };
40
+ return (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath);
41
+ };
42
+ const planRuntimeDeliveryBootstrap = (projectRoot, bootstrap) => {
43
+ if (!bootstrap)
44
+ return null;
45
+ const bootstrapFile = inspectPlanningFile(projectRoot, bootstrapConfig_1.RUNTIME_DELIVERY_BOOTSTRAP_PATH);
46
+ const original = bootstrapFile.exists ? bootstrapFile.content : null;
47
+ if (original === bootstrap.content)
48
+ return null;
49
+ return {
50
+ file: bootstrapConfig_1.RUNTIME_DELIVERY_BOOTSTRAP_PATH,
51
+ original,
52
+ updated: bootstrap.content,
53
+ reason: 'Pin the authenticated runtime delivery bootstrap for this project.',
54
+ };
55
+ };
56
+ const planRuntimeDeliveryGitignore = (projectRoot, bootstrap) => {
57
+ if (!bootstrap)
58
+ return null;
59
+ const file = '.gitignore';
60
+ const gitignoreFile = inspectPlanningFile(projectRoot, file);
61
+ const original = gitignoreFile.exists ? gitignoreFile.content : null;
62
+ const updated = (0, bootstrapConfig_1.addRuntimeDeliveryBootstrapGitignoreRules)(original || '');
63
+ if (updated === original)
64
+ return null;
65
+ return {
66
+ file,
67
+ original,
68
+ updated,
69
+ reason: 'Keep the pinned runtime delivery bootstrap reproducible in clean builds.',
70
+ };
71
+ };
28
72
  const shouldApplyAiChange = (change) => change.confidence !== 'low' &&
29
73
  (change.decisionType === 'safe_auto_patch' || change.decisionType === 'review_only_patch');
74
+ const isDynamicExpoConfigChange = (change) => /^app\.config\.(?:js|ts|cjs|mjs)$/.test(change.file);
75
+ const reviewOnlyChanges = (changes) => changes.filter(change => change.confidence !== 'low' &&
76
+ (change.decisionType === 'review_only_patch' || isDynamicExpoConfigChange(change)));
77
+ async function confirmReviewOnlyChanges(params) {
78
+ const changesRequiringReview = reviewOnlyChanges(params.changes);
79
+ if (params.dryRun || !changesRequiringReview.length)
80
+ return true;
81
+ if (params.yes) {
82
+ console.log(chalk_1.default.yellow('Review-only AI changes require explicit interactive approval. ' +
83
+ '--yes cannot approve them. No files changed.'));
84
+ return false;
85
+ }
86
+ for (const change of changesRequiringReview) {
87
+ console.log(chalk_1.default.yellow(`\nReview-only proposed change: ${change.file}`));
88
+ console.log((0, diff_preview_1.colorizeUnifiedDiff)((0, diff_preview_1.buildUnifiedDiff)({
89
+ projectRoot: params.projectRoot,
90
+ originals: params.originals,
91
+ changes: [change],
92
+ })));
93
+ const answer = await (0, prompts_1.default)({
94
+ type: 'confirm',
95
+ name: 'approve',
96
+ message: `Apply this review-only AI change to ${(0, terminal_safety_1.escapeTerminalControls)(change.file)}? ` +
97
+ (0, terminal_safety_1.escapeTerminalControls)(change.reason),
98
+ initial: false,
99
+ });
100
+ if (!answer.approve) {
101
+ console.log(chalk_1.default.gray('Review-only AI change declined. No files changed.'));
102
+ return false;
103
+ }
104
+ }
105
+ return true;
106
+ }
30
107
  const hasCleanGitStatus = (projectRoot, command) => {
31
108
  try {
32
109
  const status = (0, child_process_1.execSync)(command, {
@@ -41,30 +118,37 @@ const hasCleanGitStatus = (projectRoot, command) => {
41
118
  }
42
119
  };
43
120
  const usesStrictExpoRuntimeAuthority = (projectRoot, virtualConfig) => {
44
- const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
45
- const configContent = fs_extra_1.default.existsSync(configPath)
46
- ? fs_extra_1.default.readFileSync(configPath, 'utf8')
121
+ const configFile = inspectPlanningFile(projectRoot, 'bundle.drop.config.js');
122
+ const configContent = configFile.exists
123
+ ? configFile.content
47
124
  : virtualConfig?.content;
48
125
  return Boolean(configContent && EXPO_RUNTIME_AUTHORITY_PATTERN.test(configContent));
49
126
  };
50
127
  const hasCleanGitWorktree = (projectRoot) => hasCleanGitStatus(projectRoot, 'git status --porcelain');
51
128
  const restoreNativePrebuild = (backup, reason) => {
129
+ const failedRoot = path_1.default.join(backup.backupDir, reason);
130
+ fs_extra_1.default.mkdirSync(failedRoot);
52
131
  for (const directory of ['ios', 'android']) {
53
132
  const current = path_1.default.join(backup.projectRoot, directory);
54
- const failed = path_1.default.join(backup.backupDir, reason, directory);
55
- if (fs_extra_1.default.existsSync(current)) {
56
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(failed));
57
- fs_extra_1.default.moveSync(current, failed, { overwrite: true });
133
+ const failed = path_1.default.join(failedRoot, directory);
134
+ try {
135
+ fs_extra_1.default.lstatSync(current);
136
+ fs_extra_1.default.renameSync(current, failed);
137
+ }
138
+ catch (error) {
139
+ if (error.code !== 'ENOENT')
140
+ throw error;
58
141
  }
59
142
  if (backup.existingDirectories.includes(directory)) {
143
+ (0, safe_file_transaction_1.inspectProjectDirectory)(backup.backupDir, directory);
60
144
  fs_extra_1.default.copySync(path_1.default.join(backup.backupDir, directory), current, { preserveTimestamps: true });
61
145
  }
62
146
  }
63
147
  };
64
148
  const runLayeredPrebuild = (projectRoot) => {
65
149
  const expoCli = require.resolve('expo/bin/cli', { paths: [projectRoot] });
66
- const backupDir = path_1.default.join(projectRoot, '.bundledrop-backup', `prebuild-${new Date().toISOString().replace(/[:.]/g, '-')}`);
67
- const existingDirectories = ['ios', 'android'].filter(directory => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, directory)));
150
+ const backupDir = (0, safe_file_transaction_1.createSafeBackupDirectory)(projectRoot, 'prebuild');
151
+ const existingDirectories = ['ios', 'android'].filter(directory => (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, directory));
68
152
  const backup = { projectRoot, backupDir, existingDirectories };
69
153
  for (const directory of existingDirectories) {
70
154
  fs_extra_1.default.copySync(path_1.default.join(projectRoot, directory), path_1.default.join(backupDir, directory), {
@@ -95,20 +179,10 @@ const assertBundleDropPluginPresent = (projectRoot) => {
95
179
  'For dynamic config, keep the AI-proposed app.config patch and try again.');
96
180
  }
97
181
  };
98
- const isSummarizedSetupContext = (kind) => kind === 'package_manifest' || kind === 'bundle_drop_config';
99
- const authoritativeDynamicExpoConfigFile = (projectRoot, candidate = (0, expo_1.evaluateExpoConfig)(projectRoot).dynamicConfigPath) => {
100
- if (typeof candidate !== 'string' || !candidate.trim()) {
101
- throw new Error('Expo did not identify the authoritative dynamic app config path. No files changed.');
102
- }
103
- const absolutePath = path_1.default.isAbsolute(candidate) ? candidate : path_1.default.resolve(projectRoot, candidate);
104
- const relativePath = path_1.default.relative(projectRoot, absolutePath).split(path_1.default.sep).join('/');
105
- if (relativePath.startsWith('../') ||
106
- path_1.default.isAbsolute(relativePath) ||
107
- !/^app\.config\.(js|ts|cjs|mjs)$/.test(relativePath)) {
108
- throw new Error(`Expo reported an unsafe dynamic app config path: ${candidate}. No files changed.`);
109
- }
110
- return relativePath;
111
- };
182
+ const isSummarizedSetupContext = (file) => file.kind === 'package_manifest' ||
183
+ file.kind === 'bundle_drop_config' ||
184
+ file.kind === 'metro_config' ||
185
+ file.path === 'app.json';
112
186
  const describeAiDestination = (serverUrl) => {
113
187
  const parsed = new URL(serverUrl);
114
188
  const isLocal = ['localhost', '127.0.0.1', '::1', '[::1]', '10.0.2.2'].includes(parsed.hostname);
@@ -121,9 +195,11 @@ const describeAiDestination = (serverUrl) => {
121
195
  };
122
196
  async function requestContextConsent(files, serverUrl, yes) {
123
197
  console.log(chalk_1.default.gray(`AI setup destination: ${describeAiDestination(serverUrl)}`));
198
+ const contextSize = files.reduce((total, file) => total + Buffer.byteLength(file.content, 'utf8'), 0);
199
+ console.log(chalk_1.default.gray(`Provider context size: ${contextSize} bytes.`));
124
200
  console.log(chalk_1.default.gray('Files proposed for AI setup planning:'));
125
201
  files.forEach(file => {
126
- const disclosure = isSummarizedSetupContext(file.kind) ? 'summary only' : 'full content';
202
+ const disclosure = isSummarizedSetupContext(file) ? 'summary only' : 'full content';
127
203
  console.log(chalk_1.default.gray(` - ${file.path} (${file.kind}, ${disclosure})`));
128
204
  });
129
205
  if (yes)
@@ -156,14 +232,32 @@ const existingSetupPassesDoctor = async (projectRoot, projectType, detected) =>
156
232
  return false;
157
233
  }
158
234
  };
235
+ const assertNoCodePushMigrationResidue = (projectRoot) => {
236
+ const residuePaths = (0, code_push_residue_1.findCodePushResiduePaths)(projectRoot);
237
+ if (!residuePaths.length)
238
+ return;
239
+ const displayedPaths = residuePaths.slice(0, 20).map(filePath => ` - ${filePath}`);
240
+ if (residuePaths.length > displayedPaths.length) {
241
+ displayedPaths.push(` - and ${residuePaths.length - displayedPaths.length} more path(s)`);
242
+ }
243
+ throw new Error('CodePush migration cannot continue while local CodePush references remain outside the ' +
244
+ `provider-patched native entrypoints:\n${displayedPaths.join('\n')}\n` +
245
+ 'Remove the listed JS wrappers/imports, custom native references, build hooks, and ' +
246
+ 'deployment-key configuration manually, then rerun Bundle Drop setup. No files changed.');
247
+ };
159
248
  async function initProjectConfigAi(options = {}) {
160
249
  const projectRoot = (0, scanner_1.findProjectRoot)(process.cwd());
161
250
  const projectType = (0, expo_1.detectProjectType)({ projectRoot, explicitType: options.projectType });
162
251
  const scan = (0, scanner_1.scanProjectForAiSetup)(projectType, projectRoot, options.virtualConfig);
252
+ const bootstrapChange = planRuntimeDeliveryBootstrap(projectRoot, options.runtimeDeliveryBootstrap);
253
+ const bootstrapGitignoreChange = planRuntimeDeliveryGitignore(projectRoot, options.runtimeDeliveryBootstrap);
163
254
  assertSetupOwnershipCompatible(projectType, scan.request.detected.expoUpdatesStatus);
164
- if (await existingSetupPassesDoctor(projectRoot, projectType, scan.request.detected)) {
255
+ if (!bootstrapChange &&
256
+ !bootstrapGitignoreChange &&
257
+ await existingSetupPassesDoctor(projectRoot, projectType, scan.request.detected)) {
165
258
  console.log(chalk_1.default.green('✅ Bundle Drop setup is already complete. No AI planning is required.'));
166
259
  await (0, doctor_1.runDoctor)({ projectType, cwd: projectRoot });
260
+ logRuntimeInitializationNextStep();
167
261
  return;
168
262
  }
169
263
  console.log(chalk_1.default.cyan(`🧠 Bundle Drop AI setup (${projectType})`));
@@ -183,18 +277,21 @@ async function initProjectConfigAi(options = {}) {
183
277
  finally {
184
278
  loading.stop();
185
279
  }
280
+ (0, terminal_safety_1.assertSafeProviderPlan)(plan);
186
281
  console.log(chalk_1.default.cyan('\nSetup summary:'));
187
- console.log(plan.summary);
188
- plan.warnings.forEach(warning => console.log(chalk_1.default.yellow(`⚠️ ${warning}`)));
282
+ console.log((0, terminal_safety_1.escapeTerminalControls)(plan.summary));
283
+ plan.warnings.forEach(warning => console.log(chalk_1.default.yellow(`⚠️ ${(0, terminal_safety_1.escapeTerminalControls)(warning)}`)));
189
284
  plan.actions.forEach(action => {
190
285
  const confirmation = action.requiresConfirmation ? ' (confirmation required)' : '';
191
- console.log(chalk_1.default.gray(` - ${action.type}${confirmation}: ${action.reason}`));
286
+ console.log(chalk_1.default.gray(` - ${(0, terminal_safety_1.escapeTerminalControls)(action.type)}${confirmation}: ` +
287
+ (0, terminal_safety_1.escapeTerminalControls)(action.reason)));
192
288
  });
193
289
  if (plan.confidence === 'low') {
194
290
  if (options.virtualConfig && !options.dryRun) {
195
- const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
196
- if (!fs_extra_1.default.existsSync(configPath)) {
197
- fs_extra_1.default.writeFileSync(configPath, options.virtualConfig.content, 'utf8');
291
+ const configFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'bundle.drop.config.js');
292
+ if (!configFile.exists) {
293
+ (0, safe_file_transaction_1.writeProjectFileAtomically)(projectRoot, 'bundle.drop.config.js', options.virtualConfig.content);
294
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
198
295
  console.log(chalk_1.default.green(`Project config retained at ${configPath}`));
199
296
  }
200
297
  }
@@ -217,13 +314,36 @@ async function initProjectConfigAi(options = {}) {
217
314
  'after reviewing the plan; a new native binary will be required.');
218
315
  }
219
316
  }
220
- for (const action of plan.actions.filter(action => action.requiresConfirmation && action.type !== 'migrate_expo_updates')) {
317
+ if (projectType === 'bare' && scan.request.detected.codePushDetected) {
318
+ if (!options.migrateCodePush && !options.yes) {
319
+ const migrationAnswer = await (0, prompts_1.default)({
320
+ type: 'confirm',
321
+ name: 'migrate',
322
+ message: 'Remove react-native-code-push and migrate native startup ownership to Bundle Drop?',
323
+ initial: false,
324
+ });
325
+ options.migrateCodePush = Boolean(migrationAnswer.migrate);
326
+ }
327
+ if (!options.migrateCodePush) {
328
+ throw new Error('CodePush blocks Bundle Drop setup. Re-run with --migrate-code-push after reviewing ' +
329
+ 'the plan; a new native binary will be required.');
330
+ }
331
+ }
332
+ const shouldMigrateCodePush = projectType === 'bare' &&
333
+ scan.request.detected.codePushDetected &&
334
+ Boolean(options.migrateCodePush);
335
+ if (shouldMigrateCodePush)
336
+ assertNoCodePushMigrationResidue(projectRoot);
337
+ for (const action of plan.actions.filter(action => action.requiresConfirmation &&
338
+ action.type !== 'migrate_expo_updates' &&
339
+ action.type !== 'migrate_codepush')) {
221
340
  if (options.yes)
222
341
  continue;
223
342
  const actionAnswer = await (0, prompts_1.default)({
224
343
  type: 'confirm',
225
344
  name: 'proceed',
226
- message: `Proceed with ${action.type}? ${action.reason}`,
345
+ message: `Proceed with ${(0, terminal_safety_1.escapeTerminalControls)(action.type)}? ` +
346
+ (0, terminal_safety_1.escapeTerminalControls)(action.reason),
227
347
  initial: false,
228
348
  });
229
349
  if (!actionAnswer.proceed) {
@@ -231,15 +351,29 @@ async function initProjectConfigAi(options = {}) {
231
351
  return;
232
352
  }
233
353
  }
234
- const aiChanges = plan.changes.filter(shouldApplyAiChange);
235
354
  const originals = new Map(scan.request.files.map(file => [file.path, file.content]));
236
- (0, validate_plan_1.validateSetupChangesBeforeApply)({ projectType, originals, changes: aiChanges });
355
+ if (!await confirmReviewOnlyChanges({
356
+ projectRoot,
357
+ originals,
358
+ changes: plan.changes,
359
+ yes: options.yes,
360
+ dryRun: options.dryRun,
361
+ })) {
362
+ return;
363
+ }
364
+ const aiChanges = plan.changes.filter(shouldApplyAiChange);
365
+ (0, validate_plan_1.validateSetupChangesBeforeApply)({
366
+ projectType,
367
+ originals,
368
+ changes: aiChanges,
369
+ migrateExpoUpdates: Boolean(options.migrateExpoUpdates),
370
+ });
237
371
  if (projectType === 'bare') {
238
372
  const metroChange = (0, bare_metro_config_1.planBareMetroConfig)(projectRoot);
239
- const bundleConfigPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
240
- const bundleConfigExists = fs_extra_1.default.existsSync(bundleConfigPath);
373
+ const bundleConfigFile = inspectPlanningFile(projectRoot, 'bundle.drop.config.js');
374
+ const bundleConfigExists = bundleConfigFile.exists;
241
375
  const bundleConfig = bundleConfigExists
242
- ? fs_extra_1.default.readFileSync(bundleConfigPath, 'utf8')
376
+ ? bundleConfigFile.content
243
377
  : options.virtualConfig?.content;
244
378
  const updatedBundleConfig = bundleConfig
245
379
  ? (0, configure_expo_1.setBundleDropProjectType)(bundleConfig, 'bare')
@@ -253,11 +387,18 @@ async function initProjectConfigAi(options = {}) {
253
387
  reason: 'Persist the reviewed bare React Native project type.',
254
388
  }
255
389
  : null;
256
- const localChanges = [metroChange, bundleConfigChange].filter((change) => Boolean(change));
257
- if (!aiChanges.length && !localChanges.length) {
390
+ const localChanges = [
391
+ metroChange,
392
+ bundleConfigChange,
393
+ bootstrapChange,
394
+ bootstrapGitignoreChange,
395
+ ].filter((change) => Boolean(change));
396
+ if (!aiChanges.length && !localChanges.length && !shouldMigrateCodePush) {
258
397
  console.log(chalk_1.default.gray('No bare native changes are required.'));
259
- if (!options.dryRun)
398
+ if (!options.dryRun) {
260
399
  await (0, doctor_1.runDoctor)({ projectType: 'bare', cwd: projectRoot });
400
+ logRuntimeInitializationNextStep();
401
+ }
261
402
  return;
262
403
  }
263
404
  const bareOriginals = new Map(originals);
@@ -279,6 +420,10 @@ async function initProjectConfigAi(options = {}) {
279
420
  originals: bareOriginals,
280
421
  changes: previewChanges,
281
422
  })));
423
+ if (shouldMigrateCodePush) {
424
+ const command = (0, package_manager_1.codePushRemovalCommand)((0, package_manager_1.detectPackageManager)(projectRoot));
425
+ console.log(chalk_1.default.yellow(`Dependency migration command: ${command.join(' ')}`));
426
+ }
282
427
  if (options.dryRun) {
283
428
  console.log(chalk_1.default.gray('Dry run complete. No files changed.'));
284
429
  return;
@@ -290,10 +435,21 @@ async function initProjectConfigAi(options = {}) {
290
435
  console.log(chalk_1.default.gray('No files changed.'));
291
436
  return;
292
437
  }
293
- const result = (0, apply_setup_plan_1.applySetupPatchPlans)({ projectRoot, projectType, changes: aiChanges });
438
+ let dependencyBackup;
439
+ let result;
294
440
  let metroResult;
295
441
  try {
296
- (0, validate_plan_1.validateAppliedSetupChanges)({ projectRoot, projectType, changes: aiChanges });
442
+ if (shouldMigrateCodePush) {
443
+ dependencyBackup = (0, package_manager_1.removeCodePushWithPackageManager)(projectRoot);
444
+ }
445
+ result = (0, apply_setup_plan_1.applySetupPatchPlans)({ projectRoot, projectType, changes: aiChanges });
446
+ (0, validate_plan_1.validateAppliedSetupChanges)({
447
+ projectRoot,
448
+ projectType,
449
+ changes: aiChanges,
450
+ migrateExpoUpdates: false,
451
+ originals,
452
+ });
297
453
  if (localChanges.length) {
298
454
  metroResult = (0, configure_expo_1.applyExpoConfigurationChanges)({
299
455
  projectRoot,
@@ -305,10 +461,18 @@ async function initProjectConfigAi(options = {}) {
305
461
  catch (error) {
306
462
  if (metroResult)
307
463
  (0, configure_expo_1.restoreExpoConfiguration)(metroResult);
308
- (0, apply_setup_plan_1.restoreSetupBackups)(result);
464
+ if (result)
465
+ (0, apply_setup_plan_1.restoreSetupBackups)(result);
466
+ if (dependencyBackup) {
467
+ (0, package_manager_1.restoreDependencyMigration)(dependencyBackup);
468
+ console.log(chalk_1.default.yellow('Package files were restored; reinstall dependencies to repair node_modules.'));
469
+ }
309
470
  throw error;
310
471
  }
472
+ if (!result)
473
+ throw new Error('Bare setup transaction completed without a backup result.');
311
474
  console.log(chalk_1.default.green(`✅ Bare React Native setup complete. Backups: ${result.backupDir}`));
475
+ logRuntimeInitializationNextStep();
312
476
  return;
313
477
  }
314
478
  const hasNativeDirectories = scan.request.detected.hasNativeDirectories;
@@ -325,7 +489,10 @@ async function initProjectConfigAi(options = {}) {
325
489
  const unusualAiChanges = aiChanges.filter(change => !deterministicPaths.has(change.file));
326
490
  if ((0, configure_expo_1.hasDynamicExpoConfig)(projectRoot)) {
327
491
  const evaluatedConfig = (0, expo_1.evaluateExpoConfig)(projectRoot);
328
- const dynamicConfigFile = authoritativeDynamicExpoConfigFile(projectRoot, evaluatedConfig.dynamicConfigPath);
492
+ const dynamicConfigFile = (0, scanner_1.authoritativeDynamicExpoConfigFile)(projectRoot, evaluatedConfig.dynamicConfigPath);
493
+ if (!dynamicConfigFile) {
494
+ throw new Error('Expo did not identify the authoritative dynamic app config path. No files changed.');
495
+ }
329
496
  if (!hasBundleDropPlugin(evaluatedConfig.exp) &&
330
497
  !unusualAiChanges.some(change => change.file === dynamicConfigFile)) {
331
498
  throw new Error(`Dynamic Expo config requires an allowlisted AI patch for its evaluated root config ` +
@@ -334,6 +501,7 @@ async function initProjectConfigAi(options = {}) {
334
501
  }
335
502
  const combinedChanges = [
336
503
  ...deterministic,
504
+ ...(bootstrapChange ? [bootstrapChange] : []),
337
505
  ...unusualAiChanges.map(change => ({
338
506
  file: change.file,
339
507
  original: originals.get(change.file) ?? null,
@@ -401,6 +569,13 @@ async function initProjectConfigAi(options = {}) {
401
569
  projectRoot,
402
570
  changes: combinedChanges.filter(change => change.file !== 'package.json'),
403
571
  });
572
+ (0, validate_plan_1.validateAppliedSetupChanges)({
573
+ projectRoot,
574
+ projectType: 'expo',
575
+ changes: unusualAiChanges,
576
+ migrateExpoUpdates: Boolean(options.migrateExpoUpdates),
577
+ originals,
578
+ });
404
579
  assertBundleDropPluginPresent(projectRoot);
405
580
  if (hasNativeDirectories && options.prebuild) {
406
581
  prebuildBackup = runLayeredPrebuild(projectRoot);
@@ -420,6 +595,7 @@ async function initProjectConfigAi(options = {}) {
420
595
  throw error;
421
596
  }
422
597
  console.log(chalk_1.default.green(`✅ Expo setup complete. Backups: ${applyResult.backupDir}`));
598
+ logRuntimeInitializationNextStep();
423
599
  if (!hasNativeDirectories) {
424
600
  console.log(chalk_1.default.gray('Run expo run:*, explicit prebuild/manual build, or EAS Build to generate native integration.'));
425
601
  }
@@ -3,6 +3,7 @@ export declare const findCredentialLikeLiteral: (content: string) => string | nu
3
3
  export declare const isTrustedAiPlanningServer: (serverUrl: string) => boolean;
4
4
  export declare const isBundleDropHostedAiPlanningServer: (serverUrl: string) => boolean;
5
5
  export declare function findProjectRoot(startDir?: string): string;
6
+ export declare const authoritativeDynamicExpoConfigFile: (projectRoot: string, candidate: unknown) => string | null;
6
7
  export declare function scanProjectForAiSetup(projectType: AiSetupProjectType, startDir?: string, virtualConfig?: {
7
8
  content: string;
8
9
  serverUrl: string;