@gfean/react-native-bundle-drop 0.5.1 → 0.6.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 (96) hide show
  1. package/README.md +168 -4
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  6. package/ios/BundleDropBridge.m +18 -0
  7. package/ios/BundleDropLocator.swift +48 -2
  8. package/ios/BundleDropModule.swift +75 -0
  9. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  10. package/lib/CLI/cli.d.ts +1 -0
  11. package/lib/CLI/cli.js +54 -2
  12. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  13. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  14. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  15. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  16. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  17. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  18. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  19. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  20. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  21. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  22. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  23. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  24. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  25. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  26. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  27. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  28. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  29. package/lib/CLI/scripts/doctor.js +143 -22
  30. package/lib/CLI/scripts/expo/configure-expo.js +51 -60
  31. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  32. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  33. package/lib/CLI/scripts/init-config.d.ts +7 -7
  34. package/lib/CLI/scripts/init-config.js +185 -10
  35. package/lib/CLI/scripts/login-cli.js +29 -4
  36. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  37. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  38. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  39. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  40. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  41. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  42. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  43. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  44. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  45. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  46. package/lib/api/clientApi.d.ts +3 -1
  47. package/lib/api/clientApi.js +14 -0
  48. package/lib/api/types.d.ts +39 -0
  49. package/lib/context.d.ts +1 -1
  50. package/lib/index.d.ts +2 -0
  51. package/lib/index.js +3 -1
  52. package/lib/install/installFromZip.d.ts +3 -0
  53. package/lib/install/installFromZip.js +10 -1
  54. package/lib/loadConfig.d.ts +17 -1
  55. package/lib/loadConfig.js +16 -0
  56. package/lib/manager/downloadAndInstall.d.ts +3 -2
  57. package/lib/manager/downloadAndInstall.js +111 -46
  58. package/lib/manager/rollbackState.d.ts +3 -1
  59. package/lib/manager/rollbackState.js +2 -2
  60. package/lib/manager/updateCheck.d.ts +1 -0
  61. package/lib/manager/updateCheck.js +218 -78
  62. package/lib/metro.d.ts +8 -1
  63. package/lib/metro.js +68 -19
  64. package/lib/native/bundleDropNative.js +2 -1
  65. package/lib/native/fs.d.ts +6 -0
  66. package/lib/native/fs.js +24 -0
  67. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  68. package/lib/patch-engine/installFromPatchSet.js +14 -3
  69. package/lib/patch-engine/patchTransport.d.ts +2 -0
  70. package/lib/patch-engine/patchTransport.js +9 -0
  71. package/lib/runtime/initState.d.ts +5 -0
  72. package/lib/runtime/initState.js +4 -0
  73. package/lib/runtime/service.js +60 -3
  74. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  75. package/lib/runtime-delivery/artifactCapability.js +32 -0
  76. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  77. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  78. package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
  79. package/lib/runtime-delivery/bootstrapConfig.js +217 -0
  80. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  81. package/lib/runtime-delivery/diagnostics.js +58 -0
  82. package/lib/runtime-delivery/encoding.d.ts +5 -0
  83. package/lib/runtime-delivery/encoding.js +132 -0
  84. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  85. package/lib/runtime-delivery/heartbeat.js +88 -0
  86. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  87. package/lib/runtime-delivery/localResolver.js +81 -0
  88. package/lib/runtime-delivery/manifestState.d.ts +9 -0
  89. package/lib/runtime-delivery/manifestState.js +102 -0
  90. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  91. package/lib/runtime-delivery/manifestVerifier.js +329 -0
  92. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  93. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  94. package/lib/runtime-delivery/types.d.ts +87 -0
  95. package/lib/runtime-delivery/types.js +6 -0
  96. package/package.json +2 -2
