@gfean/react-native-bundle-drop 0.3.5 → 0.3.7

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 (63) hide show
  1. package/android/build.gradle +2 -0
  2. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +12 -48
  3. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +64 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +41 -0
  5. package/ios/BundleDropBridge.m +4 -0
  6. package/ios/BundleDropLocator.h +11 -0
  7. package/ios/BundleDropLocator.swift +11 -1
  8. package/ios/BundleDropModule.swift +10 -0
  9. package/lib/CLI/cli.js +56 -6
  10. package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
  11. package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
  12. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
  13. package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
  14. package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
  15. package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
  16. package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
  17. package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
  18. package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
  19. package/lib/CLI/scripts/aipowered/scanner.js +349 -0
  20. package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
  21. package/lib/CLI/scripts/aipowered/types.js +2 -0
  22. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
  23. package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
  24. package/lib/CLI/scripts/init-config.js +10 -5
  25. package/lib/CLI/scripts/init-native-config.js +1 -1
  26. package/lib/CLI/scripts/post-init.js +7 -18
  27. package/lib/CLI/scripts/upload-cli.d.ts +2 -0
  28. package/lib/CLI/scripts/upload-cli.js +53 -25
  29. package/lib/CLI/utils/ui.d.ts +3 -0
  30. package/lib/CLI/utils/ui.js +26 -0
  31. package/lib/api/clientApi.d.ts +2 -1
  32. package/lib/api/clientApi.js +9 -0
  33. package/lib/api/types.d.ts +17 -0
  34. package/lib/context.d.ts +4 -4
  35. package/lib/context.js +2 -2
  36. package/lib/fs/bundlePointer.d.ts +2 -0
  37. package/lib/fs/bundlePointer.js +14 -4
  38. package/lib/index.d.ts +6 -3
  39. package/lib/index.js +5 -1
  40. package/lib/injectImageResolver.js +6 -15
  41. package/lib/loadConfig.d.ts +4 -4
  42. package/lib/manager/downloadAndInstall.d.ts +3 -0
  43. package/lib/manager/downloadAndInstall.js +23 -3
  44. package/lib/manager/reporting.d.ts +2 -0
  45. package/lib/manager/reporting.js +25 -0
  46. package/lib/manager/rollbackState.d.ts +25 -8
  47. package/lib/manager/rollbackState.js +87 -22
  48. package/lib/manager/updateCheck.js +15 -1
  49. package/lib/manager/updateState.d.ts +5 -1
  50. package/lib/manager/updateState.js +20 -11
  51. package/lib/native/bundleDropNative.d.ts +1 -0
  52. package/lib/native/bundleDropNative.js +14 -0
  53. package/lib/runtime/service.d.ts +28 -0
  54. package/lib/runtime/service.js +175 -16
  55. package/lib/scripts/bundle.d.ts +4 -1
  56. package/lib/scripts/bundle.js +41 -28
  57. package/lib/scripts/projectRoot.d.ts +1 -0
  58. package/lib/scripts/projectRoot.js +54 -0
  59. package/lib/scripts/upload-bundle.d.ts +2 -1
  60. package/lib/scripts/upload-bundle.js +46 -37
  61. package/lib/useBundleDrop.d.ts +2 -0
  62. package/lib/useBundleDrop.js +1 -0
  63. package/package.json +3 -2
@@ -9,10 +9,12 @@ exports.isUpdateFlowActive = isUpdateFlowActive;
9
9
  exports.checkLatest = checkLatest;
10
10
  exports.downloadAndStage = downloadAndStage;
11
11
  exports.applyDownloadedUpdate = applyDownloadedUpdate;
12
+ exports.reportHealthy = reportHealthy;
12
13
  exports.fetchAvailableChannels = fetchAvailableChannels;
13
14
  exports.fetchAvailableBundles = fetchAvailableBundles;
14
15
  exports.installBundleFromListItem = installBundleFromListItem;
15
16
  exports.getInstalledBundleInfo = getInstalledBundleInfo;
