@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,63 +1,82 @@
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.detectPackageManager = detectPackageManager;
7
4
  exports.expoUpdatesRemovalCommand = expoUpdatesRemovalCommand;
5
+ exports.codePushRemovalCommand = codePushRemovalCommand;
8
6
  exports.restoreDependencyMigration = restoreDependencyMigration;
9
7
  exports.removeExpoUpdatesWithPackageManager = removeExpoUpdatesWithPackageManager;
10
- const fs_extra_1 = __importDefault(require("fs-extra"));
11
- const path_1 = __importDefault(require("path"));
8
+ exports.removeCodePushWithPackageManager = removeCodePushWithPackageManager;
12
9
  const child_process_1 = require("child_process");
10
+ const safe_file_transaction_1 = require("../safe-file-transaction");
13
11
  const LOCKFILES = {
14
12
  npm: ['package-lock.json', 'npm-shrinkwrap.json'],
15
13
  yarn: ['yarn.lock'],
16
14
  pnpm: ['pnpm-lock.yaml'],
17
15
  bun: ['bun.lock', 'bun.lockb'],
18
16
  };
17
+ const inspectPackageManagerInputs = (projectRoot) => {
18
+ const packageFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'package.json');
19
+ if (!packageFile.exists)
20
+ throw new Error('package.json is required for dependency migration.');
21
+ const lockfiles = new Set();
22
+ for (const lockfile of [...new Set(Object.values(LOCKFILES).flat())]) {
23
+ if ((0, safe_file_transaction_1.inspectProjectFile)(projectRoot, lockfile).exists)
24
+ lockfiles.add(lockfile);
25
+ }
26
+ return {
27
+ packageJson: JSON.parse(packageFile.content),
28
+ lockfiles,
29
+ };
30
+ };
19
31
  function detectPackageManager(projectRoot) {
20
- const packageJson = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(projectRoot, 'package.json'), 'utf8'));
32
+ const { packageJson, lockfiles } = inspectPackageManagerInputs(projectRoot);
21
33
  const declared = packageJson.packageManager?.split('@')[0];
22
34
  if (declared && declared in LOCKFILES)
23
35
  return declared;
24
36
  for (const manager of ['pnpm', 'yarn', 'bun', 'npm']) {
25
- if (LOCKFILES[manager].some(lockfile => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, lockfile)))) {
37
+ if (LOCKFILES[manager].some(lockfile => lockfiles.has(lockfile))) {
26
38
  return manager;
27
39
  }
28
40
  }
29
41
  return 'npm';
30
42
  }
