@vanikya/ota-react-native 0.2.8 → 0.2.9
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/android/src/main/java/com/otaupdate/OTAUpdatePackage.kt +82 -1
- package/app.plugin.js +11 -140
- package/expo-module.config.json +8 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/package.json +2 -1
- package/src/index.ts +1 -1
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
package com.otaupdate
|
|
2
2
|
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
3
5
|
import com.facebook.react.ReactPackage
|
|
4
6
|
import com.facebook.react.bridge.NativeModule
|
|
5
7
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContext
|
|
6
9
|
import com.facebook.react.uimanager.ViewManager
|
|
10
|
+
import expo.modules.core.interfaces.Package
|
|
11
|
+
import expo.modules.core.interfaces.ReactNativeHostHandler
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
/**
|
|
14
|
+
* OTAUpdatePackage implements both React Native's ReactPackage and Expo's Package interfaces.
|
|
15
|
+
*
|
|
16
|
+
* The Expo Package interface is critical for bundle loading with Expo's new architecture.
|
|
17
|
+
* It provides ReactNativeHostHandler which allows us to override:
|
|
18
|
+
* - getJSBundleFile: Returns path to downloaded OTA bundle
|
|
19
|
+
* - getBundleAssetName: Returns null when OTA bundle exists to force using getJSBundleFile
|
|
20
|
+
*/
|
|
21
|
+
class OTAUpdatePackage : ReactPackage, Package {
|
|
22
|
+
|
|
23
|
+
companion object {
|
|
24
|
+
private const val TAG = "OTAUpdatePackage"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ReactPackage implementation
|
|
9
28
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
10
29
|
return listOf(OTAUpdateModule(reactContext))
|
|
11
30
|
}
|
|
@@ -13,4 +32,66 @@ class OTAUpdatePackage : ReactPackage {
|
|
|
13
32
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
33
|
return emptyList()
|
|
15
34
|
}
|
|
35
|
+
|
|
36
|
+
// Expo Package implementation - this is the key for Expo new architecture support
|
|
37
|
+
override fun createReactNativeHostHandlers(context: Context): List<ReactNativeHostHandler> {
|
|
38
|
+
Log.d(TAG, "=== createReactNativeHostHandlers called ===")
|
|
39
|
+
|
|
40
|
+
val handler = object : ReactNativeHostHandler {
|
|
41
|
+
|
|
42
|
+
override fun getJSBundleFile(useDeveloperSupport: Boolean): String? {
|
|
43
|
+
Log.d(TAG, "=== getJSBundleFile called (useDeveloperSupport=$useDeveloperSupport) ===")
|
|
44
|
+
|
|
45
|
+
// In development mode, let Metro bundler handle it
|
|
46
|
+
if (useDeveloperSupport) {
|
|
47
|
+
Log.d(TAG, "Developer support enabled, returning null")
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Get the bundle path from OTAUpdateHelper
|
|
52
|
+
val bundlePath = OTAUpdateHelper.getJSBundleFile(context)
|
|
53
|
+
Log.d(TAG, "OTAUpdateHelper returned bundle path: $bundlePath")
|
|
54
|
+
return bundlePath
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override fun getBundleAssetName(useDeveloperSupport: Boolean): String? {
|
|
58
|
+
Log.d(TAG, "=== getBundleAssetName called (useDeveloperSupport=$useDeveloperSupport) ===")
|
|
59
|
+
|
|
60
|
+
// In development mode, use default behavior
|
|
61
|
+
if (useDeveloperSupport) {
|
|
62
|
+
Log.d(TAG, "Developer support enabled, returning null (use default)")
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Check if we have an OTA bundle
|
|
67
|
+
val bundlePath = OTAUpdateHelper.getJSBundleFile(context)
|
|
68
|
+
if (bundlePath != null) {
|
|
69
|
+
// Return null to force React Native to use getJSBundleFile instead of bundled assets
|
|
70
|
+
Log.d(TAG, "OTA bundle exists at $bundlePath, returning null to force getJSBundleFile")
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// No OTA bundle, use default bundled assets
|
|
75
|
+
Log.d(TAG, "No OTA bundle, returning null (use default bundled assets)")
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override fun onWillCreateReactInstance(useDeveloperSupport: Boolean) {
|
|
80
|
+
Log.d(TAG, "=== onWillCreateReactInstance called (useDeveloperSupport=$useDeveloperSupport) ===")
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override fun onDidCreateReactInstance(useDeveloperSupport: Boolean, reactContext: ReactContext) {
|
|
84
|
+
Log.d(TAG, "=== onDidCreateReactInstance called ===")
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
override fun onReactInstanceException(useDeveloperSupport: Boolean, exception: Exception) {
|
|
88
|
+
Log.e(TAG, "=== onReactInstanceException called ===", exception)
|
|
89
|
+
// If there's an exception with OTA bundle, we could clear it here
|
|
90
|
+
// For now, just log the exception
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Log.d(TAG, "Returning ReactNativeHostHandler")
|
|
95
|
+
return listOf(handler)
|
|
96
|
+
}
|
|
16
97
|
}
|
package/app.plugin.js
CHANGED
|
@@ -1,152 +1,23 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
1
|
+
const { withAppDelegate } = require('@expo/config-plugins');
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* OTA Update Expo Config Plugin
|
|
7
5
|
*
|
|
8
6
|
* This plugin modifies the native code to enable OTA bundle loading:
|
|
9
|
-
* - Android:
|
|
7
|
+
* - Android: Uses Expo's Package interface (ReactNativeHostHandler) - no modification needed
|
|
10
8
|
* - iOS: Modifies bundleURL() in AppDelegate.swift
|
|
9
|
+
*
|
|
10
|
+
* For Android, the OTAUpdatePackage implements expo.modules.core.interfaces.Package
|
|
11
|
+
* which provides ReactNativeHostHandler to hook into bundle loading.
|
|
12
|
+
* This is registered via expo-module.config.json.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
function withOTAUpdateAndroid(config) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.log('[OTAUpdate] Android: OTAUpdateHelper already present, skipping');
|
|
20
|
-
return config;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
console.log('[OTAUpdate] Android: Analyzing MainApplication.kt structure...');
|
|
24
|
-
|
|
25
|
-
// Add import for OTAUpdateHelper at the top
|
|
26
|
-
const packageMatch = contents.match(/^package\s+[\w.]+\s*\n/m);
|
|
27
|
-
if (packageMatch) {
|
|
28
|
-
const insertPos = packageMatch.index + packageMatch[0].length;
|
|
29
|
-
const importStatement = `\nimport com.otaupdate.OTAUpdateHelper\n`;
|
|
30
|
-
contents = contents.slice(0, insertPos) + importStatement + contents.slice(insertPos);
|
|
31
|
-
console.log('[OTAUpdate] Android: Added import for OTAUpdateHelper');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let injected = false;
|
|
35
|
-
|
|
36
|
-
// ============================================================
|
|
37
|
-
// Strategy 1: Expo New Architecture with ReactNativeHostWrapper
|
|
38
|
-
// Look for: ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost)
|
|
39
|
-
// We need to modify the reactNativeHost to include our bundle override
|
|
40
|
-
// AND add a bundleAssetName override to return null when OTA bundle exists
|
|
41
|
-
// ============================================================
|
|
42
|
-
const expoNewArchPattern = /ReactNativeHostWrapper\.createReactHost\s*\(\s*applicationContext\s*,\s*reactNativeHost\s*\)/;
|
|
43
|
-
if (expoNewArchPattern.test(contents)) {
|
|
44
|
-
console.log('[OTAUpdate] Android: Detected Expo New Architecture pattern');
|
|
45
|
-
|
|
46
|
-
// For Expo new arch, we need to add getBundleAssetName override
|
|
47
|
-
// to return null when OTA bundle exists (this forces it to use getJSBundleFile)
|
|
48
|
-
const defaultHostPattern = /(object\s*:\s*DefaultReactNativeHost\s*\([^)]*\)\s*\{)/;
|
|
49
|
-
if (defaultHostPattern.test(contents)) {
|
|
50
|
-
const bundleOverride = `
|
|
51
|
-
override fun getJSBundleFile(): String? {
|
|
52
|
-
return OTAUpdateHelper.getJSBundleFile(applicationContext)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
override fun getBundleAssetName(): String? {
|
|
56
|
-
// Return null if OTA bundle exists to force using getJSBundleFile
|
|
57
|
-
val otaBundle = OTAUpdateHelper.getJSBundleFile(applicationContext)
|
|
58
|
-
if (otaBundle != null) {
|
|
59
|
-
return null
|
|
60
|
-
}
|
|
61
|
-
return super.getBundleAssetName()
|
|
62
|
-
}
|
|
63
|
-
`;
|
|
64
|
-
contents = contents.replace(defaultHostPattern, `$1${bundleOverride}`);
|
|
65
|
-
console.log('[OTAUpdate] Android: Injected getJSBundleFile and getBundleAssetName overrides');
|
|
66
|
-
injected = true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ============================================================
|
|
71
|
-
// Strategy 2: Standard DefaultReactNativeHost pattern
|
|
72
|
-
// ============================================================
|
|
73
|
-
if (!injected) {
|
|
74
|
-
const defaultHostPattern = /(object\s*:\s*DefaultReactNativeHost\s*\([^)]*\)\s*\{)/;
|
|
75
|
-
if (defaultHostPattern.test(contents)) {
|
|
76
|
-
console.log('[OTAUpdate] Android: Detected DefaultReactNativeHost');
|
|
77
|
-
|
|
78
|
-
const bundleOverride = `
|
|
79
|
-
override fun getJSBundleFile(): String? {
|
|
80
|
-
return OTAUpdateHelper.getJSBundleFile(applicationContext)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
override fun getBundleAssetName(): String? {
|
|
84
|
-
val otaBundle = OTAUpdateHelper.getJSBundleFile(applicationContext)
|
|
85
|
-
if (otaBundle != null) {
|
|
86
|
-
return null
|
|
87
|
-
}
|
|
88
|
-
return super.getBundleAssetName()
|
|
89
|
-
}
|
|
90
|
-
`;
|
|
91
|
-
contents = contents.replace(defaultHostPattern, `$1${bundleOverride}`);
|
|
92
|
-
console.log('[OTAUpdate] Android: Injected bundle overrides');
|
|
93
|
-
injected = true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ============================================================
|
|
98
|
-
// Strategy 3: Look for getUseDeveloperSupport and insert before it
|
|
99
|
-
// ============================================================
|
|
100
|
-
if (!injected) {
|
|
101
|
-
const devSupportPattern = /([ \t]*)(override\s+fun\s+getUseDeveloperSupport\s*\(\s*\))/;
|
|
102
|
-
if (devSupportPattern.test(contents)) {
|
|
103
|
-
console.log('[OTAUpdate] Android: Found getUseDeveloperSupport, inserting before it');
|
|
104
|
-
|
|
105
|
-
const match = contents.match(devSupportPattern);
|
|
106
|
-
const indent = match ? match[1] : ' ';
|
|
107
|
-
|
|
108
|
-
const bundleOverride = `${indent}override fun getJSBundleFile(): String? {
|
|
109
|
-
${indent} return OTAUpdateHelper.getJSBundleFile(applicationContext)
|
|
110
|
-
${indent}}
|
|
111
|
-
|
|
112
|
-
${indent}override fun getBundleAssetName(): String? {
|
|
113
|
-
${indent} val otaBundle = OTAUpdateHelper.getJSBundleFile(applicationContext)
|
|
114
|
-
${indent} if (otaBundle != null) {
|
|
115
|
-
${indent} return null
|
|
116
|
-
${indent} }
|
|
117
|
-
${indent} return super.getBundleAssetName()
|
|
118
|
-
${indent}}
|
|
119
|
-
|
|
120
|
-
${indent}`;
|
|
121
|
-
|
|
122
|
-
contents = contents.replace(devSupportPattern, `${bundleOverride}$2`);
|
|
123
|
-
console.log('[OTAUpdate] Android: Injected bundle overrides before getUseDeveloperSupport');
|
|
124
|
-
injected = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!injected) {
|
|
129
|
-
console.warn('[OTAUpdate] Android: ⚠️ Could not find injection point!');
|
|
130
|
-
console.warn('[OTAUpdate] Android: Please manually add getJSBundleFile override');
|
|
131
|
-
|
|
132
|
-
// Log relevant lines for debugging
|
|
133
|
-
const lines = contents.split('\n');
|
|
134
|
-
console.log('[OTAUpdate] Android: Relevant lines in MainApplication.kt:');
|
|
135
|
-
lines.forEach((line, i) => {
|
|
136
|
-
if (line.includes('ReactNativeHost') ||
|
|
137
|
-
line.includes('DefaultReactNativeHost') ||
|
|
138
|
-
line.includes('getDefaultReactHost') ||
|
|
139
|
-
line.includes('reactHost') ||
|
|
140
|
-
line.includes('getJSBundleFile') ||
|
|
141
|
-
line.includes('jsBundleFilePath')) {
|
|
142
|
-
console.log(` ${i + 1}: ${line.trim()}`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
config.modResults.contents = contents;
|
|
148
|
-
return config;
|
|
149
|
-
});
|
|
16
|
+
// Android bundle loading is handled by OTAUpdatePackage implementing
|
|
17
|
+
// expo.modules.core.interfaces.Package with ReactNativeHostHandler.
|
|
18
|
+
// No MainApplication.kt modification is needed for Expo apps.
|
|
19
|
+
console.log('[OTAUpdate] Android: Using Expo Package interface for bundle loading');
|
|
20
|
+
return config;
|
|
150
21
|
}
|
|
151
22
|
|
|
152
23
|
function withOTAUpdateIOS(config) {
|
package/lib/commonjs/index.js
CHANGED
package/lib/module/index.js
CHANGED
|
@@ -10,5 +10,5 @@ export { OTAApiClient, getDeviceInfo } from './utils/api';
|
|
|
10
10
|
export { UpdateStorage, getStorageAdapter } from './utils/storage';
|
|
11
11
|
export { calculateHash, verifyBundleHash, verifySignature, verifyBundle } from './utils/verification';
|
|
12
12
|
// Version info
|
|
13
|
-
export const VERSION = '0.2.
|
|
13
|
+
export const VERSION = '0.2.9';
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -9,5 +9,5 @@ export { UpdateStorage, getStorageAdapter } from './utils/storage';
|
|
|
9
9
|
export type { StoredUpdate, StorageAdapter } from './utils/storage';
|
|
10
10
|
export { calculateHash, verifyBundleHash, verifySignature, verifyBundle, } from './utils/verification';
|
|
11
11
|
export type { VerificationResult } from './utils/verification';
|
|
12
|
-
export declare const VERSION = "0.2.
|
|
12
|
+
export declare const VERSION = "0.2.9";
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanikya/ota-react-native",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "OTA Update SDK for React Native apps - self-hosted CodePush/EAS Updates alternative",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"*.podspec",
|
|
16
16
|
"react-native.config.js",
|
|
17
17
|
"app.plugin.js",
|
|
18
|
+
"expo-module.config.json",
|
|
18
19
|
"README.md"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
package/src/index.ts
CHANGED