@gfean/react-native-bundle-drop 0.3.3 → 0.3.6

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 (84) hide show
  1. package/BundleDrop.podspec +2 -0
  2. package/README.md +8 -2
  3. package/android/build.gradle +91 -1
  4. package/android/gradle.properties +1 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
  6. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
  8. package/ios/BundleDropBridge.m +14 -0
  9. package/ios/BundleDropFileOps.swift +220 -0
  10. package/ios/BundleDropLocator.h +11 -0
  11. package/ios/BundleDropLocator.swift +34 -45
  12. package/ios/BundleDropModule.swift +65 -15
  13. package/ios/BundleDropOtaResolver.swift +112 -0
  14. package/ios/BundleDropZipExtractor.h +13 -0
  15. package/ios/BundleDropZipExtractor.m +226 -0
  16. package/lib/CLI/cli.js +56 -6
  17. package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
  18. package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
  19. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
  20. package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
  21. package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
  22. package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
  23. package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
  24. package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
  25. package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
  26. package/lib/CLI/scripts/aipowered/scanner.js +349 -0
  27. package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
  28. package/lib/CLI/scripts/aipowered/types.js +2 -0
  29. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
  30. package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
  31. package/lib/CLI/scripts/init-config.js +10 -5
  32. package/lib/CLI/scripts/init-native-config.js +1 -1
  33. package/lib/CLI/scripts/post-init.js +7 -18
  34. package/lib/CLI/scripts/upload-cli.d.ts +2 -0
  35. package/lib/CLI/scripts/upload-cli.js +67 -28
  36. package/lib/CLI/utils/ui.d.ts +3 -0
  37. package/lib/CLI/utils/ui.js +26 -0
  38. package/lib/api/clientApi.d.ts +2 -1
  39. package/lib/api/clientApi.js +9 -0
  40. package/lib/api/types.d.ts +21 -3
  41. package/lib/bundleInfo.d.ts +12 -0
  42. package/lib/context.d.ts +19 -2
  43. package/lib/context.js +5 -2
  44. package/lib/errors.d.ts +25 -0
  45. package/lib/errors.js +26 -1
  46. package/lib/fs/bundlePointer.d.ts +2 -0
  47. package/lib/fs/bundlePointer.js +14 -4
  48. package/lib/fs/fsUtils.d.ts +1 -2
  49. package/lib/fs/fsUtils.js +12 -27
  50. package/lib/fs/userProperties.d.ts +25 -4
  51. package/lib/fs/userProperties.js +51 -7
  52. package/lib/index.d.ts +7 -3
  53. package/lib/index.js +5 -1
  54. package/lib/injectImageResolver.js +6 -15
  55. package/lib/install/installFromZip.d.ts +1 -1
  56. package/lib/install/installFromZip.js +47 -42
  57. package/lib/loadConfig.d.ts +21 -2
  58. package/lib/loadConfig.js +11 -7
  59. package/lib/manager/downloadAndInstall.d.ts +3 -0
  60. package/lib/manager/downloadAndInstall.js +30 -28
  61. package/lib/manager/reporting.d.ts +2 -0
  62. package/lib/manager/reporting.js +27 -2
  63. package/lib/manager/rollbackState.d.ts +28 -11
  64. package/lib/manager/rollbackState.js +90 -38
  65. package/lib/manager/updateCheck.js +17 -3
  66. package/lib/manager/updateState.d.ts +5 -1
  67. package/lib/manager/updateState.js +20 -11
  68. package/lib/native/fs.d.ts +6 -0
  69. package/lib/native/fs.js +27 -0
  70. package/lib/runtime/initState.d.ts +2 -2
  71. package/lib/runtime/service.d.ts +28 -0
  72. package/lib/runtime/service.js +136 -10
  73. package/lib/scripts/bundle.d.ts +4 -1
  74. package/lib/scripts/bundle.js +42 -29
  75. package/lib/scripts/projectRoot.d.ts +1 -0
  76. package/lib/scripts/projectRoot.js +54 -0
  77. package/lib/scripts/resolve-ios-version.d.ts +2 -0
  78. package/lib/scripts/resolve-ios-version.js +74 -0
  79. package/lib/scripts/upload-bundle.d.ts +2 -1
  80. package/lib/scripts/upload-bundle.js +56 -41
  81. package/lib/types.d.ts +3 -0
  82. package/lib/useBundleDrop.d.ts +2 -0
  83. package/lib/useBundleDrop.js +1 -0
  84. package/package.json +9 -11