31
- function expoUpdatesRemovalCommand(manager) {
43
+ const dependencyRemovalCommand = (manager, dependency) => {
32
44
  return manager === 'npm'
33
- ? ['npm', 'uninstall', 'expo-updates', '--legacy-peer-deps']
34
- : [manager, 'remove', 'expo-updates'];
45
+ ? ['npm', 'uninstall', dependency, '--legacy-peer-deps']
46
+ : [manager, 'remove', dependency];
47
+ };
48
+ function expoUpdatesRemovalCommand(manager) {
49
+ return dependencyRemovalCommand(manager, 'expo-updates');
50
+ }
51
+ function codePushRemovalCommand(manager) {
52
+ return dependencyRemovalCommand(manager, 'react-native-code-push');
35
53
  }
36
54
  function restoreDependencyMigration(backup) {
37
55
  for (const file of backup.files) {
38
- fs_extra_1.default.copyFileSync(path_1.default.join(backup.backupDir, file), path_1.default.join(backup.projectRoot, file));
56
+ (0, safe_file_transaction_1.restoreProjectFile)(backup.projectRoot, backup.backupDir, file);
39
57
  }
40
58
  for (const file of backup.possibleCreatedFiles) {
41
- const targetPath = path_1.default.join(backup.projectRoot, file);
42
- if (!backup.files.includes(file) && fs_extra_1.default.existsSync(targetPath)) {
43
- fs_extra_1.default.unlinkSync(targetPath);
59
+ if (!backup.files.includes(file)) {
60
+ (0, safe_file_transaction_1.removeProjectFile)(backup.projectRoot, file);
44
61
  }
45
62
  }
46
63
  }
47
- function removeExpoUpdatesWithPackageManager(projectRoot) {
64
+ const removeDependencyWithPackageManager = (params) => {
65
+ const { projectRoot, dependency, backupName } = params;
48
66
  const manager = detectPackageManager(projectRoot);
49
- const command = expoUpdatesRemovalCommand(manager);
50
- const files = ['package.json', ...LOCKFILES[manager]].filter(file => fs_extra_1.default.existsSync(path_1.default.join(projectRoot, file)));
67
+ const command = dependencyRemovalCommand(manager, dependency);
68
+ const files = ['package.json', ...LOCKFILES[manager]].filter(file => (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file).exists);
51
69
  const backup = {
52
70
  projectRoot,
53
- backupDir: path_1.default.join(projectRoot, '.bundledrop-backup', `expo-updates-${new Date().toISOString().replace(/[:.]/g, '-')}`),
71
+ backupDir: (0, safe_file_transaction_1.createSafeBackupDirectory)(projectRoot, backupName),
54
72
  files,
55
73
  possibleCreatedFiles: LOCKFILES[manager],
56
74
  };
57
75
  for (const file of files) {
58
- const backupPath = path_1.default.join(backup.backupDir, file);
59
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
60
- fs_extra_1.default.copyFileSync(path_1.default.join(projectRoot, file), backupPath);
76
+ const target = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file);
77
+ if (!target.exists)
78
+ throw new Error(`Package file disappeared before migration: ${file}`);
79
+ (0, safe_file_transaction_1.writeBackupFile)(backup.backupDir, file, target.content, target.mode);
61
80
  }
62
81
  const result = (0, child_process_1.spawnSync)(command[0], command.slice(1), {
63
82
  cwd: projectRoot,
@@ -66,19 +85,38 @@ function removeExpoUpdatesWithPackageManager(projectRoot) {
66
85
  });
67
86
  if (result.error || result.status !== 0) {
68
87
  restoreDependencyMigration(backup);
69
- throw new Error(`Failed to remove expo-updates with ${manager}. Package files were restored; ` +
88
+ throw new Error(`Failed to remove ${dependency} with ${manager}. Package files were restored; ` +
70
89
  'run your package manager install if node_modules needs repair.');
71
90
  }
72
- const packageJson = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(projectRoot, 'package.json'), 'utf8'));
91
+ const migratedPackage = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'package.json');
92
+ if (!migratedPackage.exists) {
93
+ restoreDependencyMigration(backup);
94
+ throw new Error(`${manager} completed but package.json is missing.`);
95
+ }
96
+ const packageJson = JSON.parse(migratedPackage.content);
73
97
  const stillDeclared = [
74
98
  packageJson.dependencies,
75
99
  packageJson.devDependencies,
76
100
  packageJson.optionalDependencies,
77
101
  packageJson.peerDependencies,
78
- ].some(dependencies => Boolean(dependencies?.['expo-updates']));
102
+ ].some(dependencies => Boolean(dependencies?.[dependency]));
79
103
  if (stillDeclared) {
80
104
  restoreDependencyMigration(backup);
81
- throw new Error(`${manager} completed but expo-updates is still declared in package.json.`);
105
+ throw new Error(`${manager} completed but ${dependency} is still declared in package.json.`);
82
106
  }
83
107
  return backup;
108
+ };
109
+ function removeExpoUpdatesWithPackageManager(projectRoot) {
110
+ return removeDependencyWithPackageManager({
111
+ projectRoot,
112
+ dependency: 'expo-updates',
113
+ backupName: 'expo-updates',
114
+ });
115
+ }
116
+ function removeCodePushWithPackageManager(projectRoot) {
117
+ return removeDependencyWithPackageManager({
118
+ projectRoot,
119
+ dependency: 'react-native-code-push',
120
+ backupName: 'code-push',
121
+ });
84
122
  }
