@gfean/react-native-bundle-drop 0.4.6 → 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 (102) 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 +166 -79
  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 +228 -43
  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 +246 -32
  35. package/lib/CLI/scripts/login-cli.js +35 -10
  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/CLI/scripts/sight-artifacts.d.ts +17 -0
  47. package/lib/CLI/scripts/sight-artifacts.js +204 -0
  48. package/lib/CLI/scripts/sight-cli.d.ts +10 -0
  49. package/lib/CLI/scripts/sight-cli.js +127 -0
  50. package/lib/CLI/scripts/sight-session.d.ts +14 -0
  51. package/lib/CLI/scripts/sight-session.js +192 -0
  52. package/lib/api/clientApi.d.ts +3 -1
  53. package/lib/api/clientApi.js +14 -0
  54. package/lib/api/types.d.ts +39 -0
  55. package/lib/context.d.ts +1 -1
  56. package/lib/index.d.ts +2 -0
  57. package/lib/index.js +3 -1
  58. package/lib/install/installFromZip.d.ts +3 -0
  59. package/lib/install/installFromZip.js +10 -1
  60. package/lib/loadConfig.d.ts +17 -1
  61. package/lib/loadConfig.js +16 -0
  62. package/lib/manager/downloadAndInstall.d.ts +3 -2
  63. package/lib/manager/downloadAndInstall.js +111 -46
  64. package/lib/manager/rollbackState.d.ts +3 -1
  65. package/lib/manager/rollbackState.js +2 -2
  66. package/lib/manager/updateCheck.d.ts +1 -0
  67. package/lib/manager/updateCheck.js +218 -78
  68. package/lib/metro.d.ts +8 -1
  69. package/lib/metro.js +68 -19
  70. package/lib/native/bundleDropNative.js +2 -1
  71. package/lib/native/fs.d.ts +6 -0
  72. package/lib/native/fs.js +24 -0
  73. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  74. package/lib/patch-engine/installFromPatchSet.js +14 -3
  75. package/lib/patch-engine/patchTransport.d.ts +2 -0
  76. package/lib/patch-engine/patchTransport.js +9 -0
  77. package/lib/runtime/initState.d.ts +5 -0
  78. package/lib/runtime/initState.js +4 -0
  79. package/lib/runtime/service.js +60 -3
  80. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  81. package/lib/runtime-delivery/artifactCapability.js +32 -0
  82. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  83. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  84. package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
  85. package/lib/runtime-delivery/bootstrapConfig.js +217 -0
  86. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  87. package/lib/runtime-delivery/diagnostics.js +58 -0
  88. package/lib/runtime-delivery/encoding.d.ts +5 -0
  89. package/lib/runtime-delivery/encoding.js +132 -0
  90. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  91. package/lib/runtime-delivery/heartbeat.js +88 -0
  92. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  93. package/lib/runtime-delivery/localResolver.js +81 -0
  94. package/lib/runtime-delivery/manifestState.d.ts +9 -0
  95. package/lib/runtime-delivery/manifestState.js +102 -0
  96. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  97. package/lib/runtime-delivery/manifestVerifier.js +329 -0
  98. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  99. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  100. package/lib/runtime-delivery/types.d.ts +87 -0
  101. package/lib/runtime-delivery/types.js +6 -0
  102. 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,37 +3,215 @@ 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
