@gfean/react-native-bundle-drop 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +34 -9
  3. package/android/build.gradle +65 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +137 -13
  5. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  7. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  8. package/ios/BundleDropBridge.m +27 -0
  9. package/ios/BundleDropLocator.swift +31 -15
  10. package/ios/BundleDropModule.swift +106 -3
  11. package/ios/BundleDropOtaResolver.swift +137 -29
  12. package/ios/BundleDropStartupRecovery.swift +1108 -0
  13. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  14. package/lib/CLI/cli.js +4 -5
  15. package/lib/CLI/scripts/doctor.js +28 -9
  16. package/lib/CLI/scripts/expo/configure-expo.js +2 -1
  17. package/lib/CLI/scripts/init-config.d.ts +2 -2
  18. package/lib/CLI/scripts/init-config.js +23 -14
  19. package/lib/CLI/scripts/login-cli.js +2 -3
  20. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  21. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  22. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  23. package/lib/CLI/scripts/upload-cli.js +74 -11
  24. package/lib/CLI/serverUrl.d.ts +3 -0
  25. package/lib/CLI/serverUrl.js +31 -0
  26. package/lib/bundleInfo.d.ts +2 -0
  27. package/lib/bundleInfo.js +16 -1
  28. package/lib/context.js +12 -2
  29. package/lib/fs/bundlePointer.d.ts +1 -17
  30. package/lib/fs/bundlePointer.js +5 -93
  31. package/lib/install/bundleInstallShared.js +4 -4
  32. package/lib/manager/downloadAndInstall.js +25 -22
  33. package/lib/manager/reporting.d.ts +8 -1
  34. package/lib/manager/reporting.js +17 -22
  35. package/lib/manager/rollbackState.d.ts +18 -54
  36. package/lib/manager/rollbackState.js +115 -216
  37. package/lib/manager/updateCheck.js +9 -3
  38. package/lib/manager/updateState.d.ts +2 -1
  39. package/lib/manager/updateState.js +59 -6
  40. package/lib/metro.d.ts +1 -1
  41. package/lib/metro.js +4 -3
  42. package/lib/native/bundleDropNative.d.ts +62 -0
  43. package/lib/native/bundleDropNative.js +266 -1
  44. package/lib/patch-engine/installFromPatchSet.js +2 -2
  45. package/lib/runtime/service.js +29 -71
  46. package/lib/runtime-delivery/bootstrapConfig.d.ts +29 -11
  47. package/lib/runtime-delivery/bootstrapConfig.js +83 -22
  48. package/lib/runtime-delivery/manifestState.d.ts +3 -1
  49. package/lib/runtime-delivery/manifestState.js +22 -1
  50. package/lib/runtime-delivery/manifestVerifier.js +7 -1
  51. package/lib/scripts/bundle.d.ts +9 -2
  52. package/lib/scripts/bundle.js +68 -18
  53. package/lib/scripts/download-bundle.d.ts +1 -0
  54. package/lib/scripts/download-bundle.js +2 -2
  55. package/lib/scripts/resolveModule.d.ts +2 -0
  56. package/lib/scripts/resolveModule.js +5 -0
  57. package/package.json +5 -2
  58. package/plugin/xcodeBuildPhase.js +2 -1
