@gfean/react-native-bundle-drop 0.3.2 → 0.3.5
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.
- package/BundleDrop.podspec +4 -1
- package/LICENSE +15 -0
- package/README.md +120 -253
- package/android/build.gradle +91 -1
- package/android/gradle.properties +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
- package/ios/BundleDropBridge.m +14 -0
- package/ios/BundleDropFileOps.swift +220 -0
- package/ios/BundleDropLocator.swift +33 -44
- package/ios/BundleDropModule.swift +65 -15
- package/ios/BundleDropOtaResolver.swift +112 -0
- package/ios/BundleDropZipExtractor.h +13 -0
- package/ios/BundleDropZipExtractor.m +226 -0
- package/lib/CLI/cli.js +15 -3
- package/lib/CLI/scripts/init-config.js +12 -5
- package/lib/CLI/scripts/init-native-config.js +17 -9
- package/lib/CLI/scripts/post-init.js +9 -3
- package/lib/CLI/scripts/upload-cli.js +26 -9
- package/lib/api/types.d.ts +4 -3
- package/lib/bundleInfo.d.ts +12 -0
- package/lib/context.d.ts +17 -0
- package/lib/context.js +3 -0
- package/lib/errors.d.ts +25 -0
- package/lib/errors.js +26 -1
- package/lib/fs/fsUtils.d.ts +1 -2
- package/lib/fs/fsUtils.js +12 -27
- package/lib/fs/userProperties.d.ts +25 -4
- package/lib/fs/userProperties.js +51 -7
- package/lib/index.d.ts +1 -0
- package/lib/install/installFromZip.d.ts +1 -1
- package/lib/install/installFromZip.js +47 -42
- package/lib/loadConfig.d.ts +19 -0
- package/lib/loadConfig.js +11 -7
- package/lib/manager/downloadAndInstall.js +7 -25
- package/lib/manager/reporting.js +2 -2
- package/lib/manager/rollbackState.d.ts +3 -3
- package/lib/manager/rollbackState.js +6 -19
- package/lib/manager/updateCheck.js +2 -2
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +27 -0
- package/lib/runtime/initState.d.ts +2 -2
- package/lib/runtime/service.js +2 -0
- package/lib/scripts/bundle.js +2 -2
- package/lib/scripts/resolve-ios-version.d.ts +2 -0
- package/lib/scripts/resolve-ios-version.js +74 -0
- package/lib/scripts/upload-bundle.js +10 -4
- package/lib/types.d.ts +3 -0
- package/package.json +53 -16
- package/CLIENT_README.md +0 -411
package/package.json
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfean/react-native-bundle-drop",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.3.5",
|
|
4
|
+
"nativeVersion": "0.3.5",
|
|
5
|
+
"description": "Over-the-air (OTA) updates for React Native — ship fixes instantly, no App Store or Play Store delays",
|
|
5
6
|
"main": "lib/index.js",
|
|
6
7
|
"types": "lib/index.d.ts",
|
|
7
|
-
"author":
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "George Fean",
|
|
10
|
+
"url": "https://github.com/GFean"
|
|
11
|
+
},
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"homepage": "https://bundledrop.app",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/GFean/react-native-bundle-drop/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/GFean/react-native-bundle-drop.git"
|
|
20
|
+
},
|
|
10
21
|
"exports": {
|
|
11
22
|
".": {
|
|
12
23
|
"types": "./lib/index.d.ts",
|
|
@@ -18,6 +29,10 @@
|
|
|
18
29
|
},
|
|
19
30
|
"./package.json": "./package.json"
|
|
20
31
|
},
|
|
32
|
+
"sideEffects": [
|
|
33
|
+
"./lib/bootstrap.js",
|
|
34
|
+
"./lib/index.js"
|
|
35
|
+
],
|
|
21
36
|
"scripts": {
|
|
22
37
|
"clean": "rimraf lib dist",
|
|
23
38
|
"build": "tsc -p tsconfig.build.json && node scripts/make-cli-executable.js",
|
|
@@ -25,6 +40,9 @@
|
|
|
25
40
|
"test": "jest --runInBand",
|
|
26
41
|
"test:coverage": "jest --runInBand --coverage",
|
|
27
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",
|
|
28
46
|
"coverage:gate": "yarn test:coverage && yarn coverage:check",
|
|
29
47
|
"prepublishOnly": "yarn clean && yarn build",
|
|
30
48
|
"build-and-publish": "yarn clean && yarn build && npm publish --access=restricted",
|
|
@@ -43,6 +61,7 @@
|
|
|
43
61
|
"husky": "^9.1.7",
|
|
44
62
|
"jest": "^29.7.0",
|
|
45
63
|
"react": "^18.3.1",
|
|
64
|
+
"react-native": ">=0.71.0",
|
|
46
65
|
"react-test-renderer": "^18.3.1",
|
|
47
66
|
"rimraf": "^6.0.1",
|
|
48
67
|
"ts-jest": "^29.4.4",
|
|
@@ -54,32 +73,50 @@
|
|
|
54
73
|
},
|
|
55
74
|
"files": [
|
|
56
75
|
"lib",
|
|
57
|
-
"android/src/**",
|
|
76
|
+
"android/src/main/**",
|
|
58
77
|
"android/build.gradle",
|
|
59
78
|
"android/gradle.properties",
|
|
60
|
-
"android/gradle/wrapper/**",
|
|
61
|
-
"android/gradlew",
|
|
62
|
-
"android/gradlew.bat",
|
|
63
79
|
"ios/*.{m,h,mm,swift}",
|
|
64
80
|
"BundleDrop.podspec",
|
|
65
81
|
"react-native.config.js",
|
|
66
|
-
"README.md"
|
|
67
|
-
|
|
82
|
+
"README.md"
|
|
83
|
+
],
|
|
84
|
+
"keywords": [
|
|
85
|
+
"react-native",
|
|
86
|
+
"react-native-ota",
|
|
87
|
+
"ota-updates",
|
|
88
|
+
"over-the-air",
|
|
89
|
+
"react-native-update",
|
|
90
|
+
"react-native-updates",
|
|
91
|
+
"bundle-updates",
|
|
92
|
+
"hot-update",
|
|
93
|
+
"codepush-alternative",
|
|
94
|
+
"expo-eas-update-alternative",
|
|
95
|
+
"react-native-deployment",
|
|
96
|
+
"mobile-updates",
|
|
97
|
+
"app-updates",
|
|
98
|
+
"live-updates",
|
|
99
|
+
"feature-rollout",
|
|
100
|
+
"staged-rollout",
|
|
101
|
+
"rollback",
|
|
102
|
+
"react-native-ci",
|
|
103
|
+
"react-native-release",
|
|
104
|
+
"react-native-production"
|
|
68
105
|
],
|
|
106
|
+
"peerDependencies": {
|
|
107
|
+
"react": ">=17.0.0",
|
|
108
|
+
"react-native": ">=0.71.0"
|
|
109
|
+
},
|
|
69
110
|
"dependencies": {
|
|
70
111
|
"adm-zip": "^0.5.16",
|
|
71
|
-
"archiver": "^7.0.1",
|
|
72
112
|
"axios": "^1.8.4",
|
|
73
113
|
"chalk": "4",
|
|
74
114
|
"commander": "^13.1.0",
|
|
75
|
-
"fflate": "^0.8.2",
|
|
76
115
|
"figures": "3",
|
|
77
116
|
"form-data": "^4.0.2",
|
|
78
|
-
"formdata-node": "^6.0.3",
|
|
79
117
|
"fs-extra": "^11.2.0",
|
|
80
118
|
"plist": "^3.1.0",
|
|
81
|
-
"prompts": "^2.4.2"
|
|
82
|
-
"undici": "^7.8.0"
|
|
119
|
+
"prompts": "^2.4.2"
|
|
83
120
|
},
|
|
84
121
|
"publishConfig": {
|
|
85
122
|
"access": "restricted"
|
package/CLIENT_README.md
DELETED
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
# Bundle Drop Client Quickstart (React Native)
|
|
2
|
-
|
|
3
|
-
This guide is for app teams integrating `@gfean/react-native-bundle-drop` to fetch and apply OTA bundles.
|
|
4
|
-
|
|
5
|
-
## 1) Install and link
|
|
6
|
-
```bash
|
|
7
|
-
yarn add @gfean/react-native-bundle-drop
|
|
8
|
-
cd ios && pod install && cd ..
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Add the Android bootstrap side-effect import:
|
|
12
|
-
```js
|
|
13
|
-
// index.js (entry)
|
|
14
|
-
import '@gfean/react-native-bundle-drop/bootstrap';
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
### Metro config (resolve bundle.drop.config.js from node_modules)
|
|
18
|
-
If Metro cannot find `bundle.drop.config.js` from packages, add an alias:
|
|
19
|
-
```js
|
|
20
|
-
// metro.config.js
|
|
21
|
-
const path = require('path');
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
resolver: {
|
|
25
|
-
extraNodeModules: {
|
|
26
|
-
'bundle-drop-config': path.resolve(__dirname, 'bundle.drop.config.js'),
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## 2) App config
|
|
33
|
-
Add `bundle.drop.config.js` to your project root:
|
|
34
|
-
```js
|
|
35
|
-
module.exports = {
|
|
36
|
-
serverUrl: '<YOUR_BACKEND_URL>',
|
|
37
|
-
runtimeVersion: {
|
|
38
|
-
ios: '1.0.0',
|
|
39
|
-
android: '1.0.0',
|
|
40
|
-
},
|
|
41
|
-
org: { slug: '<org-slug>' },
|
|
42
|
-
project: {
|
|
43
|
-
name: '<Project Name>',
|
|
44
|
-
slug: '<project-slug>',
|
|
45
|
-
apiKey: '<project-api-key>',
|
|
46
|
-
},
|
|
47
|
-
debugLocal: false,
|
|
48
|
-
};
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## 3) Minimal usage
|
|
52
|
-
Startup (required):
|
|
53
|
-
```ts
|
|
54
|
-
import '@gfean/react-native-bundle-drop/bootstrap';
|
|
55
|
-
import { BundleDrop } from '@gfean/react-native-bundle-drop';
|
|
56
|
-
|
|
57
|
-
BundleDrop.init({
|
|
58
|
-
enabled: !__DEV__,
|
|
59
|
-
environment: __DEV__ ? 'development' : 'production',
|
|
60
|
-
policy: __DEV__ ? 'manual' : 'on-next-launch',
|
|
61
|
-
channelName: 'General',
|
|
62
|
-
onStatusUpdate: msg => console.log('[OTA]', msg),
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
`environment` is required and should come from your app runtime config (`.env`, schema loader, build flavor, etc.), not from `bundle.drop.config.js`. `enabled` defaults to `true`; set `enabled: false` when you want BundleDrop initialized in no-op mode for a given runtime.
|
|
67
|
-
|
|
68
|
-
Recommended pattern:
|
|
69
|
-
- Always call `BundleDrop.init(...)` during startup.
|
|
70
|
-
- Use `enabled: false` when OTA should be off for a given runtime, such as Metro/dev or certain app flavors.
|
|
71
|
-
- This keeps `useBundleDrop()` safe to mount while all OTA actions remain no-op.
|
|
72
|
-
|
|
73
|
-
Manual UI example:
|
|
74
|
-
```ts
|
|
75
|
-
import { useBundleDrop } from '@gfean/react-native-bundle-drop';
|
|
76
|
-
|
|
77
|
-
const {
|
|
78
|
-
channelName,
|
|
79
|
-
setChannel,
|
|
80
|
-
isEnabled,
|
|
81
|
-
status,
|
|
82
|
-
isBusy,
|
|
83
|
-
installedInfo,
|
|
84
|
-
pendingApply,
|
|
85
|
-
checkLatest,
|
|
86
|
-
downloadUpdate,
|
|
87
|
-
applyUpdate,
|
|
88
|
-
fetchAvailableChannels,
|
|
89
|
-
availableChannels,
|
|
90
|
-
} = useBundleDrop();
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
If `BundleDrop.init(...)` is skipped, BundleDrop warns once and behaves like `enabled: false` until init happens.
|
|
94
|
-
|
|
95
|
-
Quick check-only pattern:
|
|
96
|
-
```ts
|
|
97
|
-
const { checkLatest, status } = useBundleDrop();
|
|
98
|
-
await checkLatest();
|
|
99
|
-
console.log(status);
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 4) Policies
|
|
103
|
-
- `manual`: initialize local BundleDrop state but do not auto resolve/download/apply on startup.
|
|
104
|
-
- `immediate`: download, stage, then apply immediately.
|
|
105
|
-
- `on-next-launch`: download and stage now; apply on next launch.
|
|
106
|
-
|
|
107
|
-
`checkOnly: true` can be combined with init when you want startup to perform only a resolve/check.
|
|
108
|
-
|
|
109
|
-
## 5) Channels
|
|
110
|
-
- Keep channel names stable: `General`, `Beta`, `QA`.
|
|
111
|
-
- `BundleDrop.init(...)` sets the initial runtime `channelName`.
|
|
112
|
-
- `BundleDrop.setChannel(channelName)` or `useBundleDrop().setChannel(channelName)` can switch the active channel later.
|
|
113
|
-
- `BundleDrop.getChannelName()` reads the active runtime channel outside React.
|
|
114
|
-
- `fetchAvailableChannels()` retrieves available public channels for the configured project.
|
|
115
|
-
- `fetchBundles({ channelName? })` lists downloadable bundles, defaulting to the active runtime channel.
|
|
116
|
-
|
|
117
|
-
## 6) Compatibility (`runtimeVersion`)
|
|
118
|
-
- Define `runtimeVersion` per platform in `bundle.drop.config.js`.
|
|
119
|
-
- Upload embeds `runtimeVersion` in metadata.
|
|
120
|
-
- Client sends `runtimeVersion` during OTA resolve.
|
|
121
|
-
|
|
122
|
-
## 7) Targeted rollout (`currentUserProperties`)
|
|
123
|
-
Use user properties to target cohorts from backend rollout rules.
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
import {
|
|
127
|
-
setUserProperty,
|
|
128
|
-
setUserPropery,
|
|
129
|
-
getUserProperties,
|
|
130
|
-
getCurrentUserProperties,
|
|
131
|
-
removeUserProperty,
|
|
132
|
-
resetUserProperties,
|
|
133
|
-
} from '@gfean/react-native-bundle-drop';
|
|
134
|
-
|
|
135
|
-
await setUserProperty('QA Analyst');
|
|
136
|
-
await setUserProperty('Beta Tester');
|
|
137
|
-
await setUserPropery('QA Analyst'); // alias + duplicate ignored
|
|
138
|
-
|
|
139
|
-
const propsA = await getUserProperties();
|
|
140
|
-
const propsB = await getCurrentUserProperties();
|
|
141
|
-
|
|
142
|
-
await removeUserProperty('Beta Tester');
|
|
143
|
-
await resetUserProperties();
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Behavior:
|
|
147
|
-
- Values are trimmed.
|
|
148
|
-
- Duplicates are ignored.
|
|
149
|
-
- Stored locally in `bundle-drop/user-properties.json`.
|
|
150
|
-
- Sent automatically as `currentUserProperties` during OTA resolve checks.
|
|
151
|
-
|
|
152
|
-
Environment behavior:
|
|
153
|
-
- `environment` is sent automatically from `BundleDrop.init(...)`.
|
|
154
|
-
- It is intended for analytics and future runtime targeting context.
|
|
155
|
-
- Do not store environment in `bundle.drop.config.js`.
|
|
156
|
-
|
|
157
|
-
Disabled behavior:
|
|
158
|
-
- With `enabled: false`, BundleDrop does not perform startup OTA work.
|
|
159
|
-
- `useBundleDrop()` exposes `isEnabled: false`.
|
|
160
|
-
- OTA actions such as `checkLatest()`, `downloadUpdate()`, and `applyUpdate()` return disabled/no-op results instead of throwing.
|
|
161
|
-
|
|
162
|
-
## 8) Bundling/upload (CI/local)
|
|
163
|
-
- Login (interactive, for local development):
|
|
164
|
-
```bash
|
|
165
|
-
npx bundle-drop login
|
|
166
|
-
```
|
|
167
|
-
- Upload Android:
|
|
168
|
-
```bash
|
|
169
|
-
npx bundle-drop upload android --version 1.2.3 --channel General
|
|
170
|
-
# or --buildgradle-path android/app/build.gradle
|
|
171
|
-
```
|
|
172
|
-
- Upload iOS:
|
|
173
|
-
```bash
|
|
174
|
-
npx bundle-drop upload ios --plist-file ios/Info.plist --channel General
|
|
175
|
-
# or --version 1.2.3
|
|
176
|
-
```
|
|
177
|
-
- Optional upload flags:
|
|
178
|
-
- `--runtimeVersion x.y.z` — override runtime version
|
|
179
|
-
- `--release-notes "text"` — attach release notes (max 2000 chars)
|
|
180
|
-
- `--token <pat>` — authenticate with a Personal Access Token (skips `bundle-drop login`; ideal for CI/CD)
|
|
181
|
-
- `--author <name>` — override the author name stored with the bundle
|
|
182
|
-
|
|
183
|
-
### CI/CD example
|
|
184
|
-
```bash
|
|
185
|
-
npx bundle-drop upload android \
|
|
186
|
-
--version 1.2.3 \
|
|
187
|
-
--channel General \
|
|
188
|
-
--token $BUNDLE_DROP_PAT \
|
|
189
|
-
--author "CI Pipeline"
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Upload result file
|
|
193
|
-
|
|
194
|
-
After a successful upload, the CLI writes a result file inside the module directory at `node_modules/@gfean/react-native-bundle-drop/dist/bundle-drop-result.json` with all upload details:
|
|
195
|
-
|
|
196
|
-
```json
|
|
197
|
-
{
|
|
198
|
-
"platform": "android",
|
|
199
|
-
"appVersion": "1.2.3",
|
|
200
|
-
"channel": "General",
|
|
201
|
-
"orgSlug": "my-org",
|
|
202
|
-
"projectSlug": "my-app",
|
|
203
|
-
"runtimeVersion": "1.0.0",
|
|
204
|
-
"bundleId": "abc123",
|
|
205
|
-
"bundleVersion": 42,
|
|
206
|
-
"bundleVersionLabel": "v42",
|
|
207
|
-
"hash": "sha256hex...",
|
|
208
|
-
"releaseNotes": "Bug fixes",
|
|
209
|
-
"author": "CI Pipeline"
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
Use this in CI to read any field — no output parsing needed:
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
BD_RESULT="node_modules/@gfean/react-native-bundle-drop/dist/bundle-drop-result.json"
|
|
217
|
-
|
|
218
|
-
# Read any field
|
|
219
|
-
jq -r '.bundleVersionLabel' "$BD_RESULT"
|
|
220
|
-
jq -r '.appVersion' "$BD_RESULT"
|
|
221
|
-
jq -r '.channel' "$BD_RESULT"
|
|
222
|
-
|
|
223
|
-
# Azure DevOps
|
|
224
|
-
echo "##vso[task.setvariable variable=BundleVersion]$(jq -r '.bundleVersionLabel' "$BD_RESULT")"
|
|
225
|
-
|
|
226
|
-
# GitHub Actions
|
|
227
|
-
echo "bundle_version=$(jq -r '.bundleVersionLabel' "$BD_RESULT")" >> "$GITHUB_OUTPUT"
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## 9) Native setup (Android)
|
|
231
|
-
|
|
232
|
-
The only change in your `MainApplication` (Kotlin or Java) is a single override that delegates bundle resolution to BundleDrop. It returns the OTA bundle path when available, otherwise falls back to the default.
|
|
233
|
-
|
|
234
|
-
Kotlin:
|
|
235
|
-
```kt
|
|
236
|
-
override fun getJSBundleFile(): String? =
|
|
237
|
-
BundleDropModule.resolveJSBundleFile(applicationContext, super.getJSBundleFile())
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
Java:
|
|
241
|
-
```java
|
|
242
|
-
@Override
|
|
243
|
-
protected String getJSBundleFile() {
|
|
244
|
-
return BundleDropModule.resolveJSBundleFile(getApplicationContext(), super.getJSBundleFile());
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### A) Kotlin — older RN template (has `reactNativeHost`)
|
|
249
|
-
|
|
250
|
-
If your `MainApplication.kt` already has a `reactNativeHost` block, add the import and the one-liner inside it:
|
|
251
|
-
|
|
252
|
-
```kt
|
|
253
|
-
import com.bundledrop.BundleDropModule
|
|
254
|
-
|
|
255
|
-
// inside your existing reactNativeHost object:
|
|
256
|
-
override fun getJSBundleFile(): String? =
|
|
257
|
-
BundleDropModule.resolveJSBundleFile(applicationContext, super.getJSBundleFile())
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### B) Kotlin — RN 0.84+ template (ReactHost, no `reactNativeHost`)
|
|
261
|
-
|
|
262
|
-
RN 0.84+ templates use `ReactHost` but don't expose `reactNativeHost`. BundleDrop needs `ReactNativeHost.getJSBundleFile()`, so you reintroduce `reactNativeHost` and wire `reactHost` from it.
|
|
263
|
-
|
|
264
|
-
1. Add imports (only if missing):
|
|
265
|
-
```kt
|
|
266
|
-
import com.bundledrop.BundleDropModule
|
|
267
|
-
import com.facebook.react.ReactHost
|
|
268
|
-
import com.facebook.react.ReactNativeHost
|
|
269
|
-
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
|
270
|
-
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
|
271
|
-
import com.facebook.react.defaults.DefaultReactNativeHost
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
2. Add `reactNativeHost` property (before `reactHost`):
|
|
275
|
-
```kt
|
|
276
|
-
override val reactNativeHost: ReactNativeHost =
|
|
277
|
-
object : DefaultReactNativeHost(this) {
|
|
278
|
-
|
|
279
|
-
override fun getPackages() = PackageList(this).packages
|
|
280
|
-
override fun getJSMainModuleName(): String = "index"
|
|
281
|
-
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
|
|
282
|
-
|
|
283
|
-
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
284
|
-
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
285
|
-
|
|
286
|
-
override fun getJSBundleFile(): String? =
|
|
287
|
-
BundleDropModule.resolveJSBundleFile(applicationContext, super.getJSBundleFile())
|
|
288
|
-
}
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
3. Ensure `reactHost` is created from `reactNativeHost`:
|
|
292
|
-
```kt
|
|
293
|
-
override val reactHost: ReactHost by lazy {
|
|
294
|
-
getDefaultReactHost(
|
|
295
|
-
context = applicationContext,
|
|
296
|
-
reactNativeHost = reactNativeHost
|
|
297
|
-
)
|
|
298
|
-
}
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
4. Ensure `onCreate()` calls:
|
|
302
|
-
```kt
|
|
303
|
-
loadReactNative(this)
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
### C) Java — older RN template (`MainApplication.java`)
|
|
307
|
-
|
|
308
|
-
Older React Native versions used Java instead of Kotlin. Add the import and the override inside your `ReactNativeHost` anonymous class:
|
|
309
|
-
|
|
310
|
-
```java
|
|
311
|
-
import com.bundledrop.BundleDropModule;
|
|
312
|
-
|
|
313
|
-
// inside your ReactNativeHost (or DefaultReactNativeHost) anonymous class:
|
|
314
|
-
@Override
|
|
315
|
-
protected String getJSBundleFile() {
|
|
316
|
-
return BundleDropModule.resolveJSBundleFile(getApplicationContext(), super.getJSBundleFile());
|
|
317
|
-
}
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
Full example context:
|
|
321
|
-
|
|
322
|
-
```java
|
|
323
|
-
private final ReactNativeHost mReactNativeHost =
|
|
324
|
-
new DefaultReactNativeHost(this) {
|
|
325
|
-
@Override
|
|
326
|
-
protected List<ReactPackage> getPackages() {
|
|
327
|
-
return new PackageList(this).getPackages();
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
@Override
|
|
331
|
-
protected String getJSMainModuleName() {
|
|
332
|
-
return "index";
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
@Override
|
|
336
|
-
protected boolean getUseDeveloperSupport() {
|
|
337
|
-
return BuildConfig.DEBUG;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
@Override
|
|
341
|
-
protected String getJSBundleFile() {
|
|
342
|
-
return BundleDropModule.resolveJSBundleFile(getApplicationContext(), super.getJSBundleFile());
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
> **Note:** The CLI command `npx bundle-drop init` detects your template (Kotlin/Java, older/new) automatically and applies the correct patch.
|
|
348
|
-
|
|
349
|
-
## 10) Native setup (iOS)
|
|
350
|
-
|
|
351
|
-
The goal is to load the OTA bundle in **Release** (if present) and fall back to the embedded `main.jsbundle`, while keeping **Debug** on Metro.
|
|
352
|
-
|
|
353
|
-
### A) Swift (`AppDelegate.swift`)
|
|
354
|
-
|
|
355
|
-
Add the import and replace the `bundleURL()` override:
|
|
356
|
-
|
|
357
|
-
```swift
|
|
358
|
-
import BundleDrop
|
|
359
|
-
|
|
360
|
-
override func bundleURL() -> URL? {
|
|
361
|
-
#if DEBUG
|
|
362
|
-
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
|
|
363
|
-
#else
|
|
364
|
-
if let url = BundleDropLocator.bundleURL() {
|
|
365
|
-
return url
|
|
366
|
-
}
|
|
367
|
-
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
|
|
368
|
-
#endif
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
### B) Objective-C / ObjC++ (`AppDelegate.m` / `AppDelegate.mm`)
|
|
373
|
-
|
|
374
|
-
Add the import and replace the `sourceURLForBridge:` method:
|
|
375
|
-
|
|
376
|
-
```objc
|
|
377
|
-
#import <BundleDrop/BundleDrop-Swift.h>
|
|
378
|
-
|
|
379
|
-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
380
|
-
{
|
|
381
|
-
#if DEBUG
|
|
382
|
-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
|
|
383
|
-
#else
|
|
384
|
-
NSURL *otaURL = [BundleDropLocator bundleURL];
|
|
385
|
-
if (otaURL != nil) {
|
|
386
|
-
return otaURL;
|
|
387
|
-
}
|
|
388
|
-
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
389
|
-
#endif
|
|
390
|
-
}
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
> **Note:** The CLI command `npx bundle-drop init` searches `ios/` recursively for `AppDelegate.swift`, `.mm`, or `.m` and patches whichever it finds first.
|
|
394
|
-
|
|
395
|
-
## 11) Public API snapshot
|
|
396
|
-
Top-level exports:
|
|
397
|
-
- `BundleDrop.init`
|
|
398
|
-
- `BundleDrop.setChannel`
|
|
399
|
-
- `BundleDrop.getChannelName`
|
|
400
|
-
- `getAvailableChannels`, `checkForUpdate`, `getInstalledBundleInfo`
|
|
401
|
-
- `getAvailableBundles`
|
|
402
|
-
- `downloadUpdate`, `installBundle`
|
|
403
|
-
- `getUpdateState`, `applyUpdate`
|
|
404
|
-
- `useBundleDrop`
|
|
405
|
-
- `BundleDropError`, `isBundleDropError`
|
|
406
|
-
- `setUserProperty`, `setUserPropery`, `getUserProperties`, `getCurrentUserProperties`, `removeUserProperty`, `resetUserProperties`
|
|
407
|
-
|
|
408
|
-
## 12) Notes
|
|
409
|
-
- Android asset resolver patching runs automatically.
|
|
410
|
-
- `getUpdateState()` returns `{ hasBundle, info, pendingApply }`.
|
|
411
|
-
- Set `debugLocal: true` to force localhost (`10.0.2.2` on Android).
|