17
+ exports.getObservabilityContext = getObservabilityContext;
16
18
  exports.getRuntimeUpdateState = getRuntimeUpdateState;
17
19
  exports.checkForUpdate = checkForUpdate;
18
20
  exports.downloadUpdate = downloadUpdate;
@@ -36,6 +38,10 @@ const DEFAULT_STATUS = 'Click the button to check for updates';
36
38
  const DISABLED_STATUS = 'BundleDrop is disabled';
37
39
  let updateFlowActive = false;
38
40
  let startupPromise = null;
41
+ let localStartupPromise = null;
42
+ let healthTimer = null;
43
+ let runtimeRestartRequested = false;
44
+ let activeBundleInfoForObservability = null;
39
45
  let snapshot = {
40
46
  status: DISABLED_STATUS,
41
47
  isBusy: false,
@@ -102,6 +108,9 @@ function isSameStatus(current, next) {
102
108
  function getCheckStatus(response) {
103
109
  if (!response)
104
110
  return '⚠️ Unable to check for updates. Try again.';
111
+ if (response.skippedFailedBundle) {
112
+ return '✅ Current bundle retained; requested update previously failed on this device';
113
+ }
105
114
  if (response.action === 'ROLLBACK') {
106
115
  if (!response.reason) {
107
116
  return '↩️ Rollback requested';
@@ -119,8 +128,11 @@ function getCheckStatus(response) {
119
128
  : '⬇️ Update available';
120
129
  }
121
130
  function getDownloadStatus(result) {
122
- if (result.status === 'upToDate')
123
- return '✅ You have the latest version';
131
+ if (result.status === 'upToDate') {
132
+ return result.skippedFailedBundle
133
+ ? '✅ Current bundle retained; requested update previously failed on this device'
134
+ : '✅ You have the latest version';
135
+ }
124
136
  if (result.status === 'rollback') {
125
137
  if (!result.reason) {
126
138
  return '↩️ Rollback requested';
@@ -136,7 +148,52 @@ function getApplyStatus(result) {
136
148
  ? '✅ Update applied, reloading...'
137
149
  : result.status === 'noBundle'
138
150
  ? '⚠️ No downloaded bundle to apply'
139
- : 'ℹ️ Bundle already applied';
151
+ : result.status === 'blocked'
152
+ ? '⚠️ Update previously failed on this device'
153
+ : 'ℹ️ Bundle already applied';
154
+ }
155
+ function clearHealthTimer() {
156
+ if (!healthTimer)
157
+ return;
158
+ clearTimeout(healthTimer);
159
+ healthTimer = null;
160
+ }
161
+ function requestRuntimeRestart() {
162
+ runtimeRestartRequested = true;
163
+ (0, bundleDropNative_1.restartReactNativeNative)();
164
+ }
165
+ async function markActiveCandidateHealthy(expectedHash) {
166
+ if (runtimeRestartRequested) {
167
+ return false;
168
+ }
169
+ const state = await (0, updateState_1.getUpdateState)();
170
+ if (runtimeRestartRequested) {
171
+ return false;
172
+ }
173
+ if (state.pendingApply) {
174
+ return false;
175
+ }
176
+ const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)(undefined, expectedHash);
177
+ if (markedHealthy) {
178
+ await refreshState();
179
+ }
180
+ return markedHealthy;
181
+ }
182
+ function scheduleCandidateHealthMark(currentPointer, rollbackState) {
183
+ clearHealthTimer();
184
+ const hash = currentPointer?.hash;
185
+ const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
186
+ if (!hash || rollbackPolicy.healthCheckMode === 'manual')
187
+ return;
188
+ if (rollbackState?.candidateHash !== hash || rollbackState.candidateCommitted === true)
189
+ return;
190
+ const delayMs = Math.max(0, rollbackPolicy.healthyAfterSec || 0) * 1000;
191
+ healthTimer = setTimeout(() => {
192
+ healthTimer = null;
193
+ markActiveCandidateHealthy(hash).catch(error => {
194
+ console.warn('⚠️ Failed to mark BundleDrop candidate healthy:', error);
195
+ });
196
+ }, delayMs);
140
197
  }
141
198
  async function refreshState(cached) {
142
199
  const state = await (0, updateState_1.getUpdateState)(cached);
@@ -166,10 +223,15 @@ async function withBusy(fn) {
166
223
  async function waitForStartupIfNeeded() {
167
224
  await startupPromise;
168
225
  }
169
- async function runStartupFlow() {
170
- const runtime = (0, initState_1.assertBundleDropInitialized)();
171
- const statusCb = status => emitStatus(status);
172
- void (0, fsUtils_1.cleanOrphanedTempZips)(`${context_1.BUNDLE_DROP_ROOT}/bundles`);
226
+ async function waitForLocalStartupIfNeeded() {
227
+ try {
228
+ await localStartupPromise;
229
+ }
230
+ catch {
231
+ activeBundleInfoForObservability = null;
232
+ }
233
+ }
234
+ async function runLocalStartupFlow() {
173
235
  const [bundleInfo, bundlePath, currentPointer, rollbackState] = await Promise.all([
174
236
  (0, bundleInfo_1.readBundleInfo)(),
175
237
  (0, bundleDropNative_1.getDownloadedBundlePathNative)(),
@@ -178,22 +240,39 @@ async function runStartupFlow() {
178
240
  ]);
179
241
  await (0, updateState_1.reconcileAppliedBundleOnLaunch)({ bundleInfo, bundlePath });
180
242
  await refreshState({ bundleInfo, bundlePath });
243
+ const state = await (0, updateState_1.getUpdateState)({ bundlePath });
244
+ activeBundleInfoForObservability = state.hasBundle ? state.info || null : null;
245
+ return {
246
+ bundlePath,
247
+ currentPointer,
248
+ rollbackState,
249
+ };
250
+ }
251
+ async function runStartupFlow() {
252
+ const runtime = (0, initState_1.assertBundleDropInitialized)();
253
+ const statusCb = status => emitStatus(status);
254
+ void (0, fsUtils_1.cleanOrphanedTempZips)(`${context_1.BUNDLE_DROP_ROOT}/bundles`);
255
+ localStartupPromise = runLocalStartupFlow();
256
+ const { bundlePath, currentPointer, rollbackState } = await localStartupPromise;
181
257
  const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
182
258
  const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
183
259
  currentPointer,
184
260
  rollbackState,
185
261
  });
186
262
  if (rollbackResult.rolledBack) {
263
+ clearHealthTimer();
187
264
  emitStatus('↩️ Rolled back to previous bundle');
188
- (0, bundleDropNative_1.restartReactNativeNative)();
265
+ requestRuntimeRestart();
189
266
  return;
190
267
  }
191
- await (0, rollbackState_1.commitActiveBundle)({ currentPointer });
268
+ scheduleCandidateHealthMark(currentPointer, await (0, rollbackState_1.readRollbackState)());
192
269
  const pendingState = await refreshState({ bundlePath });
193
270
  if (pendingState.pendingApply) {
194
271
  if (runtime.policy === 'immediate') {
195
272
  emitStatus('♻️ Applying previously downloaded update...');
196
- const applied = await (0, updateState_1.applyUpdate)(statusCb);
273
+ const applied = await (0, updateState_1.applyUpdate)(statusCb, () => {
274
+ runtimeRestartRequested = true;
275
+ });
197
276
  if (applied.status === 'applied') {
198
277
  return;
199
278
  }
@@ -216,7 +295,7 @@ async function runStartupFlow() {
216
295
  if (decision.action === 'ROLLBACK') {
217
296
  emitStatus('↩️ Server requested rollback...');
218
297
  await (0, rollbackState_1.rollbackToPreviousOrNative)();
219
- (0, bundleDropNative_1.restartReactNativeNative)();
298
+ requestRuntimeRestart();
220
299
  return;
221
300
  }
222
301
  if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
@@ -248,7 +327,9 @@ async function runStartupFlow() {
248
327
  return;
249
328
  }
250
329
  if (downloadResult.status === 'staged') {
251
- await (0, updateState_1.applyUpdate)(statusCb);
330
+ await (0, updateState_1.applyUpdate)(statusCb, () => {
331
+ runtimeRestartRequested = true;
332
+ });
252
333
  return;
253
334
  }
254
335
  const nextStatus = getDownloadStatus(downloadResult);
@@ -276,6 +357,12 @@ function ensureStartupFlow() {
276
357
  */
277
358
  function initBundleDrop(options) {
278
359
  const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(options);
360
+ if (!alreadyInitialized) {
361
+ runtimeRestartRequested = false;
362
+ activeBundleInfoForObservability = null;
363
+ }
364
+ // Persist for the next cold start; do not block init on this I/O (errors are swallowed in native helper).
365
+ void (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
279
366
  patchSnapshot({
280
367
  channelName: config.channelName,
281
368
  isEnabled: config.enabled,
@@ -371,7 +458,9 @@ async function applyDownloadedUpdate(extraStatusHandler) {
371
458
  }
372
459
  await waitForStartupIfNeeded();
373
460
  return withBusy(async () => {
374
- const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler));
461
+ const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => {
462
+ runtimeRestartRequested = true;
463
+ });
375
464
  const status = getApplyStatus(result);
376
465
  if (status) {
377
466
  emitStatus(status, extraStatusHandler);
@@ -379,6 +468,21 @@ async function applyDownloadedUpdate(extraStatusHandler) {
379
468
  return { result, status };
380
469
  });
381
470
  }
471
+ /**
472
+ * Mark the currently running OTA candidate healthy for this device.
473
+ */
474
+ async function reportHealthy() {
475
+ const runtime = getEnabledRuntime();
476
+ if (!runtime) {
477
+ return;
478
+ }
479
+ await waitForStartupIfNeeded();
480
+ if (runtimeRestartRequested || updateFlowActive) {
481
+ return;
482
+ }
483
+ clearHealthTimer();
484
+ await markActiveCandidateHealthy();
485
+ }
382
486
  /**
383
487
  * Fetch the list of public channel names available for the configured project.
384
488
  */
@@ -424,13 +528,14 @@ async function installBundleFromListItem(bundle) {
424
528
  return { result: { status: 'disabled' }, status: DISABLED_STATUS };
425
529
  }
426
530
  await waitForStartupIfNeeded();
427
- if (!bundle.downloadUrl) {
531
+ const downloadUrl = bundle.downloadUrl;
532
+ if (!downloadUrl) {
428
533
  const status = '⚠️ Bundle is not downloadable (expired or unavailable)';
429
534
  emitStatus(status);
430
535
  return { result: { status: 'incompatible' }, status };
431
536
  }
432
537
  return withBusy(async () => {
433
- const result = await (0, downloadAndInstall_1.installBundle)(bundle.hash, bundle.downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, {
538
+ const result = await (0, downloadAndInstall_1.installBundle)(bundle.hash, downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, {
434
539
  channelName: runtime.channelName,
435
540
  onStatusUpdate: emitStatus,
436
541
  });
@@ -439,7 +544,10 @@ async function installBundleFromListItem(bundle) {
439
544
  emitStatus(status);
440
545
  return { result, status };
441
546
  }
442
- return { result, status: undefined };
547
+ const status = getDownloadStatus(result);
548
+ if (status)
549
+ emitStatus(status);
550
+ return { result, status };
443
551
  });
444
552
  }
445
553
  /**
@@ -452,6 +560,54 @@ async function getInstalledBundleInfo() {
452
560
  const state = await refreshState();
453
561
  return state.info || null;
454
562
  }
563
+ function getEmbeddedObservabilityContext() {
564
+ return {
565
+ source: 'embedded',
566
+ dist: 'embedded',
567
+ tags: {
568
+ bundle_drop_hash: null,
569
+ bundle_drop_channel: null,
570
+ bundle_drop_version: null,
571
+ bundle_drop_runtime_version: null,
572
+ bundle_drop_platform: null,
573
+ },
574
+ context: null,
575
+ };
576
+ }
577
+ /**
578
+ * Pre-formatted context for error tracking integrations.
579
+ *
580
+ * Returns `dist`, `tags`, and `context` shaped for direct use with
581
+ * Sentry, Bugsnag, Datadog, or any provider. Handles the embedded
582
+ * fallback automatically: when no OTA bundle is active, `source`
583
+ * is `'embedded'` and `dist` is `'embedded'`.
584
+ *
585
+ * If the installed bundle has `pendingApply: true` it is not yet
586
+ * executing, so the context falls back to `'embedded'`.
587
+ */
588
+ async function getObservabilityContext() {
589
+ const runtime = getEnabledRuntime();
590
+ if (!runtime) {
591
+ return getEmbeddedObservabilityContext();
592
+ }
593
+ await waitForLocalStartupIfNeeded();
594
+ const info = activeBundleInfoForObservability;
595
+ if (!info || info.pendingApply || !info.hash) {
596
+ return getEmbeddedObservabilityContext();
597
+ }
598
+ return {
599
+ source: 'ota',
600
+ dist: info.hash ?? 'embedded',
601
+ tags: {
602
+ bundle_drop_hash: info.hash ?? null,
603
+ bundle_drop_channel: info.channelName ?? null,
604
+ bundle_drop_version: info.bundleVersion != null ? `${info.bundleVersion}` : null,
605
+ bundle_drop_runtime_version: info.runtimeVersion ?? null,
606
+ bundle_drop_platform: info.platform ?? null,
607
+ },
608
+ context: info,
609
+ };
610
+ }
455
611
  /**
456
612
  * Read the current local update state from disk.
457
613
  */
@@ -520,8 +676,11 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
520
676
  });
521
677
  }
522
678
  function resetBundleDropRuntimeServiceForTests() {
679
+ clearHealthTimer();
523
680
  updateFlowActive = false;
524
681
  startupPromise = null;
682
+ localStartupPromise = null;
683
+ activeBundleInfoForObservability = null;
525
684
  snapshot = {
526
685
  status: DISABLED_STATUS,
527
686
  isBusy: false,
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env node
2
- export declare function findProjectRoot(startDir: string): string;
2
+ import { findProjectRoot } from './projectRoot';
3
+ export { findProjectRoot };
3
4
  export declare function runBundleScript(options?: {
4
5
  platform?: string;
5
6
  cwd?: string;
7
+ sourcemap?: boolean;
6
8
  }): {
7
9
  projectRoot: string;
8
10
  outputDir: string;
9
11
  bundlePath: string;
12
+ sourceMapPath: string;
10
13
  metadataPath: string;
11
14
  zipPath: string;
12
15
  runtimeVersion: string;
@@ -37,30 +37,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.findProjectRoot = findProjectRoot;
40
+ exports.findProjectRoot = void 0;
41
41
  exports.runBundleScript = runBundleScript;
42
42
  const adm_zip_1 = __importDefault(require("adm-zip"));
43
43
  const child_process_1 = require("child_process");
44
44
  const crypto_1 = require("crypto");
45
45
  const fs = __importStar(require("fs"));
46
46
  const path = __importStar(require("path"));
47
+ const projectRoot_1 = require("./projectRoot");
48
+ Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
47
49
  const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
48
- function findProjectRoot(startDir) {
49
- let dir = path.resolve(startDir);
50
- const MAX_UP = 12;
51
- for (let i = 0; i < MAX_UP; i++) {
52
- const iosDir = path.join(dir, 'ios');
53
- const androidDir = path.join(dir, 'android');
54
- if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
55
- return dir;
56
- }
57
- const parent = path.dirname(dir);
58
- if (parent === dir)
59
- break;
60
- dir = parent;
61
- }
62
- return startDir;
63
- }
64
50
  function runBundleScript(options) {
65
51
  const packageRoot = getPackageRoot();
66
52
  const platform = options?.platform || process.argv[2] || 'ios';
@@ -74,9 +60,11 @@ function runBundleScript(options) {
74
60
  const assetsDir = path.join(outputDir, 'assets');
75
61
  const bundlePath = path.join(outputDir, 'main.jsbundle');
76
62
  const metadataPath = path.join(outputDir, `metadata-${fileSuffix}.json`);
63
+ const sourceMapPath = path.join(outputDir, 'main.jsbundle.map');
77
64
  const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
78
65
  const imageManifest = {};
79
- const projectRoot = findProjectRoot(options?.cwd || process.cwd());
66
+ const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
67
+ const generateSourceMap = options?.sourcemap ?? process.argv.includes('--sourcemap');
80
68
  let runtimeVersion;
81
69
  const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
82
70
  if (fs.existsSync(configPath)) {
@@ -90,7 +78,7 @@ function runBundleScript(options) {
90
78
  else {
91
79
  console.warn('⚠️ bundle.drop.config.js not found in project root; runtimeVersion will be omitted.');
92
80
  }
93
- [bundlePath, zipPath, metadataPath].forEach(file => {
81
+ [bundlePath, zipPath, metadataPath, sourceMapPath].forEach(file => {
94
82
  if (fs.existsSync(file))
95
83
  fs.unlinkSync(file);
96
84
  });
@@ -99,13 +87,14 @@ function runBundleScript(options) {
99
87
  fs.mkdirSync(outputDir, { recursive: true });
100
88
  fs.mkdirSync(assetsDir, { recursive: true });
101
89
  console.log(`📦 Bundling React Native code for platform: ${platform}...`);
90
+ const sourcemapFlag = generateSourceMap ? ` \\\n --sourcemap-output "${sourceMapPath}"` : '';
102
91
  (0, child_process_1.execSync)(`npx react-native bundle \
103
92
  --platform ${platform} \
104
93
  --dev false \
105
94
  --entry-file index.js \
106
95
  --bundle-output "${bundlePath}" \
107
- --assets-dest "${assetsDir}"`, { stdio: 'inherit' });
108
- console.log('✅ Bundle created:', bundlePath);
96
+ --assets-dest "${assetsDir}"${sourcemapFlag}`, { stdio: 'inherit' });
97
+ console.log('✅ Bundle created');
109
98
  const osBin = process.platform === 'darwin'
110
99
  ? 'osx-bin'
111
100
  : process.platform === 'win32'
@@ -117,19 +106,42 @@ function runBundleScript(options) {
117
106
  ];
118
107
  const hermescPath = hermesLocations.find(p => fs.existsSync(p));
119
108
  if (hermescPath) {
120
- console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
121
109
  const hbcPath = bundlePath + '.hbc';
110
+ const hermesMapFlag = generateSourceMap ? ` -output-source-map` : '';
122
111
  try {
123
- (0, child_process_1.execSync)(`"${hermescPath}" -emit-binary -out "${hbcPath}" "${bundlePath}"`, { stdio: 'inherit' });
112
+ console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
113
+ (0, child_process_1.execSync)(`"${hermescPath}" -emit-binary -out "${hbcPath}" "${bundlePath}"${hermesMapFlag}`, { stdio: ['ignore', 'ignore', 'ignore'] });
124
114
  fs.renameSync(hbcPath, bundlePath);
125
- console.log('✅ Hermes bytecode compiled successfully');
115
+ console.log('✅ Hermes bytecode compiled');
126
116
  }
127
117
  catch (e) {
128
118
  console.warn('⚠️ Hermes compilation failed, falling back to plain JS bundle:', e.message);
129
119
  }
120
+ if (generateSourceMap) {
121
+ const hermesMapPath = bundlePath + '.hbc.map';
122
+ if (fs.existsSync(hermesMapPath) && fs.existsSync(sourceMapPath)) {
123
+ const composeScript = path.join(projectRoot, 'node_modules', 'react-native', 'scripts', 'compose-source-maps.js');
124
+ if (fs.existsSync(composeScript)) {
125
+ try {
126
+ const composedPath = sourceMapPath + '.composed';
127
+ (0, child_process_1.execSync)(`node "${composeScript}" "${sourceMapPath}" "${hermesMapPath}" -o "${composedPath}"`, { stdio: ['ignore', 'ignore', 'ignore'] });
128
+ fs.renameSync(composedPath, sourceMapPath);
129
+ console.log('✅ Source maps composed');
130
+ }
131
+ catch (composeErr) {
132
+ console.warn('⚠️ Source map composition failed; keeping Metro source map:', composeErr.message);
133
+ }
134
+ }
135
+ else {
136
+ console.warn('⚠️ compose-source-maps.js not found; keeping Metro source map as-is');
137
+ }
138
+ }
139
+ if (fs.existsSync(hermesMapPath))
140
+ fs.unlinkSync(hermesMapPath);
141
+ }
130
142
  }
131
143
  else {
132
- console.log('ℹ️ hermesc not found — bundling plain JS (JSC or older RN)');
144
+ console.log('ℹ️ Hermes not found — bundling plain JS');
133
145
  }
134
146
  const bundleBuffer = fs.readFileSync(bundlePath);
135
147
  const hash = (0, crypto_1.createHash)('sha256').update(bundleBuffer).digest('hex');
@@ -144,9 +156,8 @@ function runBundleScript(options) {
144
156
  metadata.runtimeVersion = runtimeVersion;
145
157
  }
146
158
  fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
147
- console.log('🧠 Metadata saved:', metadataPath);
159
+ console.log('🧠 Metadata saved');
148
160
  console.log('📌 Hash:', hash);
149
- console.log('📦 Zipping bundle...');
150
161
  const zip = new adm_zip_1.default();
151
162
  zip.addFile('main.jsbundle', bundleBuffer);
152
163
  zip.addFile(`metadata-${fileSuffix}.json`, Buffer.from(JSON.stringify(metadata, null, 2)));
@@ -182,12 +193,14 @@ function runBundleScript(options) {
182
193
  zip.addFile('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
183
194
  console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
184
195
  }
196
+ console.log('📦 Zipping bundle...');
185
197
  zip.writeZip(zipPath);
186
- console.log(`✅ OTA bundle zipped: ${zipPath}`);
198
+ console.log('✅ OTA bundle zipped');
187
199
  return {
188
200
  projectRoot,
189
201
  outputDir,
190
202
  bundlePath,
203
+ sourceMapPath: generateSourceMap ? sourceMapPath : undefined,
191
204
  metadataPath,
192
205
  zipPath,
193
206
  runtimeVersion,
@@ -0,0 +1 @@
1
+ export declare function findProjectRoot(startDir: string): string;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.findProjectRoot = findProjectRoot;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ function findProjectRoot(startDir) {
40
+ let dir = path.resolve(startDir);
41
+ const MAX_UP = 12;
42
+ for (let i = 0; i < MAX_UP; i++) {
43
+ const iosDir = path.join(dir, 'ios');
44
+ const androidDir = path.join(dir, 'android');
45
+ if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
46
+ return dir;
47
+ }
48
+ const parent = path.dirname(dir);
49
+ if (parent === dir)
50
+ break;
51
+ dir = parent;
52
+ }
53
+ return startDir;
54
+ }
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- export declare function findProjectRoot(startDir: string): string;
2
+ import { findProjectRoot } from './projectRoot';
3
+ export { findProjectRoot };
3
4
  export declare function parseAndroidVersionFromGradle(filePath: string): string;
4
5
  export declare const cleanupArtifacts: (platform: string, zipPath: string) => void;
5
6
  export declare function runUploadBundle(options?: {