@@ -1,4 +1,5 @@
1
1
  import type { ProjectType } from '../../expo';
2
+ import { type GeneratedRuntimeDeliveryBootstrap } from '../../runtime-delivery/bootstrapConfig';
2
3
  type Project = {
3
4
  name: string;
4
5
  slug: string;
@@ -9,6 +10,7 @@ type Org = {
9
10
  orgId: string;
10
11
  name: string;
11
12
  };
13
+ export { normalizeRuntimeDeliveryBootstrap } from '../../runtime-delivery/bootstrapConfig';
12
14
  export declare function getBundleDropConfigPath(startDir?: string): string;
13
15
  export declare function hasExistingBundleDropConfig(startDir?: string): boolean;
14
16
  export declare function initConfig(params: {
@@ -20,13 +22,11 @@ export declare function initConfig(params: {
20
22
  dryRun?: boolean;
21
23
  projectType?: ProjectType;
22
24
  }): Promise<{
23
- configPath: string;
24
- content: any;
25
- created: boolean;
26
- serverUrl?: undefined;
27
- orgSlug?: undefined;
28
- projectSlug?: undefined;
29
- } | {
25
+ bootstrapPath?: string;
26
+ bootstrapContent?: string;
27
+ bootstrap?: GeneratedRuntimeDeliveryBootstrap;
28
+ runtimeDeliveryAvailable?: boolean;
29
+ bootstrapRetired?: boolean;
30
30
  configPath: string;
31
31
  content: string;
32
32
  created: boolean;
@@ -3,19 +3,75 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeRuntimeDeliveryBootstrap = void 0;
6
7
  exports.getBundleDropConfigPath = getBundleDropConfigPath;
7
8
  exports.hasExistingBundleDropConfig = hasExistingBundleDropConfig;
8
9
  exports.initConfig = initConfig;
9
10
  const axios_1 = __importDefault(require("axios"));
10
11
  const chalk_1 = __importDefault(require("chalk"));
11
12
  const fs_extra_1 = __importDefault(require("fs-extra"));
13
+ const module_1 = require("module");
12
14
  const path_1 = __importDefault(require("path"));
13
15
  const prompts_1 = __importDefault(require("prompts"));
16
+ const bootstrapConfig_1 = require("../../runtime-delivery/bootstrapConfig");
17
+ const safe_file_transaction_1 = require("./safe-file-transaction");
14
18
  const DOCS_PROJECT_CREATION_URL = 'https://bundledrop.app/docs/project-creation';
15
19
  const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
20
+ var bootstrapConfig_2 = require("../../runtime-delivery/bootstrapConfig");
21
+ Object.defineProperty(exports, "normalizeRuntimeDeliveryBootstrap", { enumerable: true, get: function () { return bootstrapConfig_2.normalizeRuntimeDeliveryBootstrap; } });
16
22
  function normalizeServerUrl(url) {
17
23
  return url.replace(/\/$/, '');
18
24
  }
25
+ function isRecord(value) {
26
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
27
+ }
28
+ function validateProjectCredentials(value, expected) {
29
+ if (!isRecord(value)) {
30
+ throw new Error('Project credentials response is malformed. Existing local credentials were preserved.');
31
+ }
32
+ const projectId = typeof value.projectId === 'string' ? value.projectId.trim() : '';
33
+ const projectSlug = typeof value.projectSlug === 'string' ? value.projectSlug.trim() : '';
34
+ const orgId = typeof value.orgId === 'string' ? value.orgId.trim() : '';
35
+ const orgSlug = typeof value.orgSlug === 'string' ? value.orgSlug.trim() : '';
36
+ const runtimeDeliveryMode = value.runtimeDeliveryMode;
37
+ const downloadApiKey = value.downloadApiKey;
38
+ const downloadKeyHint = value.downloadKeyHint;
39
+ if (!projectId || !projectSlug || !orgId || !orgSlug) {
40
+ throw new Error('Project credentials response is missing its authoritative project identity. ' +
41
+ 'Existing local credentials were preserved.');
42
+ }
43
+ if (runtimeDeliveryMode !== undefined &&
44
+ !['v1', 'shadow', 'v2'].includes(runtimeDeliveryMode)) {
45
+ throw new Error('Project credentials response contains an invalid legacy runtime delivery mode. ' +
46
+ 'Existing local credentials were preserved.');
47
+ }
48
+ if (projectSlug !== expected.projectSlug || orgSlug !== expected.orgSlug) {
49
+ throw new Error(`Project credentials identity mismatch: expected ${expected.orgSlug}/${expected.projectSlug}, ` +
50
+ `received ${orgSlug}/${projectSlug}. Existing local credentials were preserved.`);
51
+ }
52
+ if (downloadApiKey !== undefined && typeof downloadApiKey !== 'string') {
53
+ throw new Error('Project credentials response contains an invalid download key. Existing local credentials were preserved.');
54
+ }
55
+ if (downloadKeyHint !== undefined &&
56
+ downloadKeyHint !== null &&
57
+ typeof downloadKeyHint !== 'string') {
58
+ throw new Error('Project credentials response contains an invalid download key hint. Existing local credentials were preserved.');
59
+ }
60
+ return {
61
+ projectId,
62
+ projectSlug,
63
+ orgId,
64
+ orgSlug,
65
+ runtimeDeliveryMode: runtimeDeliveryMode,
66
+ downloadApiKey: typeof downloadApiKey === 'string' ? downloadApiKey : undefined,
67
+ downloadKeyHint: typeof downloadKeyHint === 'string'
68
+ ? downloadKeyHint
69
+ : downloadKeyHint === null
70
+ ? null
71
+ : undefined,
72
+ runtimeDelivery: value.runtimeDelivery,
73
+ };
74
+ }
19
75
  function createBundleDropConfig(values) {
20
76
  const projectTypeConfig = values.projectType
21
77
  ? ` projectType: ${JSON.stringify(values.projectType)},\n`
@@ -62,22 +118,100 @@ ${projectTypeConfig} serverUrl: ${JSON.stringify(values.serverUrl)},
62
118
  }
63
119
  async function fetchProjectCredentials(params) {
64
120
  const baseUrl = normalizeServerUrl(params.serverUrl);
65
- const url = `${baseUrl}/projects/${encodeURIComponent(params.projectSlug)}/credentials`;
121
+ const url = `${baseUrl}/projects/${encodeURIComponent(params.projectSlug)}/credentials` +
122
+ `?orgSlug=${encodeURIComponent(params.orgSlug)}`;
123
+ let response;
66
124
  try {
67
- const res = await axios_1.default.get(url, {
125
+ response = await axios_1.default.get(url, {
68
126
  headers: {
69
127
  Accept: 'application/json',
70
128
  Authorization: `Bearer ${params.authToken}`,
71
129
  },
72
130
  timeout: 15000,
73
131
  });
74
- return res.data || null;
75
132
  }
76
133
  catch (err) {
77
134
  console.log(chalk_1.default.yellow(`⚠️ Failed to fetch project credentials from ${url}. Please verify login and project access.\n` +
78
135
  `If the project is not set up yet, see ${DOCS_PROJECT_CREATION_URL}`));
79
136
  return null;
80
137
  }
138
+ return validateProjectCredentials(response.data, {
139
+ orgSlug: params.orgSlug,
140
+ projectSlug: params.projectSlug,
141
+ });
142
+ }
143
+ function createBootstrapResult(params) {
144
+ if (!params.credentials)
145
+ return {};
146
+ const legacyMode = params.credentials.runtimeDeliveryMode;
147
+ if (params.credentials.runtimeDelivery === null ||
148
+ legacyMode === 'v1' ||
149
+ legacyMode === 'shadow') {
150
+ return {
151
+ runtimeDeliveryAvailable: false,
152
+ bootstrapRetired: true,
153
+ };
154
+ }
155
+ const bootstrap = (0, bootstrapConfig_1.createGeneratedRuntimeDeliveryBootstrap)({
156
+ identity: {
157
+ serverUrl: params.serverUrl,
158
+ orgSlug: params.orgSlug,
159
+ projectSlug: params.projectSlug,
160
+ projectId: params.credentials.projectId,
161
+ orgId: params.credentials.orgId,
162
+ },
163
+ runtimeDelivery: params.credentials.runtimeDelivery,
164
+ });
165
+ if (!bootstrap) {
166
+ return legacyMode === 'v2' || params.credentials.runtimeDelivery !== undefined
167
+ ? { runtimeDeliveryAvailable: true }
168
+ : {};
169
+ }
170
+ return {
171
+ bootstrap,
172
+ bootstrapPath: (0, bootstrapConfig_1.runtimeDeliveryBootstrapPath)(params.projectRoot),
173
+ bootstrapContent: (0, bootstrapConfig_1.serializeGeneratedRuntimeDeliveryBootstrap)(bootstrap),
174
+ runtimeDeliveryAvailable: true,
175
+ };
176
+ }
177
+ async function persistBootstrap(projectRoot, result) {
178
+ if (result.bootstrap) {
179
+ const bootstrapPath = await (0, bootstrapConfig_1.writeGeneratedRuntimeDeliveryBootstrap)({
180
+ projectRoot,
181
+ bootstrap: result.bootstrap,
182
+ });
183
+ await (0, bootstrapConfig_1.ensureRuntimeDeliveryBootstrapGitignore)(projectRoot);
184
+ console.log(chalk_1.default.green(`✅ Synced Bundle Drop runtime delivery bootstrap at ${bootstrapPath}`));
185
+ return;
186
+ }
187
+ if (result.bootstrapRetired) {
188
+ const bootstrapPath = await (0, bootstrapConfig_1.removeGeneratedRuntimeDeliveryBootstrap)(projectRoot);
189
+ console.log(chalk_1.default.green(bootstrapPath
190
+ ? `✅ Removed the runtime delivery bootstrap because delivery is disabled for this project: ${bootstrapPath}`
191
+ : '✅ Runtime delivery is disabled for this project; no bootstrap is present.'));
192
+ }
193
+ }
194
+ function loadExistingConfig(configPath, content) {
195
+ try {
196
+ const moduleLike = { exports: {} };
197
+ const localRequire = (0, module_1.createRequire)(configPath);
198
+ const load = new Function('module', 'exports', 'require', '__dirname', '__filename', content);
199
+ load(moduleLike, moduleLike.exports, localRequire, path_1.default.dirname(configPath), configPath);
200
+ const config = moduleLike.exports;
201
+ if (!config.serverUrl || !config.org?.slug || !config.project?.slug)
202
+ return null;
203
+ return {
204
+ projectType: config.projectType,
205
+ serverUrl: normalizeServerUrl(config.serverUrl),
206
+ orgSlug: config.org.slug,
207
+ projectName: config.project.name || '',
208
+ projectSlug: config.project.slug,
209
+ apiKey: config.project.apiKey || '',
210
+ };
211
+ }
212
+ catch {
213
+ return null;
214
+ }
81
215
  }
82
216
  function findProjectRoot(startDir) {
83
217
  let dir = path_1.default.resolve(startDir);
@@ -101,13 +235,42 @@ function hasExistingBundleDropConfig(startDir = process.cwd()) {
101
235
  }
102
236
  async function initConfig(params) {
103
237
  const configPath = getBundleDropConfigPath();
104
- if (fs_extra_1.default.existsSync(configPath)) {
105
- console.log(chalk_1.default.yellow(`ℹ️ bundle.drop.config.js already exists at ${configPath}. If this is accidental, delete it and rerun the init/login.\n` +
106
- `See ${DOCS_INSTALLATION_URL}`));
238
+ const projectRoot = path_1.default.dirname(configPath);
239
+ const existingConfigFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'bundle.drop.config.js');
240
+ if (existingConfigFile.exists) {
241
+ const existing = loadExistingConfig(configPath, existingConfigFile.content);
242
+ let bootstrapResult = {};
243
+ if (existing && params.authToken) {
244
+ const credentials = await fetchProjectCredentials({
245
+ serverUrl: existing.serverUrl,
246
+ orgSlug: existing.orgSlug,
247
+ projectSlug: existing.projectSlug,
248
+ authToken: params.authToken,
249
+ });
250
+ bootstrapResult = createBootstrapResult({
251
+ projectRoot,
252
+ serverUrl: existing.serverUrl,
253
+ orgSlug: existing.orgSlug,
254
+ projectSlug: existing.projectSlug,
255
+ credentials,
256
+ });
257
+ if (!params.dryRun)
258
+ await persistBootstrap(projectRoot, bootstrapResult);
259
+ }
260
+ console.log(chalk_1.default.yellow(`ℹ️ Preserving existing bundle.drop.config.js at ${configPath}.` +
261
+ (bootstrapResult.bootstrap
262
+ ? ' Runtime delivery bootstrap is ready to sync.'
263
+ : bootstrapResult.bootstrapRetired
264
+ ? ' Runtime delivery setup is synchronized.'
265
+ : ` No valid runtime delivery bootstrap was returned; see ${DOCS_INSTALLATION_URL}`)));
107
266
  return {
108
267
  configPath,
109
- content: fs_extra_1.default.readFileSync(configPath, 'utf8'),
268
+ content: existingConfigFile.content,
110
269
  created: false,
270
+ serverUrl: existing?.serverUrl,
271
+ orgSlug: existing?.orgSlug,
272
+ projectSlug: existing?.projectSlug,
273
+ ...bootstrapResult,
111
274
  };
112
275
  }
113
276
  let orgSlug = '';
@@ -173,10 +336,12 @@ async function initConfig(params) {
173
336
  orgSlug = org.slug;
174
337
  }
175
338
  let resolvedServerUrl = normalizeServerUrl(params.serverUrl);
176
- let apiKey = params.downloadApiKey || '';
339
+ let apiKey = params.authToken ? '' : params.downloadApiKey || '';
340
+ let credentials = null;
177
341
  if (projectSlug && params.authToken) {
178
- const credentials = await fetchProjectCredentials({
342
+ credentials = await fetchProjectCredentials({
179
343
  serverUrl: resolvedServerUrl,
344
+ orgSlug,
180
345
  projectSlug,
181
346
  authToken: params.authToken,
182
347
  });
@@ -211,9 +376,18 @@ async function initConfig(params) {
211
376
  console.log(chalk_1.default.cyan(`Dry-run bundle.drop.config.js preview:\n${previewContent}`));
212
377
  }
213
378
  else {
214
- await fs_extra_1.default.writeFile(configPath, content, 'utf8');
379
+ (0, safe_file_transaction_1.writeProjectFileAtomically)(projectRoot, 'bundle.drop.config.js', content);
215
380
  console.log(chalk_1.default.green(`✅ Created bundle.drop.config.js at ${configPath}`));
216
381
  }
382
+ const bootstrapResult = createBootstrapResult({
383
+ projectRoot,
384
+ serverUrl: resolvedServerUrl,
385
+ orgSlug,
386
+ projectSlug,
387
+ credentials,
388
+ });
389
+ if (!params.dryRun)
390
+ await persistBootstrap(projectRoot, bootstrapResult);
217
391
  return {
218
392
  configPath,
219
393
  content,
@@ -221,6 +395,7 @@ async function initConfig(params) {
221
395
  serverUrl: resolvedServerUrl,
222
396
  orgSlug,
223
397
  projectSlug,
398
+ ...bootstrapResult,
224
399
  };
225
400
  }
226
401
  exports.default = initConfig;
@@ -267,8 +267,16 @@ const login = async () => {
267
267
  });
268
268
  loginCompleted = true;
269
269
  console.log(chalk_1.default.green('✅ Logged in successfully as:'), chalk_1.default.cyan(`${authFile.user.firstName} ${authFile.user.lastName}`));
270
- if ((0, init_config_1.hasExistingBundleDropConfig)()) {
271
- console.log(chalk_1.default.gray(`ℹ️ Found existing bundle.drop.config.js at ${(0, init_config_1.getBundleDropConfigPath)()}. Skipping setup prompts.`));
270
+ const hadConfig = (0, init_config_1.hasExistingBundleDropConfig)();
271
+ if (hadConfig) {
272
+ await (0, init_config_1.initConfig)({
273
+ serverUrl: baseUrl,
274
+ projects: authFile.projects,
275
+ organizations: authFile.organizations,
276
+ downloadApiKey: authFile.downloadApiKey,
277
+ authToken: authFile.token,
278
+ dryRun: false,
279
+ });
272
280
  return;
273
281
  }
274
282
  const projectType = (0, expo_1.detectProjectType)({ projectRoot: process.cwd() });
@@ -278,12 +286,29 @@ const login = async () => {
278
286
  organizations: authFile.organizations,
279
287
  downloadApiKey: authFile.downloadApiKey,
280
288
  authToken: authFile.token,
289
+ dryRun: true,
281
290
  projectType,
282
291
  });
283
- if (configResult?.created) {
292
+ if (configResult && fs_extra_1.default.existsSync(configResult.configPath)) {
284
293
  createdConfigPath = configResult.configPath;
285
294
  }
286
- await (0, post_init_1.runPostInitPrompts)({ projectType });
295
+ await (0, post_init_1.runPostInitPrompts)({
296
+ projectType,
297
+ ...(configResult?.bootstrapContent
298
+ ? { runtimeDeliveryBootstrap: { content: configResult.bootstrapContent } }
299
+ : {}),
300
+ ...(configResult
301
+ ? {
302
+ virtualConfig: {
303
+ content: configResult.content,
304
+ serverUrl: configResult.serverUrl,
305
+ orgSlug: configResult.orgSlug,
306
+ projectSlug: configResult.projectSlug,
307
+ authToken: authFile.token,
308
+ },
309
+ }
310
+ : {}),
311
+ });
287
312
  }
288
313
  catch (error) {
289
314
  const message = axios_1.default.isAxiosError(error)
@@ -0,0 +1,8 @@
1
+ export declare const METRO_CONFIG_FILES: readonly ["metro.config.js", "metro.config.cjs", "metro.config.mjs", "metro.config.ts"];
2
+ export type MetroWrapper = 'withBundleDrop' | 'withBundleDropExpo';
3
+ export declare const hasExecutableMetroWrapperReference: (source: string, wrapper: MetroWrapper) => boolean;
4
+ export declare const hasExecutableMetroModuleReference: (source: string, moduleName: string) => boolean;
5
+ export declare const hasAuthoritativeMetroWrapper: (source: string, wrapper: MetroWrapper) => boolean;
6
+ export declare const findSingleMetroConfig: (projectRoot: string) => "metro.config.js" | "metro.config.cjs" | "metro.config.mjs" | "metro.config.ts";
7
+ export declare const newCommonJsMetroConfigFile: (projectRoot: string) => "metro.config.js" | "metro.config.cjs";
8
+ export declare const assertCommonJsMetroConfig: (projectRoot: string, relativePath: string) => void;