@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
@@ -1,5 +1,5 @@
1
1
  export type MetroConfigChange = {
2
- file: 'metro.config.js';
2
+ file: string;
3
3
  original: string | null;
4
4
  updated: string;
5
5
  reason: string;
@@ -1,52 +1,44 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.planBareMetroConfig = planBareMetroConfig;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
4
+ const safe_file_transaction_1 = require("./safe-file-transaction");
5
+ const metro_config_authority_1 = require("./metro-config-authority");
9
6
  const APPEND_SNIPPET = `
10
- // Bundle Drop: ensure bundle.drop.config.js is resolvable from node_modules
11
- (() => {
12
- const path = require('path');
13
- module.exports = module.exports || {};
14
- module.exports.resolver = module.exports.resolver || {};
15
- module.exports.resolver.extraNodeModules = {
16
- ...(module.exports.resolver.extraNodeModules || {}),
17
- 'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
18
- };
19
- })();
7
+ // Bundle Drop: merge package-managed runtime delivery bootstrap into Metro.
8
+ const { withBundleDrop } = require('@gfean/react-native-bundle-drop/metro');
9
+ module.exports = withBundleDrop(module.exports || {}, { projectRoot: __dirname });
20
10
  `;
21
- const NEW_METRO_TEMPLATE = `const path = require('path');
22
- const { getDefaultConfig } = require('@react-native/metro-config');
11
+ const NEW_METRO_TEMPLATE = `const { getDefaultConfig } = require('@react-native/metro-config');
12
+ const { withBundleDrop } = require('@gfean/react-native-bundle-drop/metro');
23
13
 
24
14
  const config = getDefaultConfig(__dirname);
25
- config.resolver = config.resolver || {};
26
- config.resolver.extraNodeModules = {
27
- ...(config.resolver.extraNodeModules || {}),
28
- 'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
29
- };
30
-
31
- module.exports = config;
15
+ module.exports = withBundleDrop(config, { projectRoot: __dirname });
32
16
  `;
33
17
  function planBareMetroConfig(projectRoot) {
34
- const metroPath = path_1.default.join(projectRoot, 'metro.config.js');
35
- if (!fs_extra_1.default.existsSync(metroPath)) {
18
+ const metroConfigPath = (0, metro_config_authority_1.findSingleMetroConfig)(projectRoot);
19
+ if (!metroConfigPath) {
36
20
  return {
37
- file: 'metro.config.js',
21
+ file: (0, metro_config_authority_1.newCommonJsMetroConfigFile)(projectRoot),
38
22
  original: null,
39
23
  updated: `${NEW_METRO_TEMPLATE.trim()}\n`,
40
- reason: 'Create the bare React Native Metro alias for bundle.drop.config.js.',
24
+ reason: 'Create the bare React Native Metro wrapper for Bundle Drop.',
41
25
  };
42
26
  }
43
- const content = fs_extra_1.default.readFileSync(metroPath, 'utf8');
44
- if (content.includes('bundle-drop-config'))
27
+ const metroFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, metroConfigPath);
28
+ const content = metroFile.content;
29
+ if ((0, metro_config_authority_1.hasAuthoritativeMetroWrapper)(content, 'withBundleDrop'))
45
30
  return null;
31
+ if ((0, metro_config_authority_1.hasExecutableMetroWrapperReference)(content, 'withBundleDrop')) {
32
+ throw new Error(`${metroConfigPath} contains a non-authoritative withBundleDrop reference. ` +
33
+ 'Remove the dead, aliased, or malformed wrapper before rerunning setup.');
34
+ }
35
+ (0, metro_config_authority_1.assertCommonJsMetroConfig)(projectRoot, metroConfigPath);
46
36
  return {
47
- file: 'metro.config.js',
37
+ file: metroConfigPath,
48
38
  original: content,
49
39
  updated: `${content.trim()}\n${APPEND_SNIPPET}`,
50
- reason: 'Add the Bundle Drop alias without replacing the existing Metro config.',
40
+ reason: content.includes('bundle-drop-config')
41
+ ? 'Migrate the legacy Bundle Drop alias to the package-managed Metro wrapper.'
42
+ : 'Add the Bundle Drop Metro wrapper without replacing the existing config.',
51
43
  };
52
44
  }
@@ -8,15 +8,19 @@ exports.runDoctor = runDoctor;
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
+ const child_process_1 = require("child_process");
11
12
  const native_setup_contract_1 = require("./native-setup-contract");
12
13
  const expo_1 = require("../../expo");
13
14
  const build_receipt_1 = require("./expo/build-receipt");
14
15
  const scanner_1 = require("./aipowered/scanner");
16
+ const bootstrapConfig_1 = require("../../runtime-delivery/bootstrapConfig");
17
+ const native_entrypoint_authority_1 = require("./native-entrypoint-authority");
18
+ const metro_config_authority_1 = require("./metro-config-authority");
19
+ const safe_file_transaction_1 = require("./safe-file-transaction");
15
20
  const PACKAGE_NAME = '@gfean/react-native-bundle-drop';
16
21
  const ANDROID_MARKER = 'com.bundledrop.EXPO_ENABLED';
17
22
  const IOS_MARKER = 'BundleDropExpoEnabled';
18
23
  const IOS_RECEIPT_PHASE = 'Bundle Drop: Write iOS build identity';
19
- const METRO_CONFIG_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs'];
20
24
  const pluginName = (plugin) => typeof plugin === 'string'
21
25
  ? plugin
22
26
  : Array.isArray(plugin) && typeof plugin[0] === 'string'
@@ -40,24 +44,143 @@ const checkExpoUpdates = (projectRoot, exp) => {
40
44
  message: 'Active expo-updates can own startup. Migrate it and create a new native binary.',
41
45
  };
42
46
  };
43
- const findFiles = (directory, suffix) => {
47
+ const findFiles = (directory, suffix, budget = { visitedEntries: 0 }) => {
44
48
  const files = [];
45
49
  if (fs_1.default.existsSync(directory)) {
46
50
  for (const entry of fs_1.default.readdirSync(directory, { withFileTypes: true })) {
51
+ budget.visitedEntries += 1;
52
+ if (budget.visitedEntries > 5000) {
53
+ throw new Error('Native doctor source scan exceeded 5000 filesystem entries.');
54
+ }
47
55
  if (entry.name === 'Pods' || entry.name === 'build')
48
56
  continue;
49
57
  const entryPath = path_1.default.join(directory, entry.name);
50
58
  if (entry.isDirectory())
51
- files.push(...findFiles(entryPath, suffix));
59
+ files.push(...findFiles(entryPath, suffix, budget));
52
60
  else if (entry.name.endsWith(suffix))
53
61
  files.push(entryPath);
54
62
  }
55
63
  }
56
64
  return files;
57
65
  };
58
- const findMetroConfig = (projectRoot) => METRO_CONFIG_EXTENSIONS
59
- .map(extension => path_1.default.join(projectRoot, `metro.config.${extension}`))
60
- .find(fs_1.default.existsSync);
66
+ const inspectMetroConfig = (projectRoot) => {
67
+ try {
68
+ const file = (0, metro_config_authority_1.findSingleMetroConfig)(projectRoot);
69
+ return file
70
+ ? { file, content: (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file).content, issue: null }
71
+ : { file: undefined, content: '', issue: 'No Metro config file was found.' };
72
+ }
73
+ catch (error) {
74
+ return { file: undefined, content: '', issue: error.message };
75
+ }
76
+ };
77
+ const runtimeDeliveryBootstrapGitState = (projectRoot, relativePath) => {
78
+ const runGit = (args) => (0, child_process_1.spawnSync)('git', args, {
79
+ cwd: projectRoot,
80
+ stdio: 'ignore',
81
+ });
82
+ const repository = runGit(['rev-parse', '--is-inside-work-tree']);
83
+ if (repository.error || repository.status !== 0)
84
+ return null;
85
+ if (runGit(['check-ignore', '--no-index', '-q', '--', relativePath]).status === 0) {
86
+ return 'ignored';
87
+ }
88
+ return runGit(['ls-files', '--error-unmatch', '--', relativePath]).status === 0
89
+ ? 'tracked'
90
+ : 'untracked';
91
+ };
92
+ const checkRuntimeDeliveryBootstrap = (projectRoot) => {
93
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
94
+ if (!fs_1.default.existsSync(configPath)) {
95
+ return {
96
+ name: 'Runtime delivery bootstrap',
97
+ status: 'error',
98
+ message: 'bundle.drop.config.js is required before runtime delivery can be validated.',
99
+ };
100
+ }
101
+ try {
102
+ delete require.cache[require.resolve(configPath)];
103
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
104
+ const config = require(configPath);
105
+ if (!config.serverUrl || !config.org?.slug || !config.project?.slug) {
106
+ throw new Error('bundle.drop.config.js is missing serverUrl, org.slug, or project.slug.');
107
+ }
108
+ const inspected = (0, bootstrapConfig_1.inspectRuntimeDeliveryBootstrap)({
109
+ projectRoot,
110
+ expectedIdentity: {
111
+ serverUrl: config.serverUrl,
112
+ orgSlug: config.org.slug,
113
+ projectSlug: config.project.slug,
114
+ },
115
+ });
116
+ if (inspected) {
117
+ const { bootstrap, source } = inspected;
118
+ const activePath = source === 'legacy'
119
+ ? bootstrapConfig_1.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH
120
+ : bootstrapConfig_1.RUNTIME_DELIVERY_BOOTSTRAP_PATH;
121
+ const gitState = runtimeDeliveryBootstrapGitState(projectRoot, activePath);
122
+ if (gitState === 'ignored') {
123
+ return {
124
+ name: 'Runtime delivery bootstrap',
125
+ status: 'error',
126
+ message: 'The runtime delivery lockfile is ignored by Git and will be missing from clean builds. ' +
127
+ 'Run `bundle-drop sync` to repair .gitignore.',
128
+ };
129
+ }
130
+ if (gitState === 'untracked') {
131
+ return {
132
+ name: 'Runtime delivery bootstrap',
133
+ status: 'warning',
134
+ message: `Runtime delivery lockfile is valid with ` +
135
+ `${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s), ` +
136
+ 'but it is not committed yet.',
137
+ };
138
+ }
139
+ if (source === 'legacy') {
140
+ return {
141
+ name: 'Runtime delivery bootstrap',
142
+ status: 'warning',
143
+ message: 'The legacy runtime-delivery.generated.json bootstrap is valid. ' +
144
+ 'Run `bundle-drop sync` to migrate it to runtime-delivery.lock.json.',
145
+ };
146
+ }
147
+ if (source === 'matching-dual') {
148
+ return {
149
+ name: 'Runtime delivery bootstrap',
150
+ status: 'warning',
151
+ message: 'The runtime delivery lockfile matches the legacy bootstrap. ' +
152
+ 'Run `bundle-drop sync` to remove the legacy file.',
153
+ };
154
+ }
155
+ return {
156
+ name: 'Runtime delivery bootstrap',
157
+ status: 'pass',
158
+ message: `Runtime delivery lockfile is pinned with ${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s).`,
159
+ };
160
+ }
161
+ if (config.runtimeDelivery) {
162
+ return {
163
+ name: 'Runtime delivery bootstrap',
164
+ status: 'warning',
165
+ message: 'Stale inline runtime delivery config is ignored. Remove runtimeDelivery from ' +
166
+ 'bundle.drop.config.js, migrate Metro with `bundle-drop init`, and use `bundle-drop sync` ' +
167
+ 'for package-managed trust.',
168
+ };
169
+ }
170
+ return {
171
+ name: 'Runtime delivery bootstrap',
172
+ status: 'warning',
173
+ message: 'No runtime delivery lockfile is pinned. Run `bundle-drop sync` to create or repair it.',
174
+ };
175
+ }
176
+ catch (error) {
177
+ return {
178
+ name: 'Runtime delivery bootstrap',
179
+ status: 'error',
180
+ message: `${error.message} Run \`bundle-drop sync\` to repair it.`,
181
+ };
182
+ }
183
+ };
61
184
  const checkCommittedNativeIntegration = (projectRoot, platform) => {
62
185
  if (platform === 'android') {
63
186
  const androidRoot = path_1.default.join(projectRoot, 'android');
@@ -94,6 +217,7 @@ const checkCommittedNativeIntegration = (projectRoot, platform) => {
94
217
  };
95
218
  async function inspectExpoProject(projectRoot, platforms) {
96
219
  const checks = [];
220
+ checks.push(checkRuntimeDeliveryBootstrap(projectRoot));
97
221
  const { exp } = (0, expo_1.evaluateExpoConfig)(projectRoot);
98
222
  const plugins = (exp.plugins || []).map(pluginName);
99
223
  const bundleDropPluginCount = plugins.filter(name => name === PACKAGE_NAME).length;
@@ -134,14 +258,16 @@ async function inspectExpoProject(projectRoot, platforms) {
134
258
  if (nativeCheck)
135
259
  checks.push(nativeCheck);
136
260
  }
137
- const metroFile = findMetroConfig(projectRoot);
138
- const metroContent = metroFile ? fs_1.default.readFileSync(metroFile, 'utf8') : '';
261
+ const metro = inspectMetroConfig(projectRoot);
262
+ const hasExpoMetroWrapper = !metro.issue &&
263
+ (0, metro_config_authority_1.hasAuthoritativeMetroWrapper)(metro.content, 'withBundleDropExpo') &&
264
+ (0, metro_config_authority_1.hasExecutableMetroModuleReference)(metro.content, 'expo/metro-config');
139
265
  checks.push({
140
266
  name: 'Expo Metro wrapper',
141
- status: metroContent.includes('withBundleDropExpo') ? 'pass' : 'error',
142
- message: metroContent.includes('withBundleDropExpo')
267
+ status: hasExpoMetroWrapper ? 'pass' : 'error',
268
+ message: hasExpoMetroWrapper
143
269
  ? 'Existing Expo Metro configuration is preserved through withBundleDropExpo.'
144
- : 'Metro must use withBundleDropExpo and preserve expo/metro-config.',
270
+ : metro.issue || 'Metro must export withBundleDropExpo(...) and preserve expo/metro-config.',
145
271
  });
146
272
  const runtimeAuthorities = new Map(platforms.map(platform => [
147
273
  platform,
@@ -299,18 +425,30 @@ const checkBareStartupIntegration = (projectRoot, platform) => {
299
425
  ? ['MainApplication.kt', 'MainApplication.java']
300
426
  : ['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'];
301
427
  const entrypoints = entrypointNames.flatMap(name => findFiles(nativeRoot, name));
302
- const hasIntegration = entrypoints.some(filePath => {
428
+ const relativeEntrypoints = entrypoints.map(filePath => path_1.default.relative(projectRoot, filePath).split(path_1.default.sep).join('/'));
429
+ let authorityIssue = null;
430
+ try {
431
+ authorityIssue = (0, native_entrypoint_authority_1.findNativeEntrypointAuthorityIssue)(projectRoot, platform, relativeEntrypoints);
432
+ }
433
+ catch (error) {
434
+ authorityIssue = error.message;
435
+ }
436
+ const hasIntegration = entrypoints.length === 1 && entrypoints.every(filePath => {
303
437
  const content = fs_1.default.readFileSync(filePath, 'utf8');
304
438
  return platform === 'android'
305
439
  ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(content)
306
440
  : (0, native_setup_contract_1.hasBareIosStartupIntegration)(filePath, content);
307
- });
441
+ }) && !authorityIssue;
308
442
  return {
309
443
  name: `${platform} OTA startup ownership`,
310
444
  status: hasIntegration ? 'pass' : 'error',
311
- message: hasIntegration
312
- ? `The ${platform} application entrypoint asks Bundle Drop for the cold-start bundle.`
313
- : `The ${platform} application entrypoint does not hand cold-start bundle resolution to Bundle Drop.`,
445
+ message: entrypoints.length > 1
446
+ ? `Multiple ${platform} application entrypoints were found; resolve startup ownership manually.`
447
+ : authorityIssue
448
+ ? `Native application entrypoint authority is ambiguous: ${authorityIssue}`
449
+ : hasIntegration
450
+ ? `The ${platform} application entrypoint asks Bundle Drop for the cold-start bundle.`
451
+ : `The ${platform} application entrypoint does not hand cold-start bundle resolution to Bundle Drop.`,
314
452
  };
315
453
  };
316
454
  const checkBareNativeAutolinking = (projectRoot, platform) => {
@@ -358,8 +496,9 @@ const checkBareNativeAutolinking = (projectRoot, platform) => {
358
496
  };
359
497
  function inspectBareProject(projectRoot, platforms) {
360
498
  const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
361
- const metroPath = findMetroConfig(projectRoot);
362
- const metroContent = metroPath ? fs_1.default.readFileSync(metroPath, 'utf8') : '';
499
+ const metro = inspectMetroConfig(projectRoot);
500
+ const hasBareMetroWrapper = !metro.issue &&
501
+ (0, metro_config_authority_1.hasAuthoritativeMetroWrapper)(metro.content, 'withBundleDrop');
363
502
  const checks = [
364
503
  {
365
504
  name: 'Bundle Drop config',
@@ -370,11 +509,12 @@ function inspectBareProject(projectRoot, platforms) {
370
509
  },
371
510
  {
372
511
  name: 'Bare Metro alias',
373
- status: metroContent.includes('bundle-drop-config') ? 'pass' : 'error',
374
- message: metroContent.includes('bundle-drop-config')
375
- ? 'Metro resolves bundle-drop-config.'
376
- : 'Metro does not contain the bundle-drop-config alias.',
512
+ status: hasBareMetroWrapper ? 'pass' : 'error',
513
+ message: hasBareMetroWrapper
514
+ ? 'Metro uses the package-managed Bundle Drop wrapper.'
515
+ : metro.issue || 'Metro must export withBundleDrop(...) so generated trust data is bundled.',
377
516
  },
517
+ checkRuntimeDeliveryBootstrap(projectRoot),
378
518
  checkBarePackageMetadata(projectRoot),
379
519
  ];
380
520
  for (const platform of platforms) {
@@ -10,9 +10,11 @@ exports.hasDynamicExpoConfig = hasDynamicExpoConfig;
10
10
  exports.restoreExpoConfiguration = restoreExpoConfiguration;
11
11
  exports.applyExpoConfigurationChanges = applyExpoConfigurationChanges;
12
12
  const crypto_1 = __importDefault(require("crypto"));
13
- const fs_extra_1 = __importDefault(require("fs-extra"));
14
13
  const path_1 = __importDefault(require("path"));
15
14
  const projectType_1 = require("../../../expo/projectType");
15
+ const bootstrapConfig_1 = require("../../../runtime-delivery/bootstrapConfig");
16
+ const safe_file_transaction_1 = require("../safe-file-transaction");
17
+ const metro_config_authority_1 = require("../metro-config-authority");
16
18
  var projectType_2 = require("../../../expo/projectType");
17
19
  Object.defineProperty(exports, "setBundleDropProjectType", { enumerable: true, get: function () { return projectType_2.setBundleDropProjectType; } });
18
20
  const PACKAGE_NAME = '@gfean/react-native-bundle-drop';
@@ -75,7 +77,7 @@ module.exports = withBundleDropExpo(getDefaultConfig(__dirname), {
75
77
  const updateBundleDropConfig = (content) => {
76
78
  return (0, projectType_1.setBundleDropProjectType)(content, 'expo');
77
79
  };
78
- const findFirstExisting = (projectRoot, candidates) => candidates.find(candidate => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, candidate)));
80
+ const findFirstExisting = (projectRoot, candidates) => candidates.find(candidate => (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, candidate).exists);
79
81
  function planExpoProjectConfiguration(params) {
80
82
  const changes = [];
81
83
  const appConfigFile = findFirstExisting(params.projectRoot, [
@@ -84,9 +86,9 @@ function planExpoProjectConfiguration(params) {
84
86
  'app.config.cjs',
85
87
  'app.config.mjs',
86
88
  ]);
87
- const appJsonPath = path_1.default.join(params.projectRoot, 'app.json');
88
- if (!appConfigFile && fs_extra_1.default.existsSync(appJsonPath)) {
89
- const original = fs_extra_1.default.readFileSync(appJsonPath, 'utf8');
89
+ const appJson = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, 'app.json');
90
+ if (!appConfigFile && appJson.exists) {
91
+ const original = appJson.content;
90
92
  const updated = updateAppJson(original, params.migrateExpoUpdates);
91
93
  if (updated !== original) {
92
94
  changes.push({
@@ -97,15 +99,15 @@ function planExpoProjectConfiguration(params) {
97
99
  });
98
100
  }
99
101
  }
100
- const metroFile = findFirstExisting(params.projectRoot, [
101
- 'metro.config.js',
102
- 'metro.config.ts',
103
- 'metro.config.cjs',
104
- 'metro.config.mjs',
105
- ]);
102
+ const metroFile = (0, metro_config_authority_1.findSingleMetroConfig)(params.projectRoot);
106
103
  if (metroFile) {
107
- const original = fs_extra_1.default.readFileSync(path_1.default.join(params.projectRoot, metroFile), 'utf8');
108
- if (!original.includes('withBundleDropExpo')) {
104
+ const original = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, metroFile).content;
105
+ if (!(0, metro_config_authority_1.hasAuthoritativeMetroWrapper)(original, 'withBundleDropExpo')) {
106
+ if ((0, metro_config_authority_1.hasExecutableMetroWrapperReference)(original, 'withBundleDropExpo')) {
107
+ throw new Error(`${metroFile} contains a non-authoritative withBundleDropExpo reference. ` +
108
+ 'Remove the dead, aliased, or malformed wrapper before rerunning setup.');
109
+ }
110
+ (0, metro_config_authority_1.assertCommonJsMetroConfig)(params.projectRoot, metroFile);
109
111
  changes.push({
110
112
  file: metroFile,
111
113
  original,
@@ -115,17 +117,18 @@ function planExpoProjectConfiguration(params) {
115
117
  }
116
118
  }
117
119
  else {
120
+ const newMetroFile = (0, metro_config_authority_1.newCommonJsMetroConfigFile)(params.projectRoot);
118
121
  changes.push({
119
- file: 'metro.config.js',
122
+ file: newMetroFile,
120
123
  original: null,
121
124
  updated: NEW_EXPO_METRO_CONFIG,
122
125
  reason: 'Create an Expo Metro config with the Bundle Drop wrapper.',
123
126
  });
124
127
  }
125
- const bundleConfigPath = path_1.default.join(params.projectRoot, 'bundle.drop.config.js');
126
- const bundleConfigExists = fs_extra_1.default.existsSync(bundleConfigPath);
128
+ const bundleConfigFile = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, 'bundle.drop.config.js');
129
+ const bundleConfigExists = bundleConfigFile.exists;
127
130
  const bundleConfig = bundleConfigExists
128
- ? fs_extra_1.default.readFileSync(bundleConfigPath, 'utf8')
131
+ ? bundleConfigFile.content
129
132
  : params.bundleConfigContent;
130
133
  if (!bundleConfig) {
131
134
  throw new Error('bundle.drop.config.js is required before Expo configuration can be planned.');
@@ -140,8 +143,10 @@ function planExpoProjectConfiguration(params) {
140
143
  });
141
144
  }
142
145
  if (params.migrateExpoUpdates) {
143
- const packagePath = path_1.default.join(params.projectRoot, 'package.json');
144
- const packageJson = fs_extra_1.default.readFileSync(packagePath, 'utf8');
146
+ const packageFile = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, 'package.json');
147
+ if (!packageFile.exists)
148
+ throw new Error('package.json is required for expo-updates migration.');
149
+ const packageJson = packageFile.content;
145
150
  const updatedPackageJson = updatePackageJson(packageJson);
146
151
  if (updatedPackageJson !== packageJson) {
147
152
  changes.push({
@@ -152,28 +157,27 @@ function planExpoProjectConfiguration(params) {
152
157
  });
153
158
  }
154
159
  }
155
- const fingerprintIgnorePath = path_1.default.join(params.projectRoot, '.fingerprintignore');
156
- const fingerprintIgnore = fs_extra_1.default.existsSync(fingerprintIgnorePath)
157
- ? fs_extra_1.default.readFileSync(fingerprintIgnorePath, 'utf8')
158
- : '';
160
+ const fingerprintIgnoreFile = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, '.fingerprintignore');
161
+ const fingerprintIgnore = fingerprintIgnoreFile.exists ? fingerprintIgnoreFile.content : '';
159
162
  if (EXPO_RUNTIME_SOURCE_PATTERN.test(updatedBundleConfig) &&
160
163
  !fingerprintIgnore.split(/\r?\n/).includes(TRANSIENT_GRADLE_KOTLIN_FINGERPRINT_PATTERN)) {
161
164
  changes.push({
162
165
  file: '.fingerprintignore',
163
- original: fs_extra_1.default.existsSync(fingerprintIgnorePath) ? fingerprintIgnore : null,
166
+ original: fingerprintIgnoreFile.exists ? fingerprintIgnore : null,
164
167
  updated: `${fingerprintIgnore.trimEnd()}${fingerprintIgnore.trim() ? '\n' : ''}` +
165
168
  `${TRANSIENT_GRADLE_KOTLIN_FINGERPRINT_PATTERN}\n`,
166
169
  reason: 'Exclude transient Gradle Kotlin compiler sessions from Expo runtime fingerprints.',
167
170
  });
168
171
  }
169
- const gitignorePath = path_1.default.join(params.projectRoot, '.gitignore');
170
- const gitignore = fs_extra_1.default.existsSync(gitignorePath) ? fs_extra_1.default.readFileSync(gitignorePath, 'utf8') : '';
171
- if (!gitignore.split(/\r?\n/).includes('.bundle-drop/')) {
172
+ const gitignoreFile = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, '.gitignore');
173
+ const gitignore = gitignoreFile.exists ? gitignoreFile.content : '';
174
+ const updatedGitignore = (0, bootstrapConfig_1.addRuntimeDeliveryBootstrapGitignoreRules)(gitignore);
175
+ if (updatedGitignore !== gitignore) {
172
176
  changes.push({
173
177
  file: '.gitignore',
174
- original: fs_extra_1.default.existsSync(gitignorePath) ? gitignore : null,
175
- updated: `${gitignore.trimEnd()}${gitignore.trim() ? '\n' : ''}.bundle-drop/\n`,
176
- reason: 'Ignore generated build identity and Metro configuration artifacts.',
178
+ original: gitignoreFile.exists ? gitignore : null,
179
+ updated: updatedGitignore,
180
+ reason: 'Commit the public trust bootstrap while ignoring generated runtime artifacts.',
177
181
  });
178
182
  }
179
183
  return changes;
@@ -193,6 +197,8 @@ const assertSetupPathAllowed = (file) => {
193
197
  const allowed = file === 'package.json' ||
194
198
  file === '.fingerprintignore' ||
195
199
  file === '.gitignore' ||
200
+ file === bootstrapConfig_1.RUNTIME_DELIVERY_BOOTSTRAP_PATH ||
201
+ file === bootstrapConfig_1.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH ||
196
202
  file === 'bundle.drop.config.js' ||
197
203
  file === 'app.json' ||
198
204
  /^app\.config\.(js|ts|cjs|mjs)$/.test(file) ||
@@ -203,61 +209,47 @@ const assertSetupPathAllowed = (file) => {
203
209
  };
204
210
  function restoreExpoConfiguration(result) {
205
211
  for (const changed of [...result.changedFiles].reverse()) {
206
- const targetPath = path_1.default.join(result.projectRoot, changed.file);
207
- const backupPath = path_1.default.join(result.backupDir, changed.file);
208
212
  if (changed.existed) {
209
- fs_extra_1.default.copyFileSync(backupPath, targetPath);
213
+ (0, safe_file_transaction_1.restoreProjectFile)(result.projectRoot, result.backupDir, changed.file);
210
214
  }
211
- else if (fs_extra_1.default.existsSync(targetPath)) {
212
- fs_extra_1.default.unlinkSync(targetPath);
215
+ else {
216
+ (0, safe_file_transaction_1.removeProjectFile)(result.projectRoot, changed.file);
213
217
  }
214
218
  }
215
219
  if (result.buildReceiptInvalidated) {
216
220
  const receiptFile = path_1.default.join('.bundle-drop', 'build-identity.json');
217
- const targetPath = path_1.default.join(result.projectRoot, receiptFile);
218
- const backupPath = path_1.default.join(result.backupDir, receiptFile);
219
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(targetPath));
220
- fs_extra_1.default.copyFileSync(backupPath, targetPath);
221
+ (0, safe_file_transaction_1.restoreProjectFile)(result.projectRoot, result.backupDir, receiptFile);
221
222
  }
222
223
  }
223
224
  function applyExpoConfigurationChanges(params) {
224
225
  const result = {
225
226
  projectRoot: params.projectRoot,
226
- backupDir: path_1.default.join(params.projectRoot, '.bundledrop-backup', new Date().toISOString().replace(/[:.]/g, '-')),
227
+ backupDir: (0, safe_file_transaction_1.createSafeBackupDirectory)(params.projectRoot, 'expo-setup'),
227
228
  changedFiles: [],
228
229
  buildReceiptInvalidated: false,
229
230
  };
230
231
  try {
231
232
  const receiptFile = path_1.default.join('.bundle-drop', 'build-identity.json');
232
- const receiptPath = path_1.default.join(params.projectRoot, receiptFile);
233
- if (fs_extra_1.default.existsSync(receiptPath)) {
234
- const backupPath = path_1.default.join(result.backupDir, receiptFile);
235
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
236
- fs_extra_1.default.copyFileSync(receiptPath, backupPath);
237
- fs_extra_1.default.unlinkSync(receiptPath);
233
+ const receipt = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, receiptFile);
234
+ if (receipt.exists) {
235
+ (0, safe_file_transaction_1.writeBackupFile)(result.backupDir, receiptFile, receipt.content, receipt.mode);
236
+ (0, safe_file_transaction_1.removeProjectFile)(params.projectRoot, receiptFile);
238
237
  result.buildReceiptInvalidated = true;
239
238
  }
240
239
  for (const change of params.changes) {
241
240
  assertSetupPathAllowed(change.file);
242
- const targetPath = path_1.default.join(params.projectRoot, change.file);
243
- const exists = fs_extra_1.default.existsSync(targetPath);
244
- if (exists !== (change.original !== null)) {
241
+ const target = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, change.file);
242
+ if (target.exists !== (change.original !== null)) {
245
243
  throw new Error(`File existence changed since Expo setup preview: ${change.file}`);
246
244
  }
247
- if (exists) {
248
- const current = fs_extra_1.default.readFileSync(targetPath, 'utf8');
249
- if (sha256(current) !== sha256(change.original || '')) {
245
+ if (target.exists) {
246
+ if (sha256(target.content) !== sha256(change.original || '')) {
250
247
  throw new Error(`File changed since Expo setup preview: ${change.file}`);
251
248
  }
252
- const backupPath = path_1.default.join(result.backupDir, change.file);
253
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
254
- fs_extra_1.default.copyFileSync(targetPath, backupPath);
249
+ (0, safe_file_transaction_1.writeBackupFile)(result.backupDir, change.file, target.content, target.mode);
255
250
  }
256
- result.changedFiles.push({ file: change.file, existed: exists });
257
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(targetPath));
258
- const temporaryPath = `${targetPath}.bundledrop-tmp`;
259
- fs_extra_1.default.writeFileSync(temporaryPath, change.updated, 'utf8');
260
- fs_extra_1.default.renameSync(temporaryPath, targetPath);
251
+ result.changedFiles.push({ file: change.file, existed: target.exists });
252
+ (0, safe_file_transaction_1.writeProjectFileAtomically)(params.projectRoot, change.file, change.updated, target.mode);
261
253
  }
262
254
  return result;
263
255
  }
@@ -1,6 +1,7 @@
1
1
  export type SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
2
2
  export declare function detectPackageManager(projectRoot: string): SupportedPackageManager;
3
3
  export declare function expoUpdatesRemovalCommand(manager: SupportedPackageManager): string[];
4
+ export declare function codePushRemovalCommand(manager: SupportedPackageManager): string[];
4
5
  export type DependencyMigrationBackup = {
5
6
  projectRoot: string;
6
7
  backupDir: string;
@@ -9,3 +10,4 @@ export type DependencyMigrationBackup = {
9
10
  };
10
11
  export declare function restoreDependencyMigration(backup: DependencyMigrationBackup): void;
11
12
  export declare function removeExpoUpdatesWithPackageManager(projectRoot: string): DependencyMigrationBackup;
13
+ export declare function removeCodePushWithPackageManager(projectRoot: string): DependencyMigrationBackup;