@gfean/react-native-bundle-drop 0.4.2 → 0.4.4

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 (111) hide show
  1. package/BundleDropExpo.podspec +21 -0
  2. package/README.md +339 -74
  3. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +33 -3
  4. package/app.plugin.js +3 -0
  5. package/expo/android/build.gradle +159 -0
  6. package/expo/android/src/main/AndroidManifest.xml +1 -0
  7. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoConfiguration.kt +35 -0
  8. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoIdentityModule.kt +30 -0
  9. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoPackage.kt +29 -0
  10. package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoReactNativeHostHandler.kt +16 -0
  11. package/expo/bundle-drop-expo-gradle-plugin/build.gradle +31 -0
  12. package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/BundleDropExpoPlugin.groovy +83 -0
  13. package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/GenerateBundleDropBuildIdentityTask.groovy +57 -0
  14. package/expo/ios/Sources/BundleDropExpoIdentity.m +31 -0
  15. package/expo/ios/Sources/BundleDropExpoReactDelegateHandler.swift +24 -0
  16. package/expo-module.config.json +19 -0
  17. package/ios/BundleDropLocator.swift +7 -1
  18. package/lib/CLI/cli.d.ts +1 -2
  19. package/lib/CLI/cli.js +126 -31
  20. package/lib/CLI/logo.d.ts +9 -0
  21. package/lib/CLI/logo.js +26 -0
  22. package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
  23. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +55 -0
  24. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -1
  25. package/lib/CLI/scripts/aipowered/backend-client.js +25 -2
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +400 -0
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -1
  29. package/lib/CLI/scripts/aipowered/scanner.js +274 -5
  30. package/lib/CLI/scripts/aipowered/types.d.ts +39 -0
  31. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +12 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.js +76 -1
  33. package/lib/CLI/scripts/doctor.d.ts +17 -0
  34. package/lib/CLI/scripts/doctor.js +412 -0
  35. package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
  36. package/lib/CLI/scripts/expo/build-receipt.js +223 -0
  37. package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
  38. package/lib/CLI/scripts/expo/configure-expo.js +268 -0
  39. package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
  40. package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
  41. package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
  42. package/lib/CLI/scripts/expo/package-manager.js +84 -0
  43. package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
  44. package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
  45. package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
  46. package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
  47. package/lib/CLI/scripts/init-config.d.ts +18 -1
  48. package/lib/CLI/scripts/init-config.js +29 -9
  49. package/lib/CLI/scripts/init-metro-config.d.ts +7 -0
  50. package/lib/CLI/scripts/init-metro-config.js +28 -8
  51. package/lib/CLI/scripts/login-cli.js +17 -3
  52. package/lib/CLI/scripts/post-init.d.ts +6 -1
  53. package/lib/CLI/scripts/post-init.js +6 -33
  54. package/lib/CLI/scripts/upload-cli.d.ts +1 -0
  55. package/lib/CLI/scripts/upload-cli.js +106 -36
  56. package/lib/context.d.ts +0 -2
  57. package/lib/context.js +19 -3
  58. package/lib/expo/buildIdentity.d.ts +15 -0
  59. package/lib/expo/buildIdentity.js +201 -0
  60. package/lib/expo/buildReceipt.d.ts +42 -0
  61. package/lib/expo/buildReceipt.js +272 -0
  62. package/lib/expo/config.d.ts +7 -0
  63. package/lib/expo/config.js +43 -0
  64. package/lib/expo/configCache.d.ts +1 -0
  65. package/lib/expo/configCache.js +20 -0
  66. package/lib/expo/errors.d.ts +6 -0
  67. package/lib/expo/errors.js +11 -0
  68. package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
  69. package/lib/expo/expoUpdatesOwnership.js +22 -0
  70. package/lib/expo/exportExpoProject.d.ts +21 -0
  71. package/lib/expo/exportExpoProject.js +125 -0
  72. package/lib/expo/exportValidation.d.ts +11 -0
  73. package/lib/expo/exportValidation.js +115 -0
  74. package/lib/expo/index.d.ts +18 -0
  75. package/lib/expo/index.js +25 -0
  76. package/lib/expo/localModules.d.ts +4 -0
  77. package/lib/expo/localModules.js +51 -0
  78. package/lib/expo/nativeIdentity.d.ts +1 -0
  79. package/lib/expo/nativeIdentity.js +17 -0
  80. package/lib/expo/projectType.d.ts +7 -0
  81. package/lib/expo/projectType.js +200 -0
  82. package/lib/expo/runtimeVersion.d.ts +13 -0
  83. package/lib/expo/runtimeVersion.js +45 -0
  84. package/lib/expo/types.d.ts +15 -0
  85. package/lib/expo/types.js +2 -0
  86. package/lib/fs/userProperties.d.ts +0 -2
  87. package/lib/fs/userProperties.js +0 -3
  88. package/lib/index.d.ts +1 -1
  89. package/lib/index.js +1 -2
  90. package/lib/loadConfig.d.ts +17 -5
  91. package/lib/loadConfig.js +2 -19
  92. package/lib/metro.d.ts +17 -0
  93. package/lib/metro.js +57 -0
  94. package/lib/native/bundleDropNative.d.ts +2 -0
  95. package/lib/native/bundleDropNative.js +9 -1
  96. package/lib/runtime/service.js +12 -1
  97. package/lib/scripts/bundle.d.ts +2 -2
  98. package/lib/scripts/bundle.js +30 -99
  99. package/lib/scripts/canonicalArtifact.d.ts +30 -0
  100. package/lib/scripts/canonicalArtifact.js +212 -0
  101. package/lib/scripts/download-bundle.js +1 -1
  102. package/lib/scripts/exportProject.d.ts +41 -0
  103. package/lib/scripts/exportProject.js +82 -0
  104. package/package.json +74 -55
  105. package/plugin/constants.js +9 -0
  106. package/plugin/expoUpdates.js +131 -0
  107. package/plugin/index.js +11 -0
  108. package/plugin/markers.js +31 -0
  109. package/plugin/withBundleDrop.js +36 -0
  110. package/plugin/xcodeBuildPhase.js +77 -0
  111. package/react-native.config.js +20 -0