@@ -37,8 +37,7 @@ 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.cleanupArtifacts = void 0;
41
- exports.findProjectRoot = findProjectRoot;
40
+ exports.cleanupArtifacts = exports.findProjectRoot = void 0;
42
41
  exports.parseAndroidVersionFromGradle = parseAndroidVersionFromGradle;
43
42
  exports.runUploadBundle = runUploadBundle;
44
43
  const axios_1 = __importDefault(require("axios"));
@@ -48,23 +47,10 @@ const fs = __importStar(require("fs"));
48
47
  const os_1 = __importDefault(require("os"));
49
48
  const path = __importStar(require("path"));
50
49
  const plist = __importStar(require("plist"));
50
+ const projectRoot_1 = require("./projectRoot");
51
+ Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
52
+ const resolve_ios_version_1 = require("./resolve-ios-version");
51
53
  const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
52
- function findProjectRoot(startDir) {
53
- let dir = path.resolve(startDir);
54
- const MAX_UP = 12;
55
- for (let i = 0; i < MAX_UP; i++) {
56
- const iosDir = path.join(dir, 'ios');
57
- const androidDir = path.join(dir, 'android');
58
- if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
59
- return dir;
60
- }
61
- const parent = path.dirname(dir);
62
- if (parent === dir)
63
- break;
64
- dir = parent;
65
- }
66
- return startDir;
67
- }
68
54
  function parseAndroidVersionFromGradle(filePath) {
69
55
  if (!fs.existsSync(filePath)) {
70
56
  console.error(`❌ build.gradle not found at ${filePath}`);
@@ -81,25 +67,20 @@ function parseAndroidVersionFromGradle(filePath) {
81
67
  const cleanupArtifacts = (platform, zipPath) => {
82
68
  const outputDir = path.join(getPackageRoot(), 'dist');
83
69
  try {
84
- if (fs.existsSync(zipPath)) {
85
- fs.unlinkSync(zipPath);
86
- console.log(`🧹 Deleted: ${zipPath}`);
87
- }
88
70
  const suffix = platform === 'ios' ? 'ios' : 'android';
89
- const metadataPath = path.join(outputDir, `metadata-${suffix}.json`);
90
- const assetsPath = path.join(outputDir, 'assets');
91
- if (fs.existsSync(metadataPath)) {
92
- fs.unlinkSync(metadataPath);
93
- console.log(`🧹 Deleted: ${metadataPath}`);
71
+ const filesToDelete = [
72
+ zipPath,
73
+ path.join(outputDir, `metadata-${suffix}.json`),
74
+ path.join(outputDir, 'main.jsbundle'),
75
+ path.join(outputDir, 'main.jsbundle.map'),
76
+ ];
77
+ for (const file of filesToDelete) {
78
+ if (fs.existsSync(file))
79
+ fs.unlinkSync(file);
94
80
  }
81
+ const assetsPath = path.join(outputDir, 'assets');
95
82
  if (fs.existsSync(assetsPath)) {
96
83
  fs.rmSync(assetsPath, { recursive: true, force: true });
97
- console.log(`🧹 Deleted: ${assetsPath}`);
98
- }
99
- const bundlePath = path.join(outputDir, 'main.jsbundle');
100
- if (fs.existsSync(bundlePath)) {
101
- fs.unlinkSync(bundlePath);
102
- console.log(`🧹 Deleted: ${bundlePath}`);
103
84
  }
104
85
  }
105
86
  catch (err) {
@@ -111,7 +92,7 @@ async function runUploadBundle(options) {
111
92
  const packageRoot = getPackageRoot();
112
93
  const outputDir = path.join(packageRoot, 'dist');
113
94
  const argv = options?.argv || process.argv;
114
- const projectRoot = findProjectRoot(options?.cwd || process.cwd());
95
+ const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
115
96
  const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
116
97
  if (!fs.existsSync(configPath)) {
117
98
  console.error('❌ bundle.drop.config.js not found in project root');
@@ -166,6 +147,9 @@ async function runUploadBundle(options) {
166
147
  const runtimeVersionOverride = runtimeVersionArg?.split('=')[1];
167
148
  const releaseNotesArg = args.find(arg => arg.startsWith('--release-notes='));
168
149
  let releaseNotes = releaseNotesArg ? releaseNotesArg.split('=')[1] : undefined;
150
+ const generateSourceMap = args.includes('--sourcemap');
151
+ const artifactDirArg = args.find(arg => arg.startsWith('--artifact-dir='));
152
+ const artifactDir = artifactDirArg ? path.resolve(artifactDirArg.split('=')[1]) : undefined;
169
153
  const MAX_NOTES = 2000;
170
154
  if (releaseNotes && releaseNotes.length > MAX_NOTES) {
171
155
  console.warn(`⚠️ Release notes too long (${releaseNotes.length}); truncating to ${MAX_NOTES} chars.`);
@@ -192,11 +176,16 @@ async function runUploadBundle(options) {
192
176
  try {
193
177
  const plistContent = fs.readFileSync(plistFile, 'utf-8');
194
178
  const parsed = plist.parse(plistContent);
195
- version = parsed.CFBundleShortVersionString;
196
- if (!version) {
179
+ const rawVersion = parsed.CFBundleShortVersionString;
180
+ if (!rawVersion) {
197
181
  console.error('❌ Could not find CFBundleShortVersionString in plist');
198
182
  process.exit(1);
199
183
  }
184
+ const resolved = (0, resolve_ios_version_1.resolveIosPlistVersion)(rawVersion, projectRoot);
185
+ if (!resolved) {
186
+ process.exit(1);
187
+ }
188
+ version = resolved;
200
189
  }
201
190
  catch (err) {
202
191
  console.error('❌ Failed to read plist file:', err);
@@ -224,11 +213,12 @@ async function runUploadBundle(options) {
224
213
  const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
225
214
  const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
226
215
  const bundleCommand = fs.existsSync(compiledBundleScript)
227
- ? `node ${compiledBundleScript}`
228
- : `ts-node ${tsBundleScript}`;
216
+ ? `node "${compiledBundleScript}"`
217
+ : `ts-node "${tsBundleScript}"`;
229
218
  try {
219
+ const sourcemapArg = generateSourceMap ? ' --sourcemap' : '';
230
220
  console.log(`📦 Running bundler for ${platform}...`);
231
- (0, child_process_1.execSync)(`${bundleCommand} ${platform}`, {
221
+ (0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
232
222
  stdio: 'inherit',
233
223
  });
234
224
  const suffix = platform === 'ios' ? 'ios' : 'android';
@@ -279,7 +269,7 @@ async function runUploadBundle(options) {
279
269
  form.append('releaseNotes', releaseNotes);
280
270
  }
281
271
  form.append('file', fs.createReadStream(zipPath));
282
- console.log(`⬆️ Uploading ${platform} bundle (v${version}) to project "${projectSlug}" at ${serverUrl}...`);
272
+ console.log(`→ Uploading bundle to server...`);
283
273
  try {
284
274
  const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
285
275
  headers: {
@@ -289,7 +279,32 @@ async function runUploadBundle(options) {
289
279
  maxContentLength: Infinity,
290
280
  maxBodyLength: Infinity,
291
281
  });
292
- console.log('✅ Upload complete:', res.data);
282
+ if (artifactDir) {
283
+ try {
284
+ fs.mkdirSync(artifactDir, { recursive: true });
285
+ const bundleFile = path.join(outputDir, 'main.jsbundle');
286
+ const sourceMapFile = path.join(outputDir, 'main.jsbundle.map');
287
+ const result = { ...res.data };
288
+ if (fs.existsSync(bundleFile)) {
289
+ fs.copyFileSync(bundleFile, path.join(artifactDir, 'main.jsbundle'));
290
+ result.bundlePath = path.join(artifactDir, 'main.jsbundle');
291
+ }
292
+ if (generateSourceMap && fs.existsSync(sourceMapFile)) {
293
+ fs.copyFileSync(sourceMapFile, path.join(artifactDir, 'main.jsbundle.map'));
294
+ result.sourceMapPath = path.join(artifactDir, 'main.jsbundle.map');
295
+ }
296
+ fs.writeFileSync(path.join(artifactDir, 'bundle-drop-result.json'), JSON.stringify(result, null, 2));
297
+ console.log('📁 Artifacts saved to:', artifactDir);
298
+ }
299
+ catch (copyErr) {
300
+ console.warn('⚠️ Upload succeeded but artifact copy failed:', copyErr.message);
301
+ }
302
+ }
303
+ console.log('✅ Upload complete');
304
+ if (res.data?.bundleVersion != null)
305
+ console.log(`Bundle Version: ${res.data.bundleVersion}`);
306
+ if (res.data?.hash)
307
+ console.log(`Hash: ${res.data.hash}`);
293
308
  return res.data;
294
309
  }
295
310
  catch (err) {
package/lib/types.d.ts CHANGED
@@ -1 +1,4 @@
1
+ /**
2
+ * Startup policy controlling what BundleDrop does after local state hydration.
3
+ */
1
4
  export type UpdatePolicy = 'manual' | 'immediate' | 'on-next-launch';
@@ -36,6 +36,8 @@ export type UseBundleDropReturn = {
36
36
  result: ApplyUpdateResult;
37
37
  status?: string;
38
38
  }>;
39
+ /** Mark the current OTA candidate healthy for this device. */
40
+ reportHealthy: () => Promise<void>;
39
41
  /** Fetch available channel names from the server (API key auth). */
40
42
  fetchAvailableChannels: () => Promise<string[]>;
41
43
  /** Last fetched list of channel names. */
@@ -24,6 +24,7 @@ function useBundleDrop() {
24
24
  checkLatest: service_1.checkLatest,
25
25
  downloadUpdate: service_1.downloadAndStage,
26
26
  applyUpdate: service_1.applyDownloadedUpdate,
27
+ reportHealthy: service_1.reportHealthy,
27
28
  fetchAvailableChannels: service_1.fetchAvailableChannels,
28
29
  availableChannels: state.availableChannels,
29
30
  setChannel: service_1.setChannel,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.3.3",
4
- "nativeVersion": "0.3.2",
3
+ "version": "0.3.6",
4
+ "nativeVersion": "0.3.6",
5
5
  "description": "Over-the-air (OTA) updates for React Native — ship fixes instantly, no App Store or Play Store delays",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -40,6 +40,9 @@
40
40
  "test": "jest --runInBand",
41
41
  "test:coverage": "jest --runInBand --coverage",
42
42
  "coverage:check": "node scripts/check-coverage-thresholds.cjs",
43
+ "test:android": "node scripts/run-android-tests.cjs",
44
+ "test:ios": "node scripts/run-ios-tests.cjs",
45
+ "test:native": "yarn test:android && yarn test:ios",
43
46
  "coverage:gate": "yarn test:coverage && yarn coverage:check",
44
47
  "prepublishOnly": "yarn clean && yarn build",
45
48
  "build-and-publish": "yarn clean && yarn build && npm publish --access=restricted",
@@ -58,6 +61,7 @@
58
61
  "husky": "^9.1.7",
59
62
  "jest": "^29.7.0",
60
63
  "react": "^18.3.1",
64
+ "react-native": ">=0.71.0",
61
65
  "react-test-renderer": "^18.3.1",
62
66
  "rimraf": "^6.0.1",
63
67
  "ts-jest": "^29.4.4",
@@ -69,12 +73,9 @@
69
73
  },
70
74
  "files": [
71
75
  "lib",
72
- "android/src/**",
76
+ "android/src/main/**",
73
77
  "android/build.gradle",
74
78
  "android/gradle.properties",
75
- "android/gradle/wrapper/**",
76
- "android/gradlew",
77
- "android/gradlew.bat",
78
79
  "ios/*.{m,h,mm,swift}",
79
80
  "BundleDrop.podspec",
80
81
  "react-native.config.js",
@@ -108,18 +109,15 @@
108
109
  },
109
110
  "dependencies": {
110
111
  "adm-zip": "^0.5.16",
111
- "archiver": "^7.0.1",
112
112
  "axios": "^1.8.4",
113
113
  "chalk": "4",
114
114
  "commander": "^13.1.0",
115
- "fflate": "^0.8.2",
115
+ "diff": "^9.0.0",
116
116
  "figures": "3",
117
117
  "form-data": "^4.0.2",
118
- "formdata-node": "^6.0.3",
119
118
  "fs-extra": "^11.2.0",
120
119
  "plist": "^3.1.0",
121
- "prompts": "^2.4.2",
122
- "undici": "^7.8.0"
120
+ "prompts": "^2.4.2"
123
121
  },
124
122
  "publishConfig": {
125
123
  "access": "restricted"