+ }
75
+ function createBundleDropConfig(values) {
76
+ const projectTypeConfig = values.projectType
77
+ ? ` projectType: ${JSON.stringify(values.projectType)},\n`
78
+ : '';
79
+ return `module.exports = {
80
+ ${projectTypeConfig} serverUrl: ${JSON.stringify(values.serverUrl)},
81
+ defaultChannel: 'develop',
82
+ runtimeVersion: {
83
+ ios: '1.0.0',
84
+ android: '1.0.0',
85
+ },
86
+ org: {
87
+ slug: ${JSON.stringify(values.orgSlug)},
88
+ },
89
+ project: {
90
+ name: ${JSON.stringify(values.projectName)},
91
+ slug: ${JSON.stringify(values.projectSlug)},
92
+ apiKey: ${JSON.stringify(values.apiKey)},
93
+ },
94
+ };
95
+ `;
96
+ }
97
+ function createRedactedBundleDropConfigPreview(values) {
98
+ const projectTypeConfig = values.projectType
99
+ ? ` projectType: ${JSON.stringify(values.projectType)},\n`
100
+ : '';
101
+ return `module.exports = {
102
+ ${projectTypeConfig} serverUrl: ${JSON.stringify(values.serverUrl)},
103
+ defaultChannel: 'develop',
104
+ runtimeVersion: {
105
+ ios: '1.0.0',
106
+ android: '1.0.0',
107
+ },
108
+ org: {
109
+ slug: ${JSON.stringify(values.orgSlug)},
110
+ },
111
+ project: {
112
+ name: ${JSON.stringify(values.projectName)},
113
+ slug: ${JSON.stringify(values.projectSlug)},
114
+ apiKey: "<redacted>",
115
+ },
116
+ };
117
+ `;
118
+ }
19
119
  async function fetchProjectCredentials(params) {
20
120
  const baseUrl = normalizeServerUrl(params.serverUrl);
21
- 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;
22
124
  try {
23
- const res = await axios_1.default.get(url, {
125
+ response = await axios_1.default.get(url, {
24
126
  headers: {
25
127
  Accept: 'application/json',
26
128
  Authorization: `Bearer ${params.authToken}`,
27
129
  },
28
130
  timeout: 15000,
29
131
  });
30
- return res.data || null;
31
132
  }
32
133
  catch (err) {
33
134
  console.log(chalk_1.default.yellow(`⚠️ Failed to fetch project credentials from ${url}. Please verify login and project access.\n` +
34
135
  `If the project is not set up yet, see ${DOCS_PROJECT_CREATION_URL}`));
35
136
  return null;
36
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
+ }
37
215
  }
38
216
  function findProjectRoot(startDir) {
39
217
  let dir = path_1.default.resolve(startDir);
@@ -57,13 +235,42 @@ function hasExistingBundleDropConfig(startDir = process.cwd()) {
57
235
  }
58
236
  async function initConfig(params) {
59
237
  const configPath = getBundleDropConfigPath();
60
- if (fs_extra_1.default.existsSync(configPath)) {
61
- 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` +
62
- `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}`)));
63
266
  return {
64
267
  configPath,
65
- content: fs_extra_1.default.readFileSync(configPath, 'utf8'),
268
+ content: existingConfigFile.content,
66
269
  created: false,
270
+ serverUrl: existing?.serverUrl,
271
+ orgSlug: existing?.orgSlug,
272
+ projectSlug: existing?.projectSlug,
273
+ ...bootstrapResult,
67
274
  };
68
275
  }
69
276
  let orgSlug = '';
@@ -129,10 +336,12 @@ async function initConfig(params) {
129
336
  orgSlug = org.slug;
130
337
  }
131
338
  let resolvedServerUrl = normalizeServerUrl(params.serverUrl);
132
- let apiKey = params.downloadApiKey || '';
339
+ let apiKey = params.authToken ? '' : params.downloadApiKey || '';
340
+ let credentials = null;
133
341
  if (projectSlug && params.authToken) {
134
- const credentials = await fetchProjectCredentials({
342
+ credentials = await fetchProjectCredentials({
135
343
  serverUrl: resolvedServerUrl,
344
+ orgSlug,
136
345
  projectSlug,
137
346
  authToken: params.authToken,
138
347
  });
@@ -147,34 +356,38 @@ async function initConfig(params) {
147
356
  else if (projectSlug && !params.authToken && !apiKey) {
148
357
  console.log(chalk_1.default.yellow('⚠️ Missing auth token; cannot fetch project API key.'));
149
358
  }
150
- const projectTypeConfig = params.projectType
151
- ? ` projectType: '${params.projectType}',\n`
152
- : '';
153
- const runtimeVersionConfig = ` runtimeVersion: {
154
- ios: '1.0.0',
155
- android: '1.0.0',
156
- },`;
157
- const content = `module.exports = {
158
- ${projectTypeConfig} serverUrl: '${resolvedServerUrl}',
159
- defaultChannel: 'develop',
160
- ${runtimeVersionConfig}
161
- org: {
162
- slug: '${orgSlug}',
163
- },
164
- project: {
165
- name: '${projectName.replace(/'/g, "\\'")}',
166
- slug: '${projectSlug}',
167
- apiKey: '${apiKey.replace(/'/g, "\\'")}',
168
- },
169
- };
170
- `;
359
+ const configValues = {
360
+ projectType: params.projectType,
361
+ serverUrl: resolvedServerUrl,
362
+ orgSlug,
363
+ projectName,
364
+ projectSlug,
365
+ apiKey,
366
+ };
367
+ const content = createBundleDropConfig(configValues);
171
368
  if (params.dryRun) {
172
- console.log(chalk_1.default.cyan(`Dry-run bundle.drop.config.js preview:\n${content}`));
369
+ const previewContent = createRedactedBundleDropConfigPreview({
370
+ projectType: params.projectType,
371
+ serverUrl: resolvedServerUrl,
372
+ orgSlug,
373
+ projectName,
374
+ projectSlug,
375
+ });
376
+ console.log(chalk_1.default.cyan(`Dry-run bundle.drop.config.js preview:\n${previewContent}`));
173
377
  }
174
378
  else {
175
- await fs_extra_1.default.writeFile(configPath, content, 'utf8');
379
+ (0, safe_file_transaction_1.writeProjectFileAtomically)(projectRoot, 'bundle.drop.config.js', content);
176
380
  console.log(chalk_1.default.green(`✅ Created bundle.drop.config.js at ${configPath}`));
177
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);
178
391
  return {
179
392
  configPath,
180
393
  content,
@@ -182,6 +395,7 @@ ${runtimeVersionConfig}
182
395
  serverUrl: resolvedServerUrl,
183
396
  orgSlug,
184
397
  projectSlug,
398
+ ...bootstrapResult,
185
399
  };
186
400
  }
187
401
  exports.default = initConfig;
@@ -16,7 +16,7 @@ const init_config_1 = require("./init-config");
16
16
  const post_init_1 = require("./post-init");
17
17
  const expo_1 = require("../../expo");
18
18
  const LOGIN_TIMEOUT_MS = 10 * 60 * 1000;
19
- const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
19
+ const DOCS_MANUAL_SETUP_URL = 'https://bundledrop.app/docs/manual-setup';
20
20
  const getBaseUrl = () => process.env.BUNDLE_DROP_SERVER_URL
21
21
  ? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
22
22
  : 'https://api.bundledrop.app';
@@ -45,7 +45,7 @@ const openBrowser = async (url) => {
45
45
  const command = platform === 'darwin'
46
46
  ? { file: 'open', args: [url] }
47
47
  : platform === 'win32'
48
- ? { file: 'cmd', args: ['/c', 'start', '', url] }
48
+ ? { file: 'explorer.exe', args: [url] }
49
49
  : { file: 'xdg-open', args: [url] };
50
50
  await new Promise((resolve, reject) => {
51
51
  const child = (0, child_process_1.spawn)(command.file, command.args, {
@@ -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,24 +286,41 @@ 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
- if (createdConfigPath) {
290
- await fs_extra_1.default.remove(createdConfigPath);
291
- }
292
314
  const message = axios_1.default.isAxiosError(error)
293
315
  ? error.response?.data?.error || error.message
294
316
  : error.message;
295
317
  const failureLabel = loginCompleted ? '❌ Setup failed after login:' : '❌ Login failed:';
296
318
  console.error(chalk_1.default.red(failureLabel), message);
297
319
  if (loginCompleted) {
298
- console.error(chalk_1.default.gray(`Manual installation: ${DOCS_INSTALLATION_URL}`));
320
+ if (createdConfigPath) {
321
+ console.error(chalk_1.default.gray(`Project config retained at ${createdConfigPath}`));
322
+ }
323
+ console.error(chalk_1.default.gray(`Manual setup: ${DOCS_MANUAL_SETUP_URL}`));
299
324
  }
300
325
  process.exitCode = 1;
301
326
  }
@@ -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;