package/lib/loadConfig.js CHANGED
@@ -1,15 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadConfig = loadConfig;
4
- const react_native_1 = require("react-native");
5
- function resolveDebugLocalPort(serverUrl) {
6
- try {
7
- return new URL(serverUrl).port || '4000';
8
- }
9
- catch {
10
- return '4000';
11
- }
12
- }
13
4
  function loadConfig() {
14
5
  try {
15
6
  // ✅ Resolved via Metro alias in the host app (extraNodeModules)
@@ -18,15 +9,8 @@ function loadConfig() {
18
9
  if (!cfg?.serverUrl || !cfg?.project?.slug || !cfg?.org?.slug) {
19
10
  throw new Error('bundle.drop.config.js missing serverUrl, org.slug or project.slug');
20
11
  }
21
- if (cfg.debugLocal === true) {
22
- const port = resolveDebugLocalPort(cfg.serverUrl);
23
- return {
24
- ...cfg,
25
- serverUrl: react_native_1.Platform.OS === 'android'
26
- ? `http://10.0.2.2:${port}`
27
- : `http://localhost:${port}`,
28
- debugLocal: true,
29
- };
12
+ if (cfg.runtimeVersion?.source === 'expo') {
13
+ throw new Error('Expo runtime identity was not embedded. Configure Metro with withBundleDropExpo().');
30
14
  }
31
15
  return cfg;
32
16
  }
@@ -37,7 +21,6 @@ function loadConfig() {
37
21
  serverUrl: 'https://api.bundledrop.app',
38
22
  org: { slug: 'default-org' },
39
23
  project: { name: 'BundleDrop', slug: 'default' },
40
- debugLocal: false,
41
24
  };
42
25
  }
43
26
  throw new Error('[BundleDrop] bundle.drop.config.js could not be loaded. ' +
package/lib/metro.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ export type { ExpoBuildIdentityReceipt } from './expo/buildReceipt';
2
+ export type BundleDropMetroConfig = {
3
+ resolver?: {
4
+ extraNodeModules?: Record<string, string>;
5
+ [key: string]: unknown;
6
+ };
7
+ [key: string]: unknown;
8
+ };
9
+ export type WithBundleDropExpoOptions = {
10
+ projectRoot?: string;
11
+ };
12
+ /**
13
+ * Preserves the caller's Expo Metro config and only adds Bundle Drop's config
14
+ * alias after resolving the same concrete identity used by build and upload.
15
+ */
16
+ export declare function withBundleDropExpo<T extends BundleDropMetroConfig>(configOrPromise: T | Promise<T>, options?: WithBundleDropExpoOptions): Promise<T>;
17
+ export default withBundleDropExpo;
package/lib/metro.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.withBundleDropExpo = withBundleDropExpo;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const expo_1 = require("./expo");
10
+ const writeGeneratedRuntimeConfig = (params) => {
11
+ const generatedDirectory = path_1.default.join(params.projectRoot, '.bundle-drop', 'generated');
12
+ const generatedConfigPath = path_1.default.join(generatedDirectory, 'bundle.drop.config.js');
13
+ fs_extra_1.default.ensureDirSync(generatedDirectory);
14
+ const baseConfigPath = path_1.default.join(params.projectRoot, 'bundle.drop.config.js');
15
+ if (!fs_extra_1.default.existsSync(baseConfigPath)) {
16
+ throw new Error('Bundle Drop Expo Metro setup requires bundle.drop.config.js in the project root.');
17
+ }
18
+ const content = [
19
+ "'use strict';",
20
+ '',
21
+ "const baseConfig = require('../../bundle.drop.config.js');",
22
+ 'module.exports = {',
23
+ ' ...baseConfig,',
24
+ ` runtimeVersion: ${JSON.stringify({
25
+ ios: params.ios,
26
+ android: params.android,
27
+ })},`,
28
+ '};',
29
+ '',
30
+ ].join('\n');
31
+ fs_extra_1.default.writeFileSync(generatedConfigPath, content, 'utf8');
32
+ return generatedConfigPath;
33
+ };
34
+ /**
35
+ * Preserves the caller's Expo Metro config and only adds Bundle Drop's config
36
+ * alias after resolving the same concrete identity used by build and upload.
37
+ */
38
+ async function withBundleDropExpo(configOrPromise, options = {}) {
39
+ const projectRoot = path_1.default.resolve(options.projectRoot || process.cwd());
40
+ const [config, ios, android] = await Promise.all([
41
+ Promise.resolve(configOrPromise),
42
+ (0, expo_1.resolveExpoMetroRuntimeVersion)(projectRoot, 'ios'),
43
+ (0, expo_1.resolveExpoMetroRuntimeVersion)(projectRoot, 'android'),
44
+ ]);
45
+ const generatedConfigPath = writeGeneratedRuntimeConfig({ projectRoot, ios, android });
46
+ return {
47
+ ...config,
48
+ resolver: {
49
+ ...(config.resolver || {}),
50
+ extraNodeModules: {
51
+ ...(config.resolver?.extraNodeModules || {}),
52
+ 'bundle-drop-config': generatedConfigPath,
53
+ },
54
+ },
55
+ };
56
+ }
57
+ exports.default = withBundleDropExpo;
@@ -1,3 +1,5 @@
1
+ export declare function isBundleDropNativeAvailable(): boolean;
2
+ export declare function isExpoOtaStartupEnabledNative(): boolean;
1
3
  export declare function getDownloadedBundlePathNative(): Promise<string | null>;
2
4
  export declare function restartReactNativeNative(): void;
3
5
  export declare function setOtaEnabledNative(enabled: boolean): Promise<void>;
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBundleDropNativeAvailable = isBundleDropNativeAvailable;
4
+ exports.isExpoOtaStartupEnabledNative = isExpoOtaStartupEnabledNative;
3
5
  exports.getDownloadedBundlePathNative = getDownloadedBundlePathNative;
4
6
  exports.restartReactNativeNative = restartReactNativeNative;
5
7
  exports.setOtaEnabledNative = setOtaEnabledNative;
6
8
  const react_native_1 = require("react-native");
7
- const { BundleDrop } = react_native_1.NativeModules;
9
+ const { BundleDrop, BundleDropExpoIdentity } = react_native_1.NativeModules;
10
+ function isBundleDropNativeAvailable() {
11
+ return Boolean(BundleDrop);
12
+ }
13
+ function isExpoOtaStartupEnabledNative() {
14
+ return BundleDropExpoIdentity?.otaStartupEnabled === true;
15
+ }
8
16
  async function getDownloadedBundlePathNative() {
9
17
  if (!BundleDrop?.getDownloadedBundlePath) {
10
18
  console.warn('BundleDrop.getDownloadedBundlePath is not defined');
@@ -36,6 +36,9 @@ const updateState_1 = require("../manager/updateState");
36
36
  const initState_1 = require("./initState");
37
37
  const DEFAULT_STATUS = 'Click the button to check for updates';
38
38
  const DISABLED_STATUS = 'BundleDrop is disabled';
39
+ const EXPO_DEVELOPMENT_FALLBACK_WARNING = '[BundleDrop] OTA startup is unavailable in this Expo runtime. ' +
40
+ 'Expo Go and standard Debug/development-client builds keep Metro priority, so OTA features are disabled. ' +
41
+ 'Use a non-Debug/Release native build to test Bundle Drop updates.';
39
42
  let updateFlowActive = false;
40
43
  let startupPromise = null;
41
44
  let localStartupPromise = null;
@@ -43,6 +46,7 @@ let healthTimer = null;
43
46
  let runtimeRestartRequested = false;
44
47
  let activeBundleInfoForObservability = null;
45
48
  let nativeOtaEnabledPromise = Promise.resolve();
49
+ let hasWarnedAboutExpoDevelopmentFallback = false;
46
50
  let snapshot = {
47
51
  status: DISABLED_STATUS,
48
52
  isBusy: false,
@@ -368,7 +372,14 @@ function ensureStartupFlow() {
368
372
  * `useBundleDrop()` or any OTA runtime APIs.
369
373
  */
370
374
  function initBundleDrop(options) {
371
- const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(options);
375
+ const useExpoDevelopmentFallback = options.enabled !== false &&
376
+ context_1.config.projectType === 'expo' &&
377
+ (!(0, bundleDropNative_1.isBundleDropNativeAvailable)() || !(0, bundleDropNative_1.isExpoOtaStartupEnabledNative)());
378
+ if (useExpoDevelopmentFallback && !hasWarnedAboutExpoDevelopmentFallback) {
379
+ hasWarnedAboutExpoDevelopmentFallback = true;
380
+ console.warn(EXPO_DEVELOPMENT_FALLBACK_WARNING);
381
+ }
382
+ const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(useExpoDevelopmentFallback ? { ...options, enabled: false } : options);
372
383
  if (!alreadyInitialized) {
373
384
  runtimeRestartRequested = false;
374
385
  activeBundleInfoForObservability = null;
@@ -6,10 +6,9 @@ export declare function runBundleScript(options?: {
6
6
  cwd?: string;
7
7
  sourcemap?: boolean;
8
8
  }): {
9
- projectRoot: string;
10
9
  outputDir: string;
11
10
  bundlePath: string;
12
- sourceMapPath: string;
11
+ sourceMapPath?: string;
13
12
  metadataPath: string;
14
13
  zipPath: string;
15
14
  runtimeVersion: string;
@@ -17,4 +16,5 @@ export declare function runBundleScript(options?: {
17
16
  bundleHash: string;
18
17
  jsBundleHash: string;
19
18
  manifestPath: string;
19
+ projectRoot: string;
20
20
  };
@@ -33,37 +33,19 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  return result;
34
34
  };
35
35
  })();
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
36
  Object.defineProperty(exports, "__esModule", { value: true });
40
37
  exports.findProjectRoot = void 0;
41
38
  exports.runBundleScript = runBundleScript;
42
- const adm_zip_1 = __importDefault(require("adm-zip"));
43
39
  const child_process_1 = require("child_process");
44
- const crypto_1 = require("crypto");
45
40
  const fs = __importStar(require("fs"));
46
41
  const path = __importStar(require("path"));
47
42
  const bundleManifest_1 = require("../manifest/bundleManifest");
43
+ const canonicalArtifact_1 = require("./canonicalArtifact");
48
44
  const projectRoot_1 = require("./projectRoot");
49
45
  Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
46
+ const SENTRY_HERMES_OTA_DOCS_URL = 'https://bundledrop.app/docs/observability#sentry-and-hermes-ota-builds';
47
+ const SENTRY_DEBUG_ID_MARKERS = ['//# debugId=', 'sentry-dbid-'];
50
48
  const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
51
- const sha256Buffer = (buffer) => (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
52
- const manifestRoleForPath = (filePath) => {
53
- if (filePath === 'main.jsbundle')
54
- return 'jsbundle';
55
- if (filePath.startsWith('metadata-'))
56
- return 'metadata';
57
- if (filePath === 'image-manifest.json')
58
- return 'androidImageManifest';
59
- return 'asset';
60
- };
61
- const createFileEntry = (filePath, buffer) => ({
62
- path: (0, bundleManifest_1.normalizeManifestPath)(filePath),
63
- size: buffer.length,
64
- sha256: sha256Buffer(buffer),
65
- role: manifestRoleForPath((0, bundleManifest_1.normalizeManifestPath)(filePath)),
66
- });
67
49
  const readTextIfExists = (filePath) => {
68
50
  if (!fs.existsSync(filePath))
69
51
  return null;
@@ -132,6 +114,15 @@ const promoteHermesBytecode = (hbcPath, bundlePath) => {
132
114
  fs.copyFileSync(hbcPath, bundlePath);
133
115
  fs.unlinkSync(hbcPath);
134
116
  };
117
+ const warnAboutSentryDebugId = (bundlePath, hermesEnabled) => {
118
+ if (!hermesEnabled || !fs.existsSync(bundlePath))
119
+ return;
120
+ const bundleSource = fs.readFileSync(bundlePath, 'utf8');
121
+ const hasSentryDebugId = SENTRY_DEBUG_ID_MARKERS.some(marker => bundleSource.includes(marker));
122
+ if (!hasSentryDebugId)
123
+ return;
124
+ console.warn(`⚠️ Sentry Debug ID detected in a Hermes OTA bundle. Content-derived Debug IDs can increase binary patch sizes. Configure the Sentry Metro wrapper for Bundle Drop OTA builds: ${SENTRY_HERMES_OTA_DOCS_URL}`);
125
+ };
135
126
  const detectHermesFromNativeProject = (projectRoot, platform) => {
136
127
  if (platform === 'android') {
137
128
  return detectBoolean([
@@ -192,7 +183,6 @@ function runBundleScript(options) {
192
183
  const manifestPath = path.join(outputDir, bundleManifest_1.BUNDLE_MANIFEST);
193
184
  const sourceMapPath = path.join(outputDir, 'main.jsbundle.map');
194
185
  const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
195
- const imageManifest = {};
196
186
  const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
197
187
  const generateSourceMap = options?.sourcemap ?? process.argv.includes('--sourcemap');
198
188
  const appVersion = process.env.BUNDLE_DROP_APP_VERSION;
@@ -213,6 +203,7 @@ function runBundleScript(options) {
213
203
  console.error('❌ BUNDLE_DROP_APP_VERSION is required so bundle-manifest.json can include the app version');
214
204
  process.exit(1);
215
205
  }
206
+ const hermesEnabled = shouldCompileHermesBytecode(cfg, platform, projectRoot);
216
207
  [bundlePath, zipPath, metadataPath, manifestPath, sourceMapPath].forEach(file => {
217
208
  if (fs.existsSync(file))
218
209
  fs.unlinkSync(file);
@@ -229,8 +220,15 @@ function runBundleScript(options) {
229
220
  --entry-file index.js \
230
221
  --bundle-output "${bundlePath}" \
231
222
  --assets-dest "${assetsDir}" \
232
- --reset-cache${sourcemapFlag}`, { stdio: 'inherit' });
223
+ --reset-cache${sourcemapFlag}`, {
224
+ stdio: 'inherit',
225
+ env: {
226
+ ...process.env,
227
+ BUNDLE_DROP_OTA_BUILD: '1',
228
+ },
229
+ });
233
230
  console.log('✅ Bundle created');
231
+ warnAboutSentryDebugId(bundlePath, hermesEnabled);
234
232
  const osBin = process.platform === 'darwin'
235
233
  ? 'osx-bin'
236
234
  : process.platform === 'win32'
@@ -242,7 +240,6 @@ function runBundleScript(options) {
242
240
  path.join(projectRoot, 'node_modules', 'hermes-engine', osBin, 'hermesc'),
243
241
  ];
244
242
  const hermescPath = hermesLocations.find(p => fs.existsSync(p));
245
- const hermesEnabled = shouldCompileHermesBytecode(cfg, platform, projectRoot);
246
243
  if (hermesEnabled && hermescPath) {
247
244
  const hbcPath = bundlePath + '.hbc';
248
245
  try {
@@ -284,85 +281,19 @@ function runBundleScript(options) {
284
281
  else {
285
282
  console.log(`ℹ️ Hermes bytecode disabled for ${platform} — bundling plain JS`);
286
283
  }
287
- if (!fs.existsSync(bundlePath)) {
288
- throw new Error(`Bundle output missing after bundling: ${bundlePath}`);
289
- }
290
- const bundleBuffer = fs.readFileSync(bundlePath);
291
- const jsBundleHash = sha256Buffer(bundleBuffer);
292
- const metadata = {
293
- platform,
294
- jsBundleHash,
295
- bundlePath: 'main.jsbundle',
296
- sizeInBytes: bundleBuffer.length,
297
- };
298
- if (runtimeVersion) {
299
- metadata.runtimeVersion = runtimeVersion;
300
- }
301
- const stagedFiles = new Map();
302
- stagedFiles.set('main.jsbundle', bundleBuffer);
303
- const metadataFilePath = `metadata-${fileSuffix}.json`;
304
- const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
305
- stagedFiles.set(metadataFilePath, metadataBuffer);
306
- const zip = new adm_zip_1.default();
307
- const addAssetsToZip = (dir) => {
308
- const items = fs.readdirSync(dir);
309
- for (const item of items) {
310
- const fullPath = path.join(dir, item);
311
- const relPath = path.relative(assetsDir, fullPath);
312
- const normalizedPath = relPath;
313
- if (fs.statSync(fullPath).isDirectory()) {
314
- addAssetsToZip(fullPath);
315
- }
316
- else {
317
- const buffer = fs.readFileSync(fullPath);
318
- stagedFiles.set((0, bundleManifest_1.normalizeManifestPath)(normalizedPath), buffer);
319
- if (isAndroid) {
320
- const manifestKey = (0, bundleManifest_1.normalizeManifestPath)(normalizedPath).replace(/^assets\//, '');
321
- imageManifest[manifestKey] = (0, bundleManifest_1.normalizeManifestPath)(normalizedPath);
322
- }
323
- }
324
- }
325
- };
326
- addAssetsToZip(assetsDir);
327
- if (isAndroid) {
328
- stagedFiles.set('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
329
- console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
330
- }
331
- const files = [...stagedFiles.entries()].map(([filePath, buffer]) => createFileEntry(filePath, buffer));
332
- fs.writeFileSync(metadataPath, metadataBuffer);
333
- const bundleHash = (0, bundleManifest_1.calculateBundleHash)(files);
334
- const manifest = (0, bundleManifest_1.createBundleManifest)({
335
- bundleHash,
336
- jsBundleHash,
337
- platform,
284
+ const artifact = (0, canonicalArtifact_1.buildCanonicalArtifact)({
285
+ platform: platform,
286
+ appVersion,
338
287
  runtimeVersion,
339
- version: appVersion,
340
- files,
288
+ bundlePath,
289
+ assetsDir,
290
+ outputDir,
291
+ sourceMapPath: generateSourceMap ? sourceMapPath : undefined,
292
+ assetTraversal: 'legacy-bare',
341
293
  });
342
- const manifestBuffer = Buffer.from(JSON.stringify(manifest, null, 2));
343
- stagedFiles.set(bundleManifest_1.BUNDLE_MANIFEST, manifestBuffer);
344
- fs.writeFileSync(manifestPath, manifestBuffer);
345
- console.log('🧠 Metadata saved');
346
- console.log('📌 Bundle Hash:', bundleHash);
347
- console.log('📌 JS Bundle Hash:', jsBundleHash);
348
- console.log('📦 Zipping bundle...');
349
- for (const [filePath, buffer] of stagedFiles.entries()) {
350
- zip.addFile(filePath, buffer);
351
- }
352
- zip.writeZip(zipPath);
353
- console.log('✅ OTA bundle zipped');
354
294
  return {
355
295
  projectRoot,
356
- outputDir,
357
- bundlePath,
358
- sourceMapPath: generateSourceMap ? sourceMapPath : undefined,
359
- metadataPath,
360
- zipPath,
361
- runtimeVersion,
362
- hash: bundleHash,
363
- bundleHash,
364
- jsBundleHash,
365
- manifestPath,
296
+ ...artifact,
366
297
  };
367
298
  }
368
299
  /* istanbul ignore next */
@@ -0,0 +1,30 @@
1
+ export type CanonicalArtifactPlatform = 'ios' | 'android';
2
+ export type CanonicalAssetTraversal = 'strict' | 'legacy-bare';
3
+ export type BuildCanonicalArtifactOptions = {
4
+ platform: CanonicalArtifactPlatform;
5
+ appVersion: string;
6
+ runtimeVersion: string;
7
+ bundlePath: string;
8
+ assetsDir: string;
9
+ outputDir: string;
10
+ sourceMapPath?: string;
11
+ assetTraversal?: CanonicalAssetTraversal;
12
+ };
13
+ export type CanonicalArtifact = {
14
+ outputDir: string;
15
+ bundlePath: string;
16
+ sourceMapPath?: string;
17
+ metadataPath: string;
18
+ zipPath: string;
19
+ runtimeVersion: string;
20
+ hash: string;
21
+ bundleHash: string;
22
+ jsBundleHash: string;
23
+ manifestPath: string;
24
+ };
25
+ export declare const normalizeCanonicalAssetPath: (relativePath: string) => string;
26
+ /**
27
+ * Normalizes a framework exporter result into Bundle Drop's frozen manifest and
28
+ * ZIP roles. Framework-specific export commands must finish before this runs.
29
+ */
30
+ export declare function buildCanonicalArtifact(options: BuildCanonicalArtifactOptions): CanonicalArtifact;
@@ -0,0 +1,212 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.normalizeCanonicalAssetPath = void 0;
40
+ exports.buildCanonicalArtifact = buildCanonicalArtifact;
41
+ const adm_zip_1 = __importDefault(require("adm-zip"));
42
+ const crypto_1 = require("crypto");
43
+ const fs = __importStar(require("fs"));
44
+ const path = __importStar(require("path"));
45
+ const bundleManifest_1 = require("../manifest/bundleManifest");
46
+ const sha256Buffer = (buffer) => (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
47
+ const manifestRoleForPath = (filePath) => {
48
+ if (filePath === 'main.jsbundle')
49
+ return 'jsbundle';
50
+ if (filePath.startsWith('metadata-'))
51
+ return 'metadata';
52
+ if (filePath === 'image-manifest.json')
53
+ return 'androidImageManifest';
54
+ return 'asset';
55
+ };
56
+ const createFileEntry = (filePath, buffer) => ({
57
+ path: (0, bundleManifest_1.normalizeManifestPath)(filePath),
58
+ size: buffer.length,
59
+ sha256: sha256Buffer(buffer),
60
+ role: manifestRoleForPath((0, bundleManifest_1.normalizeManifestPath)(filePath)),
61
+ });
62
+ const normalizeCanonicalAssetPath = (relativePath) => {
63
+ const nativeSeparatorsNormalized = relativePath.replace(/\\/g, '/');
64
+ const normalized = (0, bundleManifest_1.normalizeManifestPath)(nativeSeparatorsNormalized);
65
+ if (!normalized ||
66
+ path.isAbsolute(relativePath) ||
67
+ path.win32.isAbsolute(relativePath) ||
68
+ normalized.split('/').includes('..') ||
69
+ normalized === bundleManifest_1.BUNDLE_MANIFEST ||
70
+ normalized === 'main.jsbundle' ||
71
+ normalized === 'image-manifest.json' ||
72
+ normalized.startsWith('metadata-')) {
73
+ throw new Error(`Unsafe or reserved asset path: ${relativePath}`);
74
+ }
75
+ return normalized;
76
+ };
77
+ exports.normalizeCanonicalAssetPath = normalizeCanonicalAssetPath;
78
+ const collectStrictAssets = (assetsDir) => {
79
+ const assets = [];
80
+ const seenCaseInsensitive = new Set();
81
+ const visit = (directory) => {
82
+ for (const item of fs.readdirSync(directory)) {
83
+ const fullPath = path.join(directory, item);
84
+ const stat = fs.lstatSync(fullPath);
85
+ if (stat.isSymbolicLink()) {
86
+ throw new Error(`Asset symlinks are not supported: ${path.relative(assetsDir, fullPath)}`);
87
+ }
88
+ if (stat.isDirectory()) {
89
+ visit(fullPath);
90
+ continue;
91
+ }
92
+ if (!stat.isFile()) {
93
+ throw new Error(`Unsupported asset entry: ${path.relative(assetsDir, fullPath)}`);
94
+ }
95
+ const relativePath = (0, exports.normalizeCanonicalAssetPath)(path.relative(assetsDir, fullPath));
96
+ const collisionKey = relativePath.toLocaleLowerCase('en-US');
97
+ if (seenCaseInsensitive.has(collisionKey)) {
98
+ throw new Error(`Asset path collision: ${relativePath}`);
99
+ }
100
+ seenCaseInsensitive.add(collisionKey);
101
+ assets.push([relativePath, fs.readFileSync(fullPath)]);
102
+ }
103
+ };
104
+ visit(assetsDir);
105
+ return assets;
106
+ };
107
+ /**
108
+ * Bare React Native bundling historically followed symlinks and keyed assets by
109
+ * their exact relative path. Keep that traversal intact for existing bare apps;
110
+ * Expo exports use the strict collector above.
111
+ */
112
+ const collectLegacyBareAssets = (assetsDir) => {
113
+ const assets = [];
114
+ const visit = (directory) => {
115
+ for (const item of fs.readdirSync(directory)) {
116
+ const fullPath = path.join(directory, item);
117
+ if (fs.statSync(fullPath).isDirectory()) {
118
+ visit(fullPath);
119
+ continue;
120
+ }
121
+ const relativePath = (0, bundleManifest_1.normalizeManifestPath)(path.relative(assetsDir, fullPath));
122
+ assets.push([relativePath, fs.readFileSync(fullPath)]);
123
+ }
124
+ };
125
+ visit(assetsDir);
126
+ return assets;
127
+ };
128
+ /**
129
+ * Normalizes a framework exporter result into Bundle Drop's frozen manifest and
130
+ * ZIP roles. Framework-specific export commands must finish before this runs.
131
+ */
132
+ function buildCanonicalArtifact(options) {
133
+ const { platform, appVersion, runtimeVersion, bundlePath, assetsDir, outputDir, sourceMapPath, assetTraversal = 'strict', } = options;
134
+ if (!appVersion.trim())
135
+ throw new Error('Canonical artifact requires an app version');
136
+ if (!runtimeVersion.trim())
137
+ throw new Error('Canonical artifact requires a runtime version');
138
+ if (!fs.existsSync(bundlePath) || !fs.statSync(bundlePath).isFile()) {
139
+ throw new Error(`Bundle output missing after bundling: ${bundlePath}`);
140
+ }
141
+ if (!fs.existsSync(assetsDir) || !fs.statSync(assetsDir).isDirectory()) {
142
+ throw new Error(`Assets directory missing after bundling: ${assetsDir}`);
143
+ }
144
+ const fileSuffix = platform;
145
+ const metadataPath = path.join(outputDir, `metadata-${fileSuffix}.json`);
146
+ const manifestPath = path.join(outputDir, bundleManifest_1.BUNDLE_MANIFEST);
147
+ const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
148
+ const bundleBuffer = fs.readFileSync(bundlePath);
149
+ const jsBundleHash = sha256Buffer(bundleBuffer);
150
+ const metadata = {
151
+ platform,
152
+ jsBundleHash,
153
+ bundlePath: 'main.jsbundle',
154
+ sizeInBytes: bundleBuffer.length,
155
+ runtimeVersion,
156
+ };
157
+ const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
158
+ const stagedFiles = new Map([
159
+ ['main.jsbundle', bundleBuffer],
160
+ [`metadata-${fileSuffix}.json`, metadataBuffer],
161
+ ]);
162
+ const imageManifest = {};
163
+ const assets = assetTraversal === 'legacy-bare'
164
+ ? collectLegacyBareAssets(assetsDir)
165
+ : collectStrictAssets(assetsDir);
166
+ for (const [assetPath, buffer] of assets) {
167
+ stagedFiles.set(assetPath, buffer);
168
+ if (platform === 'android') {
169
+ imageManifest[assetPath.replace(/^assets\//, '')] = assetPath;
170
+ }
171
+ }
172
+ if (platform === 'android') {
173
+ stagedFiles.set('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
174
+ console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
175
+ }
176
+ const files = [...stagedFiles.entries()].map(([filePath, buffer]) => createFileEntry(filePath, buffer));
177
+ const bundleHash = (0, bundleManifest_1.calculateBundleHash)(files);
178
+ const manifest = (0, bundleManifest_1.createBundleManifest)({
179
+ bundleHash,
180
+ jsBundleHash,
181
+ platform,
182
+ runtimeVersion,
183
+ version: appVersion,
184
+ files,
185
+ });
186
+ const manifestBuffer = Buffer.from(JSON.stringify(manifest, null, 2));
187
+ stagedFiles.set(bundleManifest_1.BUNDLE_MANIFEST, manifestBuffer);
188
+ fs.writeFileSync(metadataPath, metadataBuffer);
189
+ fs.writeFileSync(manifestPath, manifestBuffer);
190
+ console.log('🧠 Metadata saved');
191
+ console.log('📌 Bundle Hash:', bundleHash);
192
+ console.log('📌 JS Bundle Hash:', jsBundleHash);
193
+ console.log('📦 Zipping bundle...');
194
+ const zip = new adm_zip_1.default();
195
+ for (const [filePath, buffer] of stagedFiles.entries()) {
196
+ zip.addFile(filePath, buffer);
197
+ }
198
+ zip.writeZip(zipPath);
199
+ console.log('✅ OTA bundle zipped');
200
+ return {
201
+ outputDir,
202
+ bundlePath,
203
+ sourceMapPath,
204
+ metadataPath,
205
+ zipPath,
206
+ runtimeVersion,
207
+ hash: bundleHash,
208
+ bundleHash,
209
+ jsBundleHash,
210
+ manifestPath,
211
+ };
212
+ }
@@ -68,7 +68,7 @@ async function runDownloadBundle(options) {
68
68
  process.exit(1);
69
69
  }
70
70
  const runtimeVersion = config?.runtimeVersion?.[platform] || config?.runtimeVersion?.[platform];
71
- const channelName = argv[3] || config?.defaultChannel || 'General';
71
+ const channelName = argv[3] || config?.defaultChannel || 'develop';
72
72
  const resolveEndpoint = `${serverUrl}/projects/${encodeURIComponent(project.slug)}/ota/resolve`;
73
73
  const outputPath = path.join(outputDir, `bundle-${platform}.zip`);
74
74
  if (!fs.existsSync(outputDir)) {