@gfean/react-native-bundle-drop 0.2.2 → 0.3.3
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 +2 -1
- package/LICENSE +15 -0
- package/README.md +122 -238
- package/lib/CLI/cli.d.ts +2 -1
- package/lib/CLI/cli.js +154 -131
- package/lib/CLI/scripts/init-config.js +12 -5
- package/lib/CLI/scripts/init-native-config.d.ts +16 -0
- package/lib/CLI/scripts/init-native-config.js +28 -9
- package/lib/CLI/scripts/login-cli.d.ts +71 -0
- package/lib/CLI/scripts/login-cli.js +24 -13
- package/lib/CLI/scripts/post-init.js +9 -3
- package/lib/CLI/scripts/upload-cli.js +14 -7
- package/lib/api/types.d.ts +29 -0
- package/lib/index.d.ts +16 -4
- package/lib/index.js +25 -15
- package/lib/manager/downloadAndInstall.d.ts +2 -0
- package/lib/manager/reporting.js +3 -0
- package/lib/manager/updateCheck.d.ts +13 -0
- package/lib/manager/updateCheck.js +6 -0
- package/lib/manager/updateState.d.ts +2 -0
- package/lib/manager/updateState.js +10 -4
- package/lib/runtime/initState.d.ts +48 -0
- package/lib/runtime/initState.js +131 -0
- package/lib/runtime/service.d.ts +111 -0
- package/lib/runtime/service.js +537 -0
- package/lib/scripts/bundle.d.ts +13 -1
- package/lib/scripts/bundle.js +126 -115
- package/lib/scripts/download-bundle.d.ts +4 -1
- package/lib/scripts/download-bundle.js +41 -33
- package/lib/scripts/upload-bundle.d.ts +7 -1
- package/lib/scripts/upload-bundle.js +183 -175
- package/lib/useBundleDrop.d.ts +19 -9
- package/lib/useBundleDrop.js +26 -172
- package/package.json +59 -8
- package/CLIENT_README.md +0 -381
- package/lib/manager/initUpdateManager.d.ts +0 -10
- package/lib/manager/initUpdateManager.js +0 -137
package/package.json
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfean/react-native-bundle-drop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"nativeVersion": "0.3.2",
|
|
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,9 +29,18 @@
|
|
|
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
|
-
"build": "tsc -p tsconfig.json && node scripts/make-cli-executable.js",
|
|
38
|
+
"build": "tsc -p tsconfig.build.json && node scripts/make-cli-executable.js",
|
|
39
|
+
"prepare": "husky",
|
|
40
|
+
"test": "jest --runInBand",
|
|
41
|
+
"test:coverage": "jest --runInBand --coverage",
|
|
42
|
+
"coverage:check": "node scripts/check-coverage-thresholds.cjs",
|
|
43
|
+
"coverage:gate": "yarn test:coverage && yarn coverage:check",
|
|
24
44
|
"prepublishOnly": "yarn clean && yarn build",
|
|
25
45
|
"build-and-publish": "yarn clean && yarn build && npm publish --access=restricted",
|
|
26
46
|
"publish:local": "yalc publish --private"
|
|
@@ -31,10 +51,16 @@
|
|
|
31
51
|
"version": "0.49.6"
|
|
32
52
|
},
|
|
33
53
|
"devDependencies": {
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
34
55
|
"@types/node": "^24.10.1",
|
|
35
56
|
"@types/react": "^18.2.66",
|
|
36
57
|
"@types/react-native": "^0.73.0",
|
|
58
|
+
"husky": "^9.1.7",
|
|
59
|
+
"jest": "^29.7.0",
|
|
60
|
+
"react": "^18.3.1",
|
|
61
|
+
"react-test-renderer": "^18.3.1",
|
|
37
62
|
"rimraf": "^6.0.1",
|
|
63
|
+
"ts-jest": "^29.4.4",
|
|
38
64
|
"ts-node": "^10.9.2",
|
|
39
65
|
"typescript": "^5.8.3"
|
|
40
66
|
},
|
|
@@ -52,9 +78,34 @@
|
|
|
52
78
|
"ios/*.{m,h,mm,swift}",
|
|
53
79
|
"BundleDrop.podspec",
|
|
54
80
|
"react-native.config.js",
|
|
55
|
-
"README.md"
|
|
56
|
-
|
|
81
|
+
"README.md"
|
|
82
|
+
],
|
|
83
|
+
"keywords": [
|
|
84
|
+
"react-native",
|
|
85
|
+
"react-native-ota",
|
|
86
|
+
"ota-updates",
|
|
87
|
+
"over-the-air",
|
|
88
|
+
"react-native-update",
|
|
89
|
+
"react-native-updates",
|
|
90
|
+
"bundle-updates",
|
|
91
|
+
"hot-update",
|
|
92
|
+
"codepush-alternative",
|
|
93
|
+
"expo-eas-update-alternative",
|
|
94
|
+
"react-native-deployment",
|
|
95
|
+
"mobile-updates",
|
|
96
|
+
"app-updates",
|
|
97
|
+
"live-updates",
|
|
98
|
+
"feature-rollout",
|
|
99
|
+
"staged-rollout",
|
|
100
|
+
"rollback",
|
|
101
|
+
"react-native-ci",
|
|
102
|
+
"react-native-release",
|
|
103
|
+
"react-native-production"
|
|
57
104
|
],
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"react": ">=17.0.0",
|
|
107
|
+
"react-native": ">=0.71.0"
|
|
108
|
+
},
|
|
58
109
|
"dependencies": {
|
|
59
110
|
"adm-zip": "^0.5.16",
|
|
60
111
|
"archiver": "^7.0.1",
|
package/CLIENT_README.md
DELETED
|
@@ -1,381 +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 (optional auto mode):
|
|
53
|
-
```ts
|
|
54
|
-
import { useEffect } from 'react';
|
|
55
|
-
import { initUpdateManager } from '@gfean/react-native-bundle-drop';
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
initUpdateManager({
|
|
59
|
-
policy: __DEV__ ? 'manual' : 'on-next-launch', // or 'immediate'
|
|
60
|
-
channelName: 'General',
|
|
61
|
-
onStatusUpdate: msg => console.log('[OTA]', msg),
|
|
62
|
-
});
|
|
63
|
-
}, []);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Manual UI example:
|
|
67
|
-
```ts
|
|
68
|
-
import { useBundleDrop } from '@gfean/react-native-bundle-drop';
|
|
69
|
-
|
|
70
|
-
const {
|
|
71
|
-
status,
|
|
72
|
-
isBusy,
|
|
73
|
-
installedInfo,
|
|
74
|
-
pendingApply,
|
|
75
|
-
checkLatest,
|
|
76
|
-
downloadUpdate,
|
|
77
|
-
applyUpdate,
|
|
78
|
-
fetchAvailableChannels,
|
|
79
|
-
availableChannels,
|
|
80
|
-
} = useBundleDrop({ channelName: 'General' });
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Quick check-only pattern:
|
|
84
|
-
```ts
|
|
85
|
-
const { checkLatest, status } = useBundleDrop({ channelName: 'General' });
|
|
86
|
-
await checkLatest();
|
|
87
|
-
console.log(status);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## 4) Policies
|
|
91
|
-
- `manual`: no auto download/apply.
|
|
92
|
-
- `immediate`: download, stage, then apply immediately.
|
|
93
|
-
- `on-next-launch`: download and stage now; apply on next launch.
|
|
94
|
-
|
|
95
|
-
## 5) Channels
|
|
96
|
-
- Keep channel names stable: `General`, `Beta`, `QA`.
|
|
97
|
-
- Use the same `channelName` in app runtime and in upload CLI.
|
|
98
|
-
- `fetchAvailableChannels()` retrieves available public channels for the configured project.
|
|
99
|
-
|
|
100
|
-
## 6) Compatibility (`runtimeVersion`)
|
|
101
|
-
- Define `runtimeVersion` per platform in `bundle.drop.config.js`.
|
|
102
|
-
- Upload embeds `runtimeVersion` in metadata.
|
|
103
|
-
- Client sends `runtimeVersion` during OTA resolve.
|
|
104
|
-
|
|
105
|
-
## 7) Targeted rollout (`currentUserProperties`)
|
|
106
|
-
Use user properties to target cohorts from backend rollout rules.
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
import {
|
|
110
|
-
setUserProperty,
|
|
111
|
-
setUserPropery,
|
|
112
|
-
getUserProperties,
|
|
113
|
-
getCurrentUserProperties,
|
|
114
|
-
removeUserProperty,
|
|
115
|
-
resetUserProperties,
|
|
116
|
-
} from '@gfean/react-native-bundle-drop';
|
|
117
|
-
|
|
118
|
-
await setUserProperty('QA Analyst');
|
|
119
|
-
await setUserProperty('Beta Tester');
|
|
120
|
-
await setUserPropery('QA Analyst'); // alias + duplicate ignored
|
|
121
|
-
|
|
122
|
-
const propsA = await getUserProperties();
|
|
123
|
-
const propsB = await getCurrentUserProperties();
|
|
124
|
-
|
|
125
|
-
await removeUserProperty('Beta Tester');
|
|
126
|
-
await resetUserProperties();
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Behavior:
|
|
130
|
-
- Values are trimmed.
|
|
131
|
-
- Duplicates are ignored.
|
|
132
|
-
- Stored locally in `bundle-drop/user-properties.json`.
|
|
133
|
-
- Sent automatically as `currentUserProperties` during OTA resolve checks.
|
|
134
|
-
|
|
135
|
-
## 8) Bundling/upload (CI/local)
|
|
136
|
-
- Login (interactive, for local development):
|
|
137
|
-
```bash
|
|
138
|
-
npx bundle-drop login
|
|
139
|
-
```
|
|
140
|
-
- Upload Android:
|
|
141
|
-
```bash
|
|
142
|
-
npx bundle-drop upload android --version 1.2.3 --channel General
|
|
143
|
-
# or --buildgradle-path android/app/build.gradle
|
|
144
|
-
```
|
|
145
|
-
- Upload iOS:
|
|
146
|
-
```bash
|
|
147
|
-
npx bundle-drop upload ios --plist-file ios/Info.plist --channel General
|
|
148
|
-
# or --version 1.2.3
|
|
149
|
-
```
|
|
150
|
-
- Optional upload flags:
|
|
151
|
-
- `--runtimeVersion x.y.z` — override runtime version
|
|
152
|
-
- `--release-notes "text"` — attach release notes (max 2000 chars)
|
|
153
|
-
- `--token <pat>` — authenticate with a Personal Access Token (skips `bundle-drop login`; ideal for CI/CD)
|
|
154
|
-
- `--author <name>` — override the author name stored with the bundle
|
|
155
|
-
|
|
156
|
-
### CI/CD example
|
|
157
|
-
```bash
|
|
158
|
-
npx bundle-drop upload android \
|
|
159
|
-
--version 1.2.3 \
|
|
160
|
-
--channel General \
|
|
161
|
-
--token $BUNDLE_DROP_PAT \
|
|
162
|
-
--author "CI Pipeline"
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Upload result file
|
|
166
|
-
|
|
167
|
-
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:
|
|
168
|
-
|
|
169
|
-
```json
|
|
170
|
-
{
|
|
171
|
-
"platform": "android",
|
|
172
|
-
"appVersion": "1.2.3",
|
|
173
|
-
"channel": "General",
|
|
174
|
-
"orgSlug": "my-org",
|
|
175
|
-
"projectSlug": "my-app",
|
|
176
|
-
"runtimeVersion": "1.0.0",
|
|
177
|
-
"bundleId": "abc123",
|
|
178
|
-
"bundleVersion": 42,
|
|
179
|
-
"bundleVersionLabel": "v42",
|
|
180
|
-
"hash": "sha256hex...",
|
|
181
|
-
"releaseNotes": "Bug fixes",
|
|
182
|
-
"author": "CI Pipeline"
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Use this in CI to read any field — no output parsing needed:
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
BD_RESULT="node_modules/@gfean/react-native-bundle-drop/dist/bundle-drop-result.json"
|
|
190
|
-
|
|
191
|
-
# Read any field
|
|
192
|
-
jq -r '.bundleVersionLabel' "$BD_RESULT"
|
|
193
|
-
jq -r '.appVersion' "$BD_RESULT"
|
|
194
|
-
jq -r '.channel' "$BD_RESULT"
|
|
195
|
-
|
|
196
|
-
# Azure DevOps
|
|
197
|
-
echo "##vso[task.setvariable variable=BundleVersion]$(jq -r '.bundleVersionLabel' "$BD_RESULT")"
|
|
198
|
-
|
|
199
|
-
# GitHub Actions
|
|
200
|
-
echo "bundle_version=$(jq -r '.bundleVersionLabel' "$BD_RESULT")" >> "$GITHUB_OUTPUT"
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## 9) Native setup (Android)
|
|
204
|
-
|
|
205
|
-
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.
|
|
206
|
-
|
|
207
|
-
Kotlin:
|
|
208
|
-
```kt
|
|
209
|
-
override fun getJSBundleFile(): String? =
|
|
210
|
-
BundleDropModule.resolveJSBundleFile(applicationContext, super.getJSBundleFile())
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
Java:
|
|
214
|
-
```java
|
|
215
|
-
@Override
|
|
216
|
-
protected String getJSBundleFile() {
|
|
217
|
-
return BundleDropModule.resolveJSBundleFile(getApplicationContext(), super.getJSBundleFile());
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### A) Kotlin — older RN template (has `reactNativeHost`)
|
|
222
|
-
|
|
223
|
-
If your `MainApplication.kt` already has a `reactNativeHost` block, add the import and the one-liner inside it:
|
|
224
|
-
|
|
225
|
-
```kt
|
|
226
|
-
import com.bundledrop.BundleDropModule
|
|
227
|
-
|
|
228
|
-
// inside your existing reactNativeHost object:
|
|
229
|
-
override fun getJSBundleFile(): String? =
|
|
230
|
-
BundleDropModule.resolveJSBundleFile(applicationContext, super.getJSBundleFile())
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### B) Kotlin — RN 0.84+ template (ReactHost, no `reactNativeHost`)
|
|
234
|
-
|
|
235
|
-
RN 0.84+ templates use `ReactHost` but don't expose `reactNativeHost`. BundleDrop needs `ReactNativeHost.getJSBundleFile()`, so you reintroduce `reactNativeHost` and wire `reactHost` from it.
|
|
236
|
-
|
|
237
|
-
1. Add imports (only if missing):
|
|
238
|
-
```kt
|
|
239
|
-
import com.bundledrop.BundleDropModule
|
|
240
|
-
import com.facebook.react.ReactHost
|
|
241
|
-
import com.facebook.react.ReactNativeHost
|
|
242
|
-
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
|
243
|
-
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
|
244
|
-
import com.facebook.react.defaults.DefaultReactNativeHost
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
2. Add `reactNativeHost` property (before `reactHost`):
|
|
248
|
-
```kt
|
|
249
|
-
override val reactNativeHost: ReactNativeHost =
|
|
250
|
-
object : DefaultReactNativeHost(this) {
|
|
251
|
-
|
|
252
|
-
override fun getPackages() = PackageList(this).packages
|
|
253
|
-
override fun getJSMainModuleName(): String = "index"
|
|
254
|
-
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
|
|
255
|
-
|
|
256
|
-
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
257
|
-
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
258
|
-
|
|
259
|
-
override fun getJSBundleFile(): String? =
|
|
260
|
-
BundleDropModule.resolveJSBundleFile(applicationContext, super.getJSBundleFile())
|
|
261
|
-
}
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
3. Ensure `reactHost` is created from `reactNativeHost`:
|
|
265
|
-
```kt
|
|
266
|
-
override val reactHost: ReactHost by lazy {
|
|
267
|
-
getDefaultReactHost(
|
|
268
|
-
context = applicationContext,
|
|
269
|
-
reactNativeHost = reactNativeHost
|
|
270
|
-
)
|
|
271
|
-
}
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
4. Ensure `onCreate()` calls:
|
|
275
|
-
```kt
|
|
276
|
-
loadReactNative(this)
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### C) Java — older RN template (`MainApplication.java`)
|
|
280
|
-
|
|
281
|
-
Older React Native versions used Java instead of Kotlin. Add the import and the override inside your `ReactNativeHost` anonymous class:
|
|
282
|
-
|
|
283
|
-
```java
|
|
284
|
-
import com.bundledrop.BundleDropModule;
|
|
285
|
-
|
|
286
|
-
// inside your ReactNativeHost (or DefaultReactNativeHost) anonymous class:
|
|
287
|
-
@Override
|
|
288
|
-
protected String getJSBundleFile() {
|
|
289
|
-
return BundleDropModule.resolveJSBundleFile(getApplicationContext(), super.getJSBundleFile());
|
|
290
|
-
}
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
Full example context:
|
|
294
|
-
|
|
295
|
-
```java
|
|
296
|
-
private final ReactNativeHost mReactNativeHost =
|
|
297
|
-
new DefaultReactNativeHost(this) {
|
|
298
|
-
@Override
|
|
299
|
-
protected List<ReactPackage> getPackages() {
|
|
300
|
-
return new PackageList(this).getPackages();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
@Override
|
|
304
|
-
protected String getJSMainModuleName() {
|
|
305
|
-
return "index";
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
@Override
|
|
309
|
-
protected boolean getUseDeveloperSupport() {
|
|
310
|
-
return BuildConfig.DEBUG;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
@Override
|
|
314
|
-
protected String getJSBundleFile() {
|
|
315
|
-
return BundleDropModule.resolveJSBundleFile(getApplicationContext(), super.getJSBundleFile());
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
> **Note:** The CLI command `npx bundle-drop init` detects your template (Kotlin/Java, older/new) automatically and applies the correct patch.
|
|
321
|
-
|
|
322
|
-
## 10) Native setup (iOS)
|
|
323
|
-
|
|
324
|
-
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.
|
|
325
|
-
|
|
326
|
-
### A) Swift (`AppDelegate.swift`)
|
|
327
|
-
|
|
328
|
-
Add the import and replace the `bundleURL()` override:
|
|
329
|
-
|
|
330
|
-
```swift
|
|
331
|
-
import BundleDrop
|
|
332
|
-
|
|
333
|
-
override func bundleURL() -> URL? {
|
|
334
|
-
#if DEBUG
|
|
335
|
-
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
|
|
336
|
-
#else
|
|
337
|
-
if let url = BundleDropLocator.bundleURL() {
|
|
338
|
-
return url
|
|
339
|
-
}
|
|
340
|
-
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
|
|
341
|
-
#endif
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
### B) Objective-C / ObjC++ (`AppDelegate.m` / `AppDelegate.mm`)
|
|
346
|
-
|
|
347
|
-
Add the import and replace the `sourceURLForBridge:` method:
|
|
348
|
-
|
|
349
|
-
```objc
|
|
350
|
-
#import <BundleDrop/BundleDrop-Swift.h>
|
|
351
|
-
|
|
352
|
-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
353
|
-
{
|
|
354
|
-
#if DEBUG
|
|
355
|
-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
|
|
356
|
-
#else
|
|
357
|
-
NSURL *otaURL = [BundleDropLocator bundleURL];
|
|
358
|
-
if (otaURL != nil) {
|
|
359
|
-
return otaURL;
|
|
360
|
-
}
|
|
361
|
-
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
362
|
-
#endif
|
|
363
|
-
}
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
> **Note:** The CLI command `npx bundle-drop init` searches `ios/` recursively for `AppDelegate.swift`, `.mm`, or `.m` and patches whichever it finds first.
|
|
367
|
-
|
|
368
|
-
## 11) Public API snapshot
|
|
369
|
-
Top-level exports:
|
|
370
|
-
- `getAvailableChannels`, `checkForUpdate`, `getInstalledBundleInfo`
|
|
371
|
-
- `downloadUpdate`
|
|
372
|
-
- `getUpdateState`, `applyUpdate`
|
|
373
|
-
- `initUpdateManager`
|
|
374
|
-
- `useBundleDrop`
|
|
375
|
-
- `BundleDropError`, `isBundleDropError`
|
|
376
|
-
- `setUserProperty`, `setUserPropery`, `getUserProperties`, `getCurrentUserProperties`, `removeUserProperty`, `resetUserProperties`
|
|
377
|
-
|
|
378
|
-
## 12) Notes
|
|
379
|
-
- Android asset resolver patching runs automatically.
|
|
380
|
-
- `getUpdateState()` returns `{ hasBundle, info, pendingApply }`.
|
|
381
|
-
- Set `debugLocal: true` to force localhost (`10.0.2.2` on Android).
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UpdatePolicy } from '../types';
|
|
2
|
-
export declare function isUpdateFlowActive(): boolean;
|
|
3
|
-
export declare function acquireUpdateLock(): boolean;
|
|
4
|
-
export declare function releaseUpdateLock(): void;
|
|
5
|
-
export declare function initUpdateManager(opts?: {
|
|
6
|
-
channelName?: string;
|
|
7
|
-
policy?: UpdatePolicy;
|
|
8
|
-
onStatusUpdate?: (status: string) => void;
|
|
9
|
-
checkOnly?: boolean;
|
|
10
|
-
}): Promise<void>;
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUpdateFlowActive = isUpdateFlowActive;
|
|
4
|
-
exports.acquireUpdateLock = acquireUpdateLock;
|
|
5
|
-
exports.releaseUpdateLock = releaseUpdateLock;
|
|
6
|
-
exports.initUpdateManager = initUpdateManager;
|
|
7
|
-
const downloadAndInstall_1 = require("./downloadAndInstall");
|
|
8
|
-
const updateCheck_1 = require("./updateCheck");
|
|
9
|
-
const updateState_1 = require("./updateState");
|
|
10
|
-
const rollbackState_1 = require("./rollbackState");
|
|
11
|
-
const bundleInfo_1 = require("../bundleInfo");
|
|
12
|
-
const context_1 = require("../context");
|
|
13
|
-
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
14
|
-
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
15
|
-
let _updateFlowActive = false;
|
|
16
|
-
function isUpdateFlowActive() {
|
|
17
|
-
return _updateFlowActive;
|
|
18
|
-
}
|
|
19
|
-
function acquireUpdateLock() {
|
|
20
|
-
if (_updateFlowActive)
|
|
21
|
-
return false;
|
|
22
|
-
_updateFlowActive = true;
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
function releaseUpdateLock() {
|
|
26
|
-
_updateFlowActive = false;
|
|
27
|
-
}
|
|
28
|
-
async function initUpdateManager(opts) {
|
|
29
|
-
if (!acquireUpdateLock())
|
|
30
|
-
return;
|
|
31
|
-
try {
|
|
32
|
-
await _initUpdateManagerInner(opts);
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
releaseUpdateLock();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function _initUpdateManagerInner(opts) {
|
|
39
|
-
const policy = opts?.policy || 'manual';
|
|
40
|
-
const channelName = opts?.channelName || context_1.defaultChannel;
|
|
41
|
-
const statusCb = opts?.onStatusUpdate;
|
|
42
|
-
// Prefetch all startup data in parallel (single bridge round-trip instead of
|
|
43
|
-
// 8+ sequential reads across reconcile / rollback / commit / getUpdateState).
|
|
44
|
-
const [bundleInfo, bundlePath, currentPointer, rollbackStateData] = await Promise.all([
|
|
45
|
-
(0, bundleInfo_1.readBundleInfo)(),
|
|
46
|
-
(0, bundleDropNative_1.getDownloadedBundlePathNative)(),
|
|
47
|
-
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
48
|
-
(0, rollbackState_1.readRollbackState)(),
|
|
49
|
-
]);
|
|
50
|
-
await (0, updateState_1.reconcileAppliedBundleOnLaunch)({ bundleInfo, bundlePath });
|
|
51
|
-
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
52
|
-
const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
|
|
53
|
-
currentPointer,
|
|
54
|
-
rollbackState: rollbackStateData,
|
|
55
|
-
});
|
|
56
|
-
if (rollbackResult.rolledBack) {
|
|
57
|
-
statusCb?.('↩️ Rolled back to previous bundle');
|
|
58
|
-
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
await (0, rollbackState_1.commitActiveBundle)({ currentPointer });
|
|
62
|
-
// bundlePath hasn't changed; let bundleInfo re-read (reconcile may have updated it).
|
|
63
|
-
const pendingState = await (0, updateState_1.getUpdateState)({ bundlePath });
|
|
64
|
-
if (pendingState.pendingApply) {
|
|
65
|
-
if (policy === 'immediate') {
|
|
66
|
-
statusCb?.('♻️ Applying previously downloaded update...');
|
|
67
|
-
const applyResult = await (0, updateState_1.applyUpdate)(statusCb);
|
|
68
|
-
if (applyResult.status === 'applied')
|
|
69
|
-
return;
|
|
70
|
-
// 'alreadyApplied' or 'noBundle' — fall through to checkForUpdate
|
|
71
|
-
}
|
|
72
|
-
if (policy === 'on-next-launch') {
|
|
73
|
-
statusCb?.('✅ Update downloaded; will apply on next launch.');
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// Resolve server decision once (covers INSTALL, ROLLBACK, NOOP).
|
|
78
|
-
const decision = await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
|
|
79
|
-
if (!decision) {
|
|
80
|
-
statusCb?.('⚠️ Unable to check for updates. Try again.');
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (decision.action === 'ROLLBACK') {
|
|
84
|
-
statusCb?.('↩️ Server requested rollback...');
|
|
85
|
-
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
86
|
-
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (decision.action === 'NOOP') {
|
|
90
|
-
if (decision.incompatible) {
|
|
91
|
-
statusCb?.('⛔️ No compatible update for this binary');
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (opts?.checkOnly)
|
|
95
|
-
statusCb?.('✅ You have the latest version');
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// INSTALL available
|
|
99
|
-
if (policy === 'manual') {
|
|
100
|
-
// Check-only mode is already handled by checkForUpdate status updates; no auto download/apply.
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const resolvedTarget = decision.downloadUrl && decision.hash
|
|
104
|
-
? {
|
|
105
|
-
hash: decision.hash,
|
|
106
|
-
downloadUrl: decision.downloadUrl,
|
|
107
|
-
bundleVersion: decision.bundleVersion,
|
|
108
|
-
version: decision.version,
|
|
109
|
-
runtimeVersion: decision.runtimeVersion,
|
|
110
|
-
}
|
|
111
|
-
: undefined;
|
|
112
|
-
if (!resolvedTarget) {
|
|
113
|
-
statusCb?.('⚠️ Update available but missing download URL');
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (policy === 'on-next-launch') {
|
|
117
|
-
const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName, resolvedTarget }, statusCb || (() => { }));
|
|
118
|
-
if (res.status === 'staged')
|
|
119
|
-
statusCb?.('✅ Update downloaded for next launch');
|
|
120
|
-
if (res.status === 'upToDate')
|
|
121
|
-
statusCb?.('✅ You have the latest version');
|
|
122
|
-
if (res.status === 'incompatible')
|
|
123
|
-
statusCb?.('⛔️ No compatible update for this binary');
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
// immediate
|
|
127
|
-
const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName, resolvedTarget }, statusCb || (() => { }));
|
|
128
|
-
if (res.status === 'staged') {
|
|
129
|
-
await (0, updateState_1.applyUpdate)(statusCb);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (res.status === 'upToDate')
|
|
133
|
-
statusCb?.('✅ You have the latest version');
|
|
134
|
-
if (res.status === 'incompatible')
|
|
135
|
-
statusCb?.('⛔️ No compatible update for this binary');
|
|
136
|
-
return;
|
|
137
|
-
}
|