@hot-updater/react-native 0.21.12 → 0.21.13
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/package.json +8 -8
- package/plugin/build/withHotUpdater.js +4 -127
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/react-native",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.13",
|
|
4
4
|
"description": "React Native OTA solution for self-hosted",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -119,18 +119,18 @@
|
|
|
119
119
|
"react-native": "0.79.1",
|
|
120
120
|
"react-native-builder-bob": "^0.40.10",
|
|
121
121
|
"typescript": "^5.8.3",
|
|
122
|
-
"hot-updater": "0.21.
|
|
122
|
+
"hot-updater": "0.21.13"
|
|
123
123
|
},
|
|
124
124
|
"dependencies": {
|
|
125
125
|
"use-sync-external-store": "1.5.0",
|
|
126
|
-
"@hot-updater/cli-tools": "0.21.
|
|
127
|
-
"@hot-updater/core": "0.21.
|
|
128
|
-
"@hot-updater/js": "0.21.
|
|
129
|
-
"@hot-updater/plugin-core": "0.21.
|
|
126
|
+
"@hot-updater/cli-tools": "0.21.13",
|
|
127
|
+
"@hot-updater/core": "0.21.13",
|
|
128
|
+
"@hot-updater/js": "0.21.13",
|
|
129
|
+
"@hot-updater/plugin-core": "0.21.13"
|
|
130
130
|
},
|
|
131
131
|
"scripts": {
|
|
132
|
-
"build": "bob build && tsc -p plugin/tsconfig.json",
|
|
133
|
-
"build:plugin": "tsc -p plugin/tsconfig.json",
|
|
132
|
+
"build": "bob build && tsc -p plugin/tsconfig.build.json",
|
|
133
|
+
"build:plugin": "tsc -p plugin/tsconfig.build.json",
|
|
134
134
|
"test:type": "tsc --noEmit",
|
|
135
135
|
"test": "vitest",
|
|
136
136
|
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
@@ -43,6 +43,7 @@ var cli_tools_1 = require("@hot-updater/cli-tools");
|
|
|
43
43
|
var config_plugins_1 = require("expo/config-plugins");
|
|
44
44
|
var hot_updater_1 = require("hot-updater");
|
|
45
45
|
var package_json_1 = __importDefault(require("../../package.json"));
|
|
46
|
+
var transformers_1 = require("./transformers");
|
|
46
47
|
var fingerprintCache = null;
|
|
47
48
|
var getFingerprint = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
49
|
return __generator(this, function (_a) {
|
|
@@ -61,35 +62,6 @@ var getFingerprint = function () { return __awaiter(void 0, void 0, void 0, func
|
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
}); };
|
|
64
|
-
/**
|
|
65
|
-
* Helper to add lines if they don't exist, anchored by a specific string.
|
|
66
|
-
*/
|
|
67
|
-
function addLinesOnce(contents, anchor, linesToAdd) {
|
|
68
|
-
if (linesToAdd.every(function (line) { return contents.includes(line); })) {
|
|
69
|
-
// All lines already exist, do nothing
|
|
70
|
-
return contents;
|
|
71
|
-
}
|
|
72
|
-
// Check if the anchor exists
|
|
73
|
-
if (!contents.includes(anchor)) {
|
|
74
|
-
// Anchor not found, cannot add lines reliably.
|
|
75
|
-
// Consider logging a warning or throwing an error here if necessary.
|
|
76
|
-
return contents;
|
|
77
|
-
}
|
|
78
|
-
// Add lines after the anchor
|
|
79
|
-
// Ensure newline separation
|
|
80
|
-
return contents.replace(anchor, "".concat(anchor, "\n").concat(linesToAdd.join("\n")));
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Helper to replace content only if the target content exists and hasn't been replaced yet.
|
|
84
|
-
*/
|
|
85
|
-
function replaceContentOnce(contents, searchRegex, replacement, checkIfAlreadyReplaced) {
|
|
86
|
-
// If the replacement content is already present, assume it's done.
|
|
87
|
-
if (contents.includes(checkIfAlreadyReplaced)) {
|
|
88
|
-
return contents;
|
|
89
|
-
}
|
|
90
|
-
// Otherwise, perform the replacement if the search target exists.
|
|
91
|
-
return contents.replace(searchRegex, replacement);
|
|
92
|
-
}
|
|
93
65
|
/**
|
|
94
66
|
* Native code modifications - should only run once
|
|
95
67
|
*/
|
|
@@ -98,109 +70,14 @@ var withHotUpdaterNativeCode = function (config) {
|
|
|
98
70
|
// === iOS: Objective-C & Swift in AppDelegate ===
|
|
99
71
|
modifiedConfig = (0, config_plugins_1.withAppDelegate)(modifiedConfig, function (cfg) {
|
|
100
72
|
var contents = cfg.modResults.contents;
|
|
101
|
-
|
|
102
|
-
var iosBundleUrl = "[HotUpdater bundleURL]";
|
|
103
|
-
var iosOriginalBundleUrlRegex = /\[\[NSBundle mainBundle\] URLForResource:@"main" withExtension:@"jsbundle"\]/g;
|
|
104
|
-
var iosAppDelegateHeader = '#import "AppDelegate.h"'; // Anchor for import
|
|
105
|
-
var swiftImport = "import HotUpdater";
|
|
106
|
-
var swiftBundleUrl = "HotUpdater.bundleURL()";
|
|
107
|
-
var swiftOriginalBundleUrlRegex = /Bundle\.main\.url\(forResource: "?main"?, withExtension: "jsbundle"\)/g;
|
|
108
|
-
var swiftReactImport = "import React"; // Anchor for import
|
|
109
|
-
// --- Objective-C ---
|
|
110
|
-
if (contents.includes(iosAppDelegateHeader)) {
|
|
111
|
-
// Check if it's likely Obj-C
|
|
112
|
-
// 1. Add import if missing
|
|
113
|
-
contents = addLinesOnce(contents, iosAppDelegateHeader, [iosImport]);
|
|
114
|
-
// 2. Replace bundleURL provider if the original exists and hasn't been replaced
|
|
115
|
-
contents = replaceContentOnce(contents, iosOriginalBundleUrlRegex, iosBundleUrl, iosBundleUrl);
|
|
116
|
-
}
|
|
117
|
-
// --- Swift ---
|
|
118
|
-
if (contents.includes(swiftReactImport)) {
|
|
119
|
-
// Check if it's likely Swift
|
|
120
|
-
// 1. Add import if missing
|
|
121
|
-
contents = addLinesOnce(contents, swiftReactImport, [swiftImport]);
|
|
122
|
-
// 2. Replace bundleURL provider if the original exists and hasn't been replaced
|
|
123
|
-
contents = replaceContentOnce(contents, swiftOriginalBundleUrlRegex, swiftBundleUrl, swiftBundleUrl);
|
|
124
|
-
}
|
|
73
|
+
contents = (0, transformers_1.transformIOS)(contents);
|
|
125
74
|
cfg.modResults.contents = contents;
|
|
126
75
|
return cfg;
|
|
127
76
|
});
|
|
128
|
-
// === Android: Kotlin
|
|
77
|
+
// === Android: Kotlin in MainApplication ===
|
|
129
78
|
modifiedConfig = (0, config_plugins_1.withMainApplication)(modifiedConfig, function (cfg) {
|
|
130
79
|
var contents = cfg.modResults.contents;
|
|
131
|
-
|
|
132
|
-
var kotlinImportAnchor = "import com.facebook.react.ReactApplication";
|
|
133
|
-
var kotlinReactNativeHostAnchor = "object : DefaultReactNativeHost(this) {"; // Start of block
|
|
134
|
-
var kotlinMethodCheck = "HotUpdater.getJSBundleFile(applicationContext)"; // Unique part of the method body
|
|
135
|
-
// Regex to find an existing getJSBundleFile override (non-greedy)
|
|
136
|
-
var kotlinExistingMethodRegex = /^\s*override fun getJSBundleFile\(\): String\?\s*\{[\s\S]*?^\s*\}/gm;
|
|
137
|
-
var kotlinHermesAnchor = "override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED";
|
|
138
|
-
var kotlinNewArchAnchor = "override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED";
|
|
139
|
-
var kotlinNewMethod = "\n override fun getJSBundleFile(): String? {\n return HotUpdater.getJSBundleFile(applicationContext)\n }";
|
|
140
|
-
var javaImport = "import com.hotupdater.HotUpdater;";
|
|
141
|
-
var javaImportAnchor = "import com.facebook.react.ReactApplication;";
|
|
142
|
-
var javaReactNativeHostAnchor = "new DefaultReactNativeHost"; // Part of the instantiation
|
|
143
|
-
var javaMethodCheck = "HotUpdater.Companion.getJSBundleFile"; // Unique part of the method body
|
|
144
|
-
// Regex to find an existing getJSBundleFile override (non-greedy)
|
|
145
|
-
var javaExistingMethodRegex = /^\s*@Override\s+protected String getJSBundleFile\(\)\s*\{[\s\S]*?^\s*\}/gm;
|
|
146
|
-
var javaHermesBlockEndAnchor = "return BuildConfig.IS_HERMES_ENABLED;\n }"; // End of the isHermesEnabled method block
|
|
147
|
-
var javaNewMethod = "\n @Override\n protected String getJSBundleFile() {\n return HotUpdater.Companion.getJSBundleFile(this.getApplication().getApplicationContext());\n }";
|
|
148
|
-
// --- Kotlin ---
|
|
149
|
-
if (contents.includes(kotlinReactNativeHostAnchor)) {
|
|
150
|
-
// Check if likely Kotlin
|
|
151
|
-
// 1. Add import if missing
|
|
152
|
-
contents = addLinesOnce(contents, kotlinImportAnchor, [kotlinImport]);
|
|
153
|
-
// 2. Add/Replace getJSBundleFile method if needed
|
|
154
|
-
if (!contents.includes(kotlinMethodCheck)) {
|
|
155
|
-
// Desired method content not found
|
|
156
|
-
// Remove potentially existing (different) override first
|
|
157
|
-
contents = contents.replace(kotlinExistingMethodRegex, "");
|
|
158
|
-
// Add the new method after the isHermesEnabled property
|
|
159
|
-
if (contents.includes(kotlinHermesAnchor)) {
|
|
160
|
-
contents = contents.replace(kotlinHermesAnchor, "".concat(kotlinHermesAnchor, "\n").concat(kotlinNewMethod));
|
|
161
|
-
}
|
|
162
|
-
else if (contents.includes(kotlinNewArchAnchor)) {
|
|
163
|
-
contents = contents.replace(kotlinNewArchAnchor, "".concat(kotlinNewArchAnchor, "\n").concat(kotlinNewMethod));
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
// Fallback: Add before the closing brace of the object if anchor not found
|
|
167
|
-
var rnHostEndRegex = /(\s*object\s*:\s*DefaultReactNativeHost\s*\([\s\S]*?\n)(\s*\})\s*$/m;
|
|
168
|
-
if (rnHostEndRegex.test(contents)) {
|
|
169
|
-
contents = contents.replace(rnHostEndRegex, "$1".concat(kotlinNewMethod, "\n$2"));
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new Error("[withHotUpdater] Kotlin: Could not find Hermes anchor or closing brace to insert getJSBundleFile.");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// --- Java ---
|
|
178
|
-
if (contents.includes(javaReactNativeHostAnchor) &&
|
|
179
|
-
contents.includes("@Override")) {
|
|
180
|
-
// Check if likely Java
|
|
181
|
-
// 1. Add import if missing
|
|
182
|
-
contents = addLinesOnce(contents, javaImportAnchor, [javaImport]);
|
|
183
|
-
// 2. Add/Replace getJSBundleFile method if needed
|
|
184
|
-
if (!contents.includes(javaMethodCheck)) {
|
|
185
|
-
// Desired method content not found
|
|
186
|
-
// Remove potentially existing (different) override first
|
|
187
|
-
contents = contents.replace(javaExistingMethodRegex, "");
|
|
188
|
-
// Add the new method after the isHermesEnabled method block
|
|
189
|
-
if (contents.includes(javaHermesBlockEndAnchor)) {
|
|
190
|
-
contents = contents.replace(javaHermesBlockEndAnchor, "".concat(javaHermesBlockEndAnchor, "\n").concat(javaNewMethod));
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// Fallback: Add before the closing brace of the anonymous class
|
|
194
|
-
var rnHostEndRegex = /(\s*new\s*DefaultReactNativeHost\s*\([\s\S]*?\n)(\s*\});\s*$/m;
|
|
195
|
-
if (rnHostEndRegex.test(contents)) {
|
|
196
|
-
contents = contents.replace(rnHostEndRegex, "$1".concat(javaNewMethod, "\n$2"));
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
throw new Error("[withHotUpdater] Java: Could not find Hermes anchor or closing brace to insert getJSBundleFile.");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
80
|
+
contents = (0, transformers_1.transformAndroid)(contents);
|
|
204
81
|
cfg.modResults.contents = contents;
|
|
205
82
|
return cfg;
|
|
206
83
|
});
|