@@ -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,124 @@ 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) => {
78
+ const relativePath = path_1.default.join('.bundle-drop', 'runtime-delivery.generated.json');
79
+ const runGit = (args) => (0, child_process_1.spawnSync)('git', args, {
80
+ cwd: projectRoot,
81
+ stdio: 'ignore',
82
+ });
83
+ const repository = runGit(['rev-parse', '--is-inside-work-tree']);
84
+ if (repository.error || repository.status !== 0)
85
+ return null;
86
+ if (runGit(['check-ignore', '--no-index', '-q', '--', relativePath]).status === 0) {
87
+ return 'ignored';
88
+ }
89
+ return runGit(['ls-files', '--error-unmatch', '--', relativePath]).status === 0
90
+ ? 'tracked'
91
+ : 'untracked';
92
+ };
93
+ const checkRuntimeDeliveryBootstrap = (projectRoot) => {
94
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
95
+ if (!fs_1.default.existsSync(configPath)) {
96
+ return {
97
+ name: 'Runtime delivery bootstrap',
98
+ status: 'error',
99
+ message: 'bundle.drop.config.js is required before runtime delivery can be validated.',
100
+ };
101
+ }
102
+ try {
103
+ delete require.cache[require.resolve(configPath)];
104
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
105
+ const config = require(configPath);
106
+ if (!config.serverUrl || !config.org?.slug || !config.project?.slug) {
107
+ throw new Error('bundle.drop.config.js is missing serverUrl, org.slug, or project.slug.');
108
+ }
109
+ const bootstrap = (0, bootstrapConfig_1.readGeneratedRuntimeDeliveryBootstrap)({
110
+ projectRoot,
111
+ expectedIdentity: {
112
+ serverUrl: config.serverUrl,
113
+ orgSlug: config.org.slug,
114
+ projectSlug: config.project.slug,
115
+ },
116
+ });
117
+ if (bootstrap) {
118
+ const gitState = runtimeDeliveryBootstrapGitState(projectRoot);
119
+ if (gitState === 'ignored') {
120
+ return {
121
+ name: 'Runtime delivery bootstrap',
122
+ status: 'error',
123
+ message: 'The runtime delivery bootstrap is ignored by Git and will be missing from clean builds. ' +
124
+ 'Run `bundle-drop sync` to repair .gitignore.',
125
+ };
126
+ }
127
+ if (gitState === 'untracked') {
128
+ return {
129
+ name: 'Runtime delivery bootstrap',
130
+ status: 'warning',
131
+ message: `Runtime delivery bootstrap is valid with ` +
132
+ `${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s), ` +
133
+ 'but it is not committed yet.',
134
+ };
135
+ }
136
+ return {
137
+ name: 'Runtime delivery bootstrap',
138
+ status: 'pass',
139
+ message: `Runtime delivery bootstrap is pinned with ${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s).`,
140
+ };
141
+ }
142
+ if (config.runtimeDelivery) {
143
+ return {
144
+ name: 'Runtime delivery bootstrap',
145
+ status: 'warning',
146
+ message: 'Stale inline runtime delivery config is ignored. Remove runtimeDelivery from ' +
147
+ 'bundle.drop.config.js, migrate Metro with `bundle-drop init`, and use `bundle-drop sync` ' +
148
+ 'for package-managed trust.',
149
+ };
150
+ }
151
+ return {
152
+ name: 'Runtime delivery bootstrap',
153
+ status: 'warning',
154
+ message: 'No runtime delivery bootstrap is pinned. Run `bundle-drop sync` to create or repair it.',
155
+ };
156
+ }
157
+ catch (error) {
158
+ return {
159
+ name: 'Runtime delivery bootstrap',
160
+ status: 'error',
161
+ message: `${error.message} Run \`bundle-drop sync\` to repair it.`,
162
+ };
163
+ }
164
+ };
61
165
  const checkCommittedNativeIntegration = (projectRoot, platform) => {
62
166
  if (platform === 'android') {
63
167
  const androidRoot = path_1.default.join(projectRoot, 'android');
@@ -94,6 +198,7 @@ const checkCommittedNativeIntegration = (projectRoot, platform) => {
94
198
  };
95
199
  async function inspectExpoProject(projectRoot, platforms) {
96
200
  const checks = [];
201
+ checks.push(checkRuntimeDeliveryBootstrap(projectRoot));
97
202
  const { exp } = (0, expo_1.evaluateExpoConfig)(projectRoot);
98
203
  const plugins = (exp.plugins || []).map(pluginName);
99
204
  const bundleDropPluginCount = plugins.filter(name => name === PACKAGE_NAME).length;
@@ -134,14 +239,16 @@ async function inspectExpoProject(projectRoot, platforms) {
134
239
  if (nativeCheck)
135
240
  checks.push(nativeCheck);
136
241
  }
137
- const metroFile = findMetroConfig(projectRoot);
138
- const metroContent = metroFile ? fs_1.default.readFileSync(metroFile, 'utf8') : '';
242
+ const metro = inspectMetroConfig(projectRoot);
243
+ const hasExpoMetroWrapper = !metro.issue &&
244
+ (0, metro_config_authority_1.hasAuthoritativeMetroWrapper)(metro.content, 'withBundleDropExpo') &&
245
+ (0, metro_config_authority_1.hasExecutableMetroModuleReference)(metro.content, 'expo/metro-config');
139
246
  checks.push({
140
247
  name: 'Expo Metro wrapper',
141
- status: metroContent.includes('withBundleDropExpo') ? 'pass' : 'error',
142
- message: metroContent.includes('withBundleDropExpo')
248
+ status: hasExpoMetroWrapper ? 'pass' : 'error',
249
+ message: hasExpoMetroWrapper
143
250
  ? 'Existing Expo Metro configuration is preserved through withBundleDropExpo.'
144
- : 'Metro must use withBundleDropExpo and preserve expo/metro-config.',
251
+ : metro.issue || 'Metro must export withBundleDropExpo(...) and preserve expo/metro-config.',
145
252
  });
146
253
  const runtimeAuthorities = new Map(platforms.map(platform => [
147
254
  platform,
@@ -299,18 +406,30 @@ const checkBareStartupIntegration = (projectRoot, platform) => {
299
406
  ? ['MainApplication.kt', 'MainApplication.java']
300
407
  : ['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'];
301
408
  const entrypoints = entrypointNames.flatMap(name => findFiles(nativeRoot, name));
302
- const hasIntegration = entrypoints.some(filePath => {
409
+ const relativeEntrypoints = entrypoints.map(filePath => path_1.default.relative(projectRoot, filePath).split(path_1.default.sep).join('/'));
410
+ let authorityIssue = null;
411
+ try {
412
+ authorityIssue = (0, native_entrypoint_authority_1.findNativeEntrypointAuthorityIssue)(projectRoot, platform, relativeEntrypoints);
413
+ }
414
+ catch (error) {
415
+ authorityIssue = error.message;
416
+ }
417
+ const hasIntegration = entrypoints.length === 1 && entrypoints.every(filePath => {
303
418
  const content = fs_1.default.readFileSync(filePath, 'utf8');
304
419
  return platform === 'android'
305
420
  ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(content)
306
421
  : (0, native_setup_contract_1.hasBareIosStartupIntegration)(filePath, content);
307
- });
422
+ }) && !authorityIssue;
308
423
  return {
309
424
  name: `${platform} OTA startup ownership`,
310
425
  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.`,
426
+ message: entrypoints.length > 1
427
+ ? `Multiple ${platform} application entrypoints were found; resolve startup ownership manually.`
428
+ : authorityIssue
429
+ ? `Native application entrypoint authority is ambiguous: ${authorityIssue}`
430
+ : hasIntegration
431
+ ? `The ${platform} application entrypoint asks Bundle Drop for the cold-start bundle.`
432
+ : `The ${platform} application entrypoint does not hand cold-start bundle resolution to Bundle Drop.`,
314
433
  };
315
434
  };
316
435
  const checkBareNativeAutolinking = (projectRoot, platform) => {
@@ -358,8 +477,9 @@ const checkBareNativeAutolinking = (projectRoot, platform) => {
358
477
  };
359
478
  function inspectBareProject(projectRoot, platforms) {
360
479
  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') : '';
480
+ const metro = inspectMetroConfig(projectRoot);
481
+ const hasBareMetroWrapper = !metro.issue &&
482
+ (0, metro_config_authority_1.hasAuthoritativeMetroWrapper)(metro.content, 'withBundleDrop');
363
483
  const checks = [
364
484
  {
365
485
  name: 'Bundle Drop config',
@@ -370,11 +490,12 @@ function inspectBareProject(projectRoot, platforms) {
370
490
  },
371
491
  {
372
492
  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.',
493
+ status: hasBareMetroWrapper ? 'pass' : 'error',
494
+ message: hasBareMetroWrapper
495
+ ? 'Metro uses the package-managed Bundle Drop wrapper.'
496
+ : metro.issue || 'Metro must export withBundleDrop(...) so generated trust data is bundled.',
377
497
  },
498
+ checkRuntimeDeliveryBootstrap(projectRoot),
378
499
  checkBarePackageMetadata(projectRoot),
379
500
  ];
380
501
  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,7 @@ const assertSetupPathAllowed = (file) => {
193
197
  const allowed = file === 'package.json' ||
194
198
  file === '.fingerprintignore' ||
195
199
  file === '.gitignore' ||
200
+ file === '.bundle-drop/runtime-delivery.generated.json' ||
196
201
  file === 'bundle.drop.config.js' ||
197
202
  file === 'app.json' ||
198
203
  /^app\.config\.(js|ts|cjs|mjs)$/.test(file) ||
@@ -203,61 +208,47 @@ const assertSetupPathAllowed = (file) => {
203
208
  };
204
209
  function restoreExpoConfiguration(result) {
205
210
  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
211
  if (changed.existed) {
209
- fs_extra_1.default.copyFileSync(backupPath, targetPath);
212
+ (0, safe_file_transaction_1.restoreProjectFile)(result.projectRoot, result.backupDir, changed.file);
210
213
  }
211
- else if (fs_extra_1.default.existsSync(targetPath)) {
212
- fs_extra_1.default.unlinkSync(targetPath);
214
+ else {
215
+ (0, safe_file_transaction_1.removeProjectFile)(result.projectRoot, changed.file);
213
216
  }
214
217
  }
215
218
  if (result.buildReceiptInvalidated) {
216
219
  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);
220
+ (0, safe_file_transaction_1.restoreProjectFile)(result.projectRoot, result.backupDir, receiptFile);
221
221
  }
222
222
  }
223
223
  function applyExpoConfigurationChanges(params) {
224
224
  const result = {
225
225
  projectRoot: params.projectRoot,
226
- backupDir: path_1.default.join(params.projectRoot, '.bundledrop-backup', new Date().toISOString().replace(/[:.]/g, '-')),
226
+ backupDir: (0, safe_file_transaction_1.createSafeBackupDirectory)(params.projectRoot, 'expo-setup'),
227
227
  changedFiles: [],
228
228
  buildReceiptInvalidated: false,
229
229
  };
230
230
  try {
231
231
  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);
232
+ const receipt = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, receiptFile);
233
+ if (receipt.exists) {
234
+ (0, safe_file_transaction_1.writeBackupFile)(result.backupDir, receiptFile, receipt.content, receipt.mode);
235
+ (0, safe_file_transaction_1.removeProjectFile)(params.projectRoot, receiptFile);
238
236
  result.buildReceiptInvalidated = true;
239
237
  }
240
238
  for (const change of params.changes) {
241
239
  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)) {
240
+ const target = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, change.file);
241
+ if (target.exists !== (change.original !== null)) {
245
242
  throw new Error(`File existence changed since Expo setup preview: ${change.file}`);
246
243
  }
247
- if (exists) {
248
- const current = fs_extra_1.default.readFileSync(targetPath, 'utf8');
249
- if (sha256(current) !== sha256(change.original || '')) {
244
+ if (target.exists) {
245
+ if (sha256(target.content) !== sha256(change.original || '')) {
250
246
  throw new Error(`File changed since Expo setup preview: ${change.file}`);
251
247
  }
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);
248
+ (0, safe_file_transaction_1.writeBackupFile)(result.backupDir, change.file, target.content, target.mode);
255
249
  }
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);
250
+ result.changedFiles.push({ file: change.file, existed: target.exists });
251
+ (0, safe_file_transaction_1.writeProjectFileAtomically)(params.projectRoot, change.file, change.updated, target.mode);
261
252
  }
262
253
  return result;
263
254
  }
@@ -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;