@@ -0,0 +1,301 @@
1
+ import Foundation
2
+ import ObjectiveC.runtime
3
+
4
+ /// Process-level integration between the startup ledger and React Native's
5
+ /// lifecycle. The controller itself remains Foundation-only and directly testable.
6
+ enum BundleDropStartupRecoveryAdapter {
7
+ static let protocolVersion = BundleDropStartupRecoveryController.protocolVersion
8
+
9
+ private static let lock = NSRecursiveLock()
10
+ private static let processToken = UUID().uuidString.lowercased()
11
+ private static var recoveryController: BundleDropStartupRecoveryController?
12
+ private static var activeAttemptHash: String?
13
+ private static var activeAttemptId: String?
14
+ private static var selectedHash: String?
15
+ private static var observersInstalled = false
16
+ private static let contentBindings = BundleDropStartupContentBindings()
17
+
18
+ static func selectStartupBundle(bundleDropRoot: URL) -> URL? {
19
+ installReactLifecycleObservers()
20
+ let selection = controller(bundleDropRoot: bundleDropRoot).selectStartupBundle()
21
+ captureStartupSelection(selection)
22
+ return selection.bundleURL
23
+ }
24
+
25
+ static func downloadedBundleURL() -> URL? {
26
+ guard BundleDropLocatorCore.hasRuntimeIdentityForOta(),
27
+ BundleDropLocatorCore.isOtaEnabled(),
28
+ let root = defaultRoot() else {
29
+ return nil
30
+ }
31
+ return controller(bundleDropRoot: root).passiveCurrentBundle()
32
+ }
33
+
34
+ static func activateCandidate(
35
+ hash: String,
36
+ maxCrashCount: Int,
37
+ healthCheckMode: String,
38
+ healthyAfterSec: Double
39
+ ) throws -> BundleDropStartupActivationResult {
40
+ try requireDefaultController().activateCandidate(
41
+ hash: hash,
42
+ maxCrashCount: maxCrashCount,
43
+ healthCheckMode: healthCheckMode,
44
+ healthyAfterSec: healthyAfterSec
45
+ )
46
+ }
47
+
48
+ static func beginReload() -> URL? {
49
+ guard let controller = defaultController() else { return nil }
50
+ installReactLifecycleObservers()
51
+ let selection = controller.selectStartupBundle(beginReload: true)
52
+ captureStartupSelection(selection)
53
+ return selection.bundleURL
54
+ }
55
+
56
+ static func markHealthy(hash: String, attemptId: String) -> Bool {
57
+ guard let controller = defaultController() else { return false }
58
+ let marked = controller.markHealthy(hash: hash, attemptId: attemptId)
59
+ if marked { clearCapturedAttempt() }
60
+ return marked
61
+ }
62
+
63
+ static func snapshot() throws -> [String: Any] {
64
+ try requireDefaultController().snapshot()
65
+ }
66
+
67
+ static func setRevokedHashes(_ hashes: [String]) throws -> Bool {
68
+ try requireDefaultController().setRevokedHashes(hashes)
69
+ return true
70
+ }
71
+
72
+ static func acknowledgeRecovery(eventId: String) throws -> Bool {
73
+ try requireDefaultController().acknowledgeRecovery(eventId: eventId)
74
+ }
75
+
76
+ static func rollback(forceEmbedded: Bool) throws -> BundleDropStartupRollbackResult {
77
+ let result = try requireDefaultController().rollback(forceEmbedded: forceEmbedded)
78
+ clearCapturedAttempt()
79
+ return result
80
+ }
81
+
82
+ static func capturedAttempt() -> (hash: String?, attemptId: String?) {
83
+ lock.lock()
84
+ defer { lock.unlock() }
85
+ return (activeAttemptHash, activeAttemptId)
86
+ }
87
+
88
+ static func clearCapturedAttempt() {
89
+ captureAttempt(hash: nil, attemptId: nil)
90
+ }
91
+
92
+ static func capturedSelectedHash() -> String? {
93
+ lock.lock()
94
+ defer { lock.unlock() }
95
+ return selectedHash
96
+ }
97
+
98
+ static func clearCapturedSelection() {
99
+ lock.lock()
100
+ activeAttemptHash = nil
101
+ activeAttemptId = nil
102
+ selectedHash = nil
103
+ contentBindings.capture(hash: nil, attemptId: nil, bundleURL: nil)
104
+ lock.unlock()
105
+ }
106
+
107
+ static func captureStartupSelection(_ selection: BundleDropStartupSelection) {
108
+ lock.lock()
109
+ activeAttemptHash = selection.attemptHash
110
+ activeAttemptId = selection.attemptId
111
+ let bundleHash = selection.bundleURL?
112
+ .deletingLastPathComponent()
113
+ .lastPathComponent
114
+ selectedHash = bundleHash?.range(
115
+ of: "^[a-f0-9]{64}$",
116
+ options: .regularExpression
117
+ ) == nil ? nil : bundleHash
118
+ contentBindings.capture(
119
+ hash: selection.attemptHash,
120
+ attemptId: selection.attemptId,
121
+ bundleURL: selection.bundleURL
122
+ )
123
+ lock.unlock()
124
+ }
125
+
126
+ private static func defaultRoot() -> URL? {
127
+ FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first?
128
+ .appendingPathComponent("bundle-drop", isDirectory: true)
129
+ }
130
+
131
+ private static func defaultController() -> BundleDropStartupRecoveryController? {
132
+ defaultRoot().map(controller)
133
+ }
134
+
135
+ private static func requireDefaultController() throws -> BundleDropStartupRecoveryController {
136
+ guard let controller = defaultController() else {
137
+ throw BundleDropStartupRecoveryError.storageUnavailable
138
+ }
139
+ return controller
140
+ }
141
+
142
+ private static func controller(bundleDropRoot: URL) -> BundleDropStartupRecoveryController {
143
+ lock.lock()
144
+ defer { lock.unlock() }
145
+ if let recoveryController { return recoveryController }
146
+ let created = BundleDropStartupRecoveryController(
147
+ bundleDropRoot: bundleDropRoot,
148
+ expectedRuntimeVersion: BundleDropLocatorCore.getRuntimeVersion(),
149
+ expectedBinaryIdentity: BundleDropLocatorCore.getBinaryVersionKey(),
150
+ processToken: processToken
151
+ )
152
+ recoveryController = created
153
+ return created
154
+ }
155
+
156
+ private static func captureAttempt(hash: String?, attemptId: String?) {
157
+ lock.lock()
158
+ activeAttemptHash = hash
159
+ activeAttemptId = attemptId
160
+ lock.unlock()
161
+ }
162
+
163
+ private static func installReactLifecycleObservers() {
164
+ lock.lock()
165
+ guard !observersInstalled else {
166
+ lock.unlock()
167
+ return
168
+ }
169
+ observersInstalled = true
170
+ lock.unlock()
171
+
172
+ NotificationCenter.default.addObserver(
173
+ forName: Notification.Name("RCTJavaScriptDidLoadNotification"),
174
+ object: nil,
175
+ queue: nil
176
+ ) { notification in
177
+ contentBindings.runtimeDidLoad(bundleURL: bundleURL(from: notification))
178
+ }
179
+
180
+ NotificationCenter.default.addObserver(
181
+ forName: Notification.Name("RCTContentDidAppearNotification"),
182
+ object: nil,
183
+ queue: nil
184
+ ) { notification in
185
+ guard let attempt = contentBindings.binding(for: notification.object) else { return }
186
+ let hash = attempt.hash
187
+ let attemptId = attempt.attemptId
188
+ guard let delay = defaultController()?.markContentAppeared(
189
+ hash: hash,
190
+ attemptId: attemptId
191
+ ) else { return }
192
+ let markHealthy = {
193
+ _ = BundleDropStartupRecoveryAdapter.markHealthy(hash: hash, attemptId: attemptId)
194
+ }
195
+ if delay <= 0 {
196
+ markHealthy()
197
+ } else {
198
+ DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: markHealthy)
199
+ }
200
+ }
201
+ }
202
+
203
+ static func bundleURL(from notification: Notification) -> URL? {
204
+ let selector = NSSelectorFromString("bundleURL")
205
+ let providers = [notification.userInfo?["bridge"], notification.object].compactMap { $0 }
206
+ for provider in providers {
207
+ let object = provider as AnyObject
208
+ // RCTBridgeProxy forwards -bundleURL but reports responds(to:) as false.
209
+ // Checking the concrete Objective-C implementation keeps URL identity
210
+ // available in bridgeless RN without accepting an anonymous global event.
211
+ guard object.responds(to: selector) ||
212
+ class_getInstanceMethod(type(of: object), selector) != nil else {
213
+ continue
214
+ }
215
+ if let url = object.perform(selector)?.takeUnretainedValue() as? URL {
216
+ return url
217
+ }
218
+ }
219
+ return nil
220
+ }
221
+ }
222
+
223
+ /// Associates each React root with the startup attempt that selected its runtime.
224
+ /// Legacy and Fabric both post `RCTContentDidAppearNotification` with their root
225
+ /// object, so a notification arriving late from an older root remains bound to
226
+ /// the older attempt instead of blessing the newest reload.
227
+ final class BundleDropStartupContentBindings {
228
+ struct Binding: Equatable {
229
+ let generation: UInt64
230
+ let hash: String
231
+ let attemptId: String
232
+ let bundlePath: String
233
+ }
234
+
235
+ private final class RootEntry {
236
+ weak var root: AnyObject?
237
+ let binding: Binding
238
+
239
+ init(root: AnyObject, binding: Binding) {
240
+ self.root = root
241
+ self.binding = binding
242
+ }
243
+ }
244
+
245
+ private let lock = NSLock()
246
+ private var generation: UInt64 = 0
247
+ private var activeBinding: Binding?
248
+ private var activeRuntimeLoaded = false
249
+ private var roots: [ObjectIdentifier: RootEntry] = [:]
250
+
251
+ func capture(hash: String?, attemptId: String?, bundleURL: URL?) {
252
+ lock.lock()
253
+ defer { lock.unlock() }
254
+ generation &+= 1
255
+ if let hash, let attemptId, let bundleURL {
256
+ activeBinding = Binding(
257
+ generation: generation,
258
+ hash: hash,
259
+ attemptId: attemptId,
260
+ bundlePath: Self.normalizedPath(bundleURL)
261
+ )
262
+ } else {
263
+ activeBinding = nil
264
+ }
265
+ activeRuntimeLoaded = false
266
+ roots = roots.filter { $0.value.root != nil }
267
+ }
268
+
269
+ func runtimeDidLoad(bundleURL: URL?) {
270
+ lock.lock()
271
+ defer { lock.unlock() }
272
+ guard let activeBinding,
273
+ let bundleURL,
274
+ Self.normalizedPath(bundleURL) == activeBinding.bundlePath else {
275
+ return
276
+ }
277
+ activeRuntimeLoaded = true
278
+ // React may reuse an RCTRootView across legacy reloads. Once the selected
279
+ // runtime has loaded, roots belong to the new generation when they next
280
+ // report content appearance.
281
+ roots.removeAll()
282
+ }
283
+
284
+ func binding(for root: Any?) -> Binding? {
285
+ guard let root else { return nil }
286
+ let rootObject = root as AnyObject
287
+ lock.lock()
288
+ defer { lock.unlock() }
289
+ let identifier = ObjectIdentifier(rootObject)
290
+ if let existing = roots[identifier], existing.root === rootObject {
291
+ return existing.binding
292
+ }
293
+ guard activeRuntimeLoaded, let activeBinding else { return nil }
294
+ roots[identifier] = RootEntry(root: rootObject, binding: activeBinding)
295
+ return activeBinding
296
+ }
297
+
298
+ private static func normalizedPath(_ url: URL) -> String {
299
+ url.standardizedFileURL.resolvingSymlinksInPath().path
300
+ }
301
+ }
package/lib/CLI/cli.js CHANGED
@@ -15,9 +15,9 @@ const upload_cli_1 = __importDefault(require("./scripts/upload-cli"));
15
15
  const sight_cli_1 = require("./scripts/sight-cli");
16
16
  const post_init_1 = require("./scripts/post-init");
17
17
  const logo_1 = require("./logo");
18
+ const serverUrl_1 = require("./serverUrl");
18
19
  const package_json_1 = __importDefault(require("../../package.json"));
19
20
  const logo = (0, logo_1.buildBundleDropLogo)();
20
- const DEFAULT_SERVER_URL = 'https://api.bundledrop.app';
21
21
  const DOCS_CLI_URL = 'https://bundledrop.app/docs/cli';
22
22
  const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
23
23
  const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
@@ -40,7 +40,6 @@ const runSetupWithManualFallback = async (params) => {
40
40
  }
41
41
  };
42
42
  const getTokenPath = () => path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
43
- const normalizeServerUrl = (url) => url?.replace(/\/$/, '') || DEFAULT_SERVER_URL;
44
43
  const readStoredAuthData = () => {
45
44
  const tokenPath = getTokenPath();
46
45
  if (!fs_1.default.existsSync(tokenPath)) {
@@ -198,7 +197,7 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
198
197
  projectRoot: process.cwd(),
199
198
  explicitType: options.projectType,
200
199
  });
201
- const serverUrl = normalizeServerUrl(process.env.BUNDLE_DROP_SERVER_URL);
200
+ const serverUrl = (0, serverUrl_1.normalizeServerUrl)(process.env.BUNDLE_DROP_SERVER_URL);
202
201
  const tokenContext = await fetchFreshAuthContext({
203
202
  serverUrl,
204
203
  token: options.token,
@@ -259,7 +258,7 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
259
258
  projectRoot: process.cwd(),
260
259
  explicitType: options.projectType,
261
260
  });
262
- const serverUrl = normalizeServerUrl(data.serverUrl || data.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
261
+ const serverUrl = (0, serverUrl_1.normalizeServerUrl)(data.serverUrl || data.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
263
262
  const freshContext = await fetchFreshAuthContext({
264
263
  serverUrl,
265
264
  token: data.token,
@@ -317,7 +316,7 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
317
316
  if (!token) {
318
317
  throw new Error('Not authenticated. Run `bundle-drop login` or pass --token.');
319
318
  }
320
- const serverUrl = normalizeServerUrl(authState?.data?.serverUrl || authState?.data?.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
319
+ const serverUrl = (0, serverUrl_1.normalizeServerUrl)(authState?.data?.serverUrl || authState?.data?.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
321
320
  const result = await initConfigModule.initConfig({
322
321
  serverUrl,
323
322
  projects: [],
@@ -74,8 +74,7 @@ const inspectMetroConfig = (projectRoot) => {
74
74
  return { file: undefined, content: '', issue: error.message };
75
75
  }
76
76
  };
77
- const runtimeDeliveryBootstrapGitState = (projectRoot) => {
78
- const relativePath = path_1.default.join('.bundle-drop', 'runtime-delivery.generated.json');
77
+ const runtimeDeliveryBootstrapGitState = (projectRoot, relativePath) => {
79
78
  const runGit = (args) => (0, child_process_1.spawnSync)('git', args, {
80
79
  cwd: projectRoot,
81
80
  stdio: 'ignore',
@@ -106,7 +105,7 @@ const checkRuntimeDeliveryBootstrap = (projectRoot) => {
106
105
  if (!config.serverUrl || !config.org?.slug || !config.project?.slug) {
107
106
  throw new Error('bundle.drop.config.js is missing serverUrl, org.slug, or project.slug.');
108
107
  }
109
- const bootstrap = (0, bootstrapConfig_1.readGeneratedRuntimeDeliveryBootstrap)({
108
+ const inspected = (0, bootstrapConfig_1.inspectRuntimeDeliveryBootstrap)({
110
109
  projectRoot,
111
110
  expectedIdentity: {
112
111
  serverUrl: config.serverUrl,
@@ -114,13 +113,17 @@ const checkRuntimeDeliveryBootstrap = (projectRoot) => {
114
113
  projectSlug: config.project.slug,
115
114
  },
116
115
  });
117
- if (bootstrap) {
118
- const gitState = runtimeDeliveryBootstrapGitState(projectRoot);
116
+ if (inspected) {
117
+ const { bootstrap, source } = inspected;
118
+ const activePath = source === 'legacy'
119
+ ? bootstrapConfig_1.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH
120
+ : bootstrapConfig_1.RUNTIME_DELIVERY_BOOTSTRAP_PATH;
121
+ const gitState = runtimeDeliveryBootstrapGitState(projectRoot, activePath);
119
122
  if (gitState === 'ignored') {
120
123
  return {
121
124
  name: 'Runtime delivery bootstrap',
122
125
  status: 'error',
123
- message: 'The runtime delivery bootstrap is ignored by Git and will be missing from clean builds. ' +
126
+ message: 'The runtime delivery lockfile is ignored by Git and will be missing from clean builds. ' +
124
127
  'Run `bundle-drop sync` to repair .gitignore.',
125
128
  };
126
129
  }
@@ -128,15 +131,31 @@ const checkRuntimeDeliveryBootstrap = (projectRoot) => {
128
131
  return {
129
132
  name: 'Runtime delivery bootstrap',
130
133
  status: 'warning',
131
- message: `Runtime delivery bootstrap is valid with ` +
134
+ message: `Runtime delivery lockfile is valid with ` +
132
135
  `${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s), ` +
133
136
  'but it is not committed yet.',
134
137
  };
135
138
  }
139
+ if (source === 'legacy') {
140
+ return {
141
+ name: 'Runtime delivery bootstrap',
142
+ status: 'warning',
143
+ message: 'The legacy runtime-delivery.generated.json bootstrap is valid. ' +
144
+ 'Run `bundle-drop sync` to migrate it to runtime-delivery.lock.json.',
145
+ };
146
+ }
147
+ if (source === 'matching-dual') {
148
+ return {
149
+ name: 'Runtime delivery bootstrap',
150
+ status: 'warning',
151
+ message: 'The runtime delivery lockfile matches the legacy bootstrap. ' +
152
+ 'Run `bundle-drop sync` to remove the legacy file.',
153
+ };
154
+ }
136
155
  return {
137
156
  name: 'Runtime delivery bootstrap',
138
157
  status: 'pass',
139
- message: `Runtime delivery bootstrap is pinned with ${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s).`,
158
+ message: `Runtime delivery lockfile is pinned with ${Object.keys(bootstrap.runtimeDelivery.publicKeys).length} public key(s).`,
140
159
  };
141
160
  }
142
161
  if (config.runtimeDelivery) {
@@ -151,7 +170,7 @@ const checkRuntimeDeliveryBootstrap = (projectRoot) => {
151
170
  return {
152
171
  name: 'Runtime delivery bootstrap',
153
172
  status: 'warning',
154
- message: 'No runtime delivery bootstrap is pinned. Run `bundle-drop sync` to create or repair it.',
173
+ message: 'No runtime delivery lockfile is pinned. Run `bundle-drop sync` to create or repair it.',
155
174
  };
156
175
  }
157
176
  catch (error) {
@@ -197,7 +197,8 @@ const assertSetupPathAllowed = (file) => {
197
197
  const allowed = file === 'package.json' ||
198
198
  file === '.fingerprintignore' ||
199
199
  file === '.gitignore' ||
200
- file === '.bundle-drop/runtime-delivery.generated.json' ||
200
+ file === bootstrapConfig_1.RUNTIME_DELIVERY_BOOTSTRAP_PATH ||
201
+ file === bootstrapConfig_1.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH ||
201
202
  file === 'bundle.drop.config.js' ||
202
203
  file === 'app.json' ||
203
204
  /^app\.config\.(js|ts|cjs|mjs)$/.test(file) ||
@@ -1,5 +1,5 @@
1
1
  import type { ProjectType } from '../../expo';
2
- import { type GeneratedRuntimeDeliveryBootstrap } from '../../runtime-delivery/bootstrapConfig';
2
+ import { type RuntimeDeliveryBootstrapLockfile } from '../../runtime-delivery/bootstrapConfig';
3
3
  type Project = {
4
4
  name: string;
5
5
  slug: string;
@@ -24,7 +24,7 @@ export declare function initConfig(params: {
24
24
  }): Promise<{
25
25
  bootstrapPath?: string;
26
26
  bootstrapContent?: string;
27
- bootstrap?: GeneratedRuntimeDeliveryBootstrap;
27
+ bootstrap?: RuntimeDeliveryBootstrapLockfile;
28
28
  runtimeDeliveryAvailable?: boolean;
29
29
  bootstrapRetired?: boolean;
30
30
  configPath: string;
@@ -15,13 +15,11 @@ const path_1 = __importDefault(require("path"));
15
15
  const prompts_1 = __importDefault(require("prompts"));
16
16
  const bootstrapConfig_1 = require("../../runtime-delivery/bootstrapConfig");
17
17
  const safe_file_transaction_1 = require("./safe-file-transaction");
18
+ const serverUrl_1 = require("../serverUrl");
18
19
  const DOCS_PROJECT_CREATION_URL = 'https://bundledrop.app/docs/project-creation';
19
20
  const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
20
21
  var bootstrapConfig_2 = require("../../runtime-delivery/bootstrapConfig");
21
22
  Object.defineProperty(exports, "normalizeRuntimeDeliveryBootstrap", { enumerable: true, get: function () { return bootstrapConfig_2.normalizeRuntimeDeliveryBootstrap; } });
22
- function normalizeServerUrl(url) {
23
- return url.replace(/\/$/, '');
24
- }
25
23
  function isRecord(value) {
26
24
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
27
25
  }
@@ -117,7 +115,7 @@ ${projectTypeConfig} serverUrl: ${JSON.stringify(values.serverUrl)},
117
115
  `;
118
116
  }
119
117
  async function fetchProjectCredentials(params) {
120
- const baseUrl = normalizeServerUrl(params.serverUrl);
118
+ const baseUrl = (0, serverUrl_1.normalizeServerUrl)(params.serverUrl);
121
119
  const url = `${baseUrl}/projects/${encodeURIComponent(params.projectSlug)}/credentials` +
122
120
  `?orgSlug=${encodeURIComponent(params.orgSlug)}`;
123
121
  let response;
@@ -152,7 +150,7 @@ function createBootstrapResult(params) {
152
150
  bootstrapRetired: true,
153
151
  };
154
152
  }
155
- const bootstrap = (0, bootstrapConfig_1.createGeneratedRuntimeDeliveryBootstrap)({
153
+ const bootstrap = (0, bootstrapConfig_1.createRuntimeDeliveryBootstrapLockfile)({
156
154
  identity: {
157
155
  serverUrl: params.serverUrl,
158
156
  orgSlug: params.orgSlug,
@@ -170,25 +168,35 @@ function createBootstrapResult(params) {
170
168
  return {
171
169
  bootstrap,
172
170
  bootstrapPath: (0, bootstrapConfig_1.runtimeDeliveryBootstrapPath)(params.projectRoot),
173
- bootstrapContent: (0, bootstrapConfig_1.serializeGeneratedRuntimeDeliveryBootstrap)(bootstrap),
171
+ bootstrapContent: (0, bootstrapConfig_1.serializeRuntimeDeliveryBootstrapLockfile)(bootstrap),
174
172
  runtimeDeliveryAvailable: true,
175
173
  };
176
174
  }
177
175
  async function persistBootstrap(projectRoot, result) {
178
176
  if (result.bootstrap) {
179
- const bootstrapPath = await (0, bootstrapConfig_1.writeGeneratedRuntimeDeliveryBootstrap)({
177
+ const bootstrapPath = await (0, bootstrapConfig_1.writeRuntimeDeliveryBootstrapLockfile)({
180
178
  projectRoot,
181
179
  bootstrap: result.bootstrap,
182
180
  });
181
+ const persisted = (0, bootstrapConfig_1.readRuntimeDeliveryLockfile)({
182
+ projectRoot,
183
+ expectedIdentity: result.bootstrap.project,
184
+ });
185
+ if (!persisted ||
186
+ (0, bootstrapConfig_1.serializeRuntimeDeliveryBootstrapLockfile)(persisted) !==
187
+ (0, bootstrapConfig_1.serializeRuntimeDeliveryBootstrapLockfile)(result.bootstrap)) {
188
+ throw new Error('Runtime delivery lockfile validation failed after writing. The legacy bootstrap was preserved.');
189
+ }
190
+ await (0, bootstrapConfig_1.removeLegacyRuntimeDeliveryBootstrap)(projectRoot);
183
191
  await (0, bootstrapConfig_1.ensureRuntimeDeliveryBootstrapGitignore)(projectRoot);
184
- console.log(chalk_1.default.green(`✅ Synced Bundle Drop runtime delivery bootstrap at ${bootstrapPath}`));
192
+ console.log(chalk_1.default.green(`✅ Synced Bundle Drop runtime delivery lockfile at ${bootstrapPath}`));
185
193
  return;
186
194
  }
187
195
  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.'));
196
+ const removedPaths = await (0, bootstrapConfig_1.removeAllRuntimeDeliveryBootstraps)(projectRoot);
197
+ console.log(chalk_1.default.green(removedPaths.length
198
+ ? `✅ Removed runtime delivery bootstrap files because delivery is disabled for this project: ${removedPaths.join(', ')}`
199
+ : '✅ Runtime delivery is disabled for this project; no bootstrap file is present.'));
192
200
  }
193
201
  }
194
202
  function loadExistingConfig(configPath, content) {
@@ -202,7 +210,7 @@ function loadExistingConfig(configPath, content) {
202
210
  return null;
203
211
  return {
204
212
  projectType: config.projectType,
205
- serverUrl: normalizeServerUrl(config.serverUrl),
213
+ serverUrl: (0, serverUrl_1.normalizeServerUrl)(config.serverUrl),
206
214
  orgSlug: config.org.slug,
207
215
  projectName: config.project.name || '',
208
216
  projectSlug: config.project.slug,
@@ -241,6 +249,7 @@ async function initConfig(params) {
241
249
  const existing = loadExistingConfig(configPath, existingConfigFile.content);
242
250
  let bootstrapResult = {};
243
251
  if (existing && params.authToken) {
252
+ (0, serverUrl_1.assertMatchingServerOrigin)(existing.serverUrl, params.serverUrl);
244
253
  const credentials = await fetchProjectCredentials({
245
254
  serverUrl: existing.serverUrl,
246
255
  orgSlug: existing.orgSlug,
@@ -335,7 +344,7 @@ async function initConfig(params) {
335
344
  if (org)
336
345
  orgSlug = org.slug;
337
346
  }
338
- let resolvedServerUrl = normalizeServerUrl(params.serverUrl);
347
+ let resolvedServerUrl = (0, serverUrl_1.normalizeServerUrl)(params.serverUrl);
339
348
  let apiKey = params.authToken ? '' : params.downloadApiKey || '';
340
349
  let credentials = null;
341
350
  if (projectSlug && params.authToken) {
@@ -15,11 +15,10 @@ const child_process_1 = require("child_process");
15
15
  const init_config_1 = require("./init-config");
16
16
  const post_init_1 = require("./post-init");
17
17
  const expo_1 = require("../../expo");
18
+ const serverUrl_1 = require("../serverUrl");
18
19
  const LOGIN_TIMEOUT_MS = 10 * 60 * 1000;
19
20
  const DOCS_MANUAL_SETUP_URL = 'https://bundledrop.app/docs/manual-setup';
20
- const getBaseUrl = () => process.env.BUNDLE_DROP_SERVER_URL
21
- ? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
22
- : 'https://api.bundledrop.app';
21
+ const getBaseUrl = () => (0, serverUrl_1.normalizeServerUrl)(process.env.BUNDLE_DROP_SERVER_URL);
23
22
  exports.getBaseUrl = getBaseUrl;
24
23
  const getClientName = () => {
25
24
  const hostname = os_1.default.hostname();
@@ -0,0 +1,19 @@
1
+ import type { MobilePlatform } from '../../../expo';
2
+ export type NativeRuntimeIdentity = {
3
+ schemaVersion: 1;
4
+ platform: MobilePlatform;
5
+ source: 'bundle-drop';
6
+ runtimeVersion: string;
7
+ } | {
8
+ schemaVersion: 1;
9
+ platform: MobilePlatform;
10
+ source: 'expo';
11
+ };
12
+ export type WriteNativeRuntimeIdentityOptions = {
13
+ projectRoot: string;
14
+ platform: MobilePlatform;
15
+ outputPath?: string;
16
+ };
17
+ export declare function resolveNativeRuntimeIdentity(projectRoot: string, platform: MobilePlatform): NativeRuntimeIdentity;
18
+ export declare function writeNativeRuntimeIdentity(options: WriteNativeRuntimeIdentityOptions): NativeRuntimeIdentity;
19
+ export declare function parseNativeRuntimeIdentityArguments(argv: string[]): WriteNativeRuntimeIdentityOptions;