@gfean/react-native-bundle-drop 0.1.82 → 0.1.85
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/bundledrop/BundleDropModule.kt +86 -0
- package/ios/BundleDropBridge.m +29 -1
- package/ios/BundleDropModule.swift +132 -4
- package/lib/bundleInfo.js +5 -5
- package/lib/context.js +3 -3
- package/lib/fs/bundlePointer.js +5 -5
- package/lib/fs/fsUtils.js +13 -13
- package/lib/fs/installId.js +3 -3
- package/lib/fs/userProperties.js +5 -5
- package/lib/injectImageResolver.js +2 -2
- package/lib/install/installFromZip.js +2 -2
- package/lib/manager/rollbackState.js +5 -5
- package/lib/native/fs.d.ts +17 -0
- package/lib/native/fs.js +33 -0
- package/package.json +1 -2
|
@@ -125,11 +125,97 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// FS primitives (replaces react-native-fs dependency)
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
@ReactMethod
|
|
133
|
+
fun fsExists(path: String, promise: Promise) {
|
|
134
|
+
promise.resolve(File(path).exists())
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@ReactMethod
|
|
138
|
+
fun fsReadFile(path: String, encoding: String, promise: Promise) {
|
|
139
|
+
try {
|
|
140
|
+
val file = File(path)
|
|
141
|
+
if (!file.exists()) {
|
|
142
|
+
promise.reject("ENOENT", "File not found: $path")
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
if (encoding == "base64") {
|
|
146
|
+
val bytes = file.readBytes()
|
|
147
|
+
promise.resolve(android.util.Base64.encodeToString(bytes, android.util.Base64.NO_WRAP))
|
|
148
|
+
} else {
|
|
149
|
+
promise.resolve(file.readText(Charsets.UTF_8))
|
|
150
|
+
}
|
|
151
|
+
} catch (e: Exception) {
|
|
152
|
+
promise.reject("ERR_READ", e.message, e)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@ReactMethod
|
|
157
|
+
fun fsWriteFile(path: String, content: String, encoding: String, promise: Promise) {
|
|
158
|
+
try {
|
|
159
|
+
val file = File(path)
|
|
160
|
+
file.parentFile?.mkdirs()
|
|
161
|
+
if (encoding == "base64") {
|
|
162
|
+
val bytes = android.util.Base64.decode(content, android.util.Base64.DEFAULT)
|
|
163
|
+
file.writeBytes(bytes)
|
|
164
|
+
} else {
|
|
165
|
+
file.writeText(content, Charsets.UTF_8)
|
|
166
|
+
}
|
|
167
|
+
promise.resolve(null)
|
|
168
|
+
} catch (e: Exception) {
|
|
169
|
+
promise.reject("ERR_WRITE", e.message, e)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@ReactMethod
|
|
174
|
+
fun fsMkdir(path: String, promise: Promise) {
|
|
175
|
+
try {
|
|
176
|
+
val dir = File(path)
|
|
177
|
+
if (!dir.exists()) dir.mkdirs()
|
|
178
|
+
promise.resolve(null)
|
|
179
|
+
} catch (e: Exception) {
|
|
180
|
+
promise.reject("ERR_MKDIR", e.message, e)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@ReactMethod
|
|
185
|
+
fun fsUnlink(path: String, promise: Promise) {
|
|
186
|
+
try {
|
|
187
|
+
val file = File(path)
|
|
188
|
+
if (file.exists()) file.delete()
|
|
189
|
+
promise.resolve(null)
|
|
190
|
+
} catch (e: Exception) {
|
|
191
|
+
promise.reject("ERR_UNLINK", e.message, e)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@ReactMethod
|
|
196
|
+
fun fsMoveFile(src: String, dest: String, promise: Promise) {
|
|
197
|
+
try {
|
|
198
|
+
val srcFile = File(src)
|
|
199
|
+
val destFile = File(dest)
|
|
200
|
+
destFile.parentFile?.mkdirs()
|
|
201
|
+
if (!srcFile.renameTo(destFile)) {
|
|
202
|
+
srcFile.copyTo(destFile, overwrite = true)
|
|
203
|
+
srcFile.delete()
|
|
204
|
+
}
|
|
205
|
+
promise.resolve(null)
|
|
206
|
+
} catch (e: Exception) {
|
|
207
|
+
promise.reject("ERR_MOVE", e.message, e)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
128
211
|
override fun getConstants(): MutableMap<String, Any> {
|
|
129
212
|
val map = mutableMapOf<String, Any>()
|
|
130
213
|
downloadedBundlePath?.let {
|
|
131
214
|
map["downloadedBundlePath"] = it
|
|
132
215
|
}
|
|
216
|
+
val context = reactApplicationContext
|
|
217
|
+
map["DocumentDirectoryPath"] = context.filesDir.absolutePath
|
|
218
|
+
map["LibraryDirectoryPath"] = context.filesDir.absolutePath
|
|
133
219
|
return map
|
|
134
220
|
}
|
|
135
221
|
}
|
package/ios/BundleDropBridge.m
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
2
|
|
|
3
|
-
// JS name "BundleDrop" -> Swift class "BundleDropModule"
|
|
4
3
|
@interface RCT_EXTERN_REMAP_MODULE(BundleDrop, BundleDropModule, NSObject)
|
|
5
4
|
|
|
6
5
|
RCT_EXTERN_METHOD(getDownloadedBundlePath:(RCTPromiseResolveBlock)resolve
|
|
@@ -8,6 +7,35 @@ RCT_EXTERN_METHOD(getDownloadedBundlePath:(RCTPromiseResolveBlock)resolve
|
|
|
8
7
|
|
|
9
8
|
RCT_EXTERN_METHOD(restartReactNative)
|
|
10
9
|
|
|
10
|
+
// FS primitives
|
|
11
|
+
RCT_EXTERN_METHOD(fsExists:(NSString *)path
|
|
12
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
13
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
14
|
+
|
|
15
|
+
RCT_EXTERN_METHOD(fsReadFile:(NSString *)path
|
|
16
|
+
encoding:(NSString *)encoding
|
|
17
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
18
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
19
|
+
|
|
20
|
+
RCT_EXTERN_METHOD(fsWriteFile:(NSString *)path
|
|
21
|
+
content:(NSString *)content
|
|
22
|
+
encoding:(NSString *)encoding
|
|
23
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
24
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
25
|
+
|
|
26
|
+
RCT_EXTERN_METHOD(fsMkdir:(NSString *)path
|
|
27
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
28
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
29
|
+
|
|
30
|
+
RCT_EXTERN_METHOD(fsUnlink:(NSString *)path
|
|
31
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
32
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
33
|
+
|
|
34
|
+
RCT_EXTERN_METHOD(fsMoveFile:(NSString *)src
|
|
35
|
+
dest:(NSString *)dest
|
|
36
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
37
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
38
|
+
|
|
11
39
|
+ (BOOL)requiresMainQueueSetup
|
|
12
40
|
{
|
|
13
41
|
return NO;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import React
|
|
3
3
|
|
|
4
|
-
@objc(BundleDropModule)
|
|
4
|
+
@objc(BundleDropModule)
|
|
5
5
|
final class BundleDropModule: NSObject {
|
|
6
6
|
|
|
7
7
|
private static var isReloading = false
|
|
8
|
+
private static let fm = FileManager.default
|
|
8
9
|
|
|
9
10
|
// MARK: - OTA bundle path
|
|
10
11
|
|
|
@@ -22,7 +23,6 @@ final class BundleDropModule: NSObject {
|
|
|
22
23
|
resolve(nil)
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
// 🚨 Restart RN safely (debounced)
|
|
26
26
|
@objc
|
|
27
27
|
func restartReactNative() {
|
|
28
28
|
DispatchQueue.main.async {
|
|
@@ -45,14 +45,142 @@ final class BundleDropModule: NSObject {
|
|
|
45
45
|
Self.isReloading = true
|
|
46
46
|
print("🔄 Restarting RN from \(url.path) size=\(size)")
|
|
47
47
|
|
|
48
|
-
// Trigger a standard RN reload; AppDelegate.bundleURL() decides OTA vs embedded
|
|
49
48
|
RCTReloadCommandSetBundleURL(url)
|
|
50
49
|
RCTTriggerReloadCommandListeners("bundle-drop-restart")
|
|
51
50
|
|
|
52
|
-
// release lock after a short moment to prevent double-trigger
|
|
53
51
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
|
54
52
|
Self.isReloading = false
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
}
|
|
56
|
+
|
|
57
|
+
// MARK: - Constants
|
|
58
|
+
|
|
59
|
+
@objc
|
|
60
|
+
func constantsToExport() -> [String: Any] {
|
|
61
|
+
let fm = FileManager.default
|
|
62
|
+
let docs = fm.urls(for: .documentDirectory, in: .userDomainMask).first?.path ?? ""
|
|
63
|
+
let lib = fm.urls(for: .libraryDirectory, in: .userDomainMask).first?.path ?? ""
|
|
64
|
+
return [
|
|
65
|
+
"DocumentDirectoryPath": docs,
|
|
66
|
+
"LibraryDirectoryPath": lib,
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// MARK: - FS primitives (replaces react-native-fs dependency)
|
|
71
|
+
|
|
72
|
+
@objc
|
|
73
|
+
func fsExists(
|
|
74
|
+
_ path: String,
|
|
75
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
76
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
77
|
+
) {
|
|
78
|
+
resolve(Self.fm.fileExists(atPath: path))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc
|
|
82
|
+
func fsReadFile(
|
|
83
|
+
_ path: String,
|
|
84
|
+
encoding: String,
|
|
85
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
86
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
87
|
+
) {
|
|
88
|
+
guard Self.fm.fileExists(atPath: path) else {
|
|
89
|
+
reject("ENOENT", "File not found: \(path)", nil)
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
do {
|
|
93
|
+
if encoding == "base64" {
|
|
94
|
+
let data = try Data(contentsOf: URL(fileURLWithPath: path))
|
|
95
|
+
resolve(data.base64EncodedString())
|
|
96
|
+
} else {
|
|
97
|
+
let text = try String(contentsOfFile: path, encoding: .utf8)
|
|
98
|
+
resolve(text)
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
reject("ERR_READ", error.localizedDescription, error)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@objc
|
|
106
|
+
func fsWriteFile(
|
|
107
|
+
_ path: String,
|
|
108
|
+
content: String,
|
|
109
|
+
encoding: String,
|
|
110
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
111
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
112
|
+
) {
|
|
113
|
+
do {
|
|
114
|
+
let dir = (path as NSString).deletingLastPathComponent
|
|
115
|
+
if !Self.fm.fileExists(atPath: dir) {
|
|
116
|
+
try Self.fm.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
|
117
|
+
}
|
|
118
|
+
if encoding == "base64" {
|
|
119
|
+
guard let data = Data(base64Encoded: content) else {
|
|
120
|
+
reject("ERR_WRITE", "Invalid base64 data", nil)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
try data.write(to: URL(fileURLWithPath: path))
|
|
124
|
+
} else {
|
|
125
|
+
try content.write(toFile: path, atomically: true, encoding: .utf8)
|
|
126
|
+
}
|
|
127
|
+
resolve(nil)
|
|
128
|
+
} catch {
|
|
129
|
+
reject("ERR_WRITE", error.localizedDescription, error)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@objc
|
|
134
|
+
func fsMkdir(
|
|
135
|
+
_ path: String,
|
|
136
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
137
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
138
|
+
) {
|
|
139
|
+
do {
|
|
140
|
+
if !Self.fm.fileExists(atPath: path) {
|
|
141
|
+
try Self.fm.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
142
|
+
}
|
|
143
|
+
resolve(nil)
|
|
144
|
+
} catch {
|
|
145
|
+
reject("ERR_MKDIR", error.localizedDescription, error)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@objc
|
|
150
|
+
func fsUnlink(
|
|
151
|
+
_ path: String,
|
|
152
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
153
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
154
|
+
) {
|
|
155
|
+
do {
|
|
156
|
+
if Self.fm.fileExists(atPath: path) {
|
|
157
|
+
try Self.fm.removeItem(atPath: path)
|
|
158
|
+
}
|
|
159
|
+
resolve(nil)
|
|
160
|
+
} catch {
|
|
161
|
+
reject("ERR_UNLINK", error.localizedDescription, error)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@objc
|
|
166
|
+
func fsMoveFile(
|
|
167
|
+
_ src: String,
|
|
168
|
+
dest: String,
|
|
169
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
170
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
171
|
+
) {
|
|
172
|
+
do {
|
|
173
|
+
let destDir = (dest as NSString).deletingLastPathComponent
|
|
174
|
+
if !Self.fm.fileExists(atPath: destDir) {
|
|
175
|
+
try Self.fm.createDirectory(atPath: destDir, withIntermediateDirectories: true)
|
|
176
|
+
}
|
|
177
|
+
if Self.fm.fileExists(atPath: dest) {
|
|
178
|
+
try Self.fm.removeItem(atPath: dest)
|
|
179
|
+
}
|
|
180
|
+
try Self.fm.moveItem(atPath: src, toPath: dest)
|
|
181
|
+
resolve(nil)
|
|
182
|
+
} catch {
|
|
183
|
+
reject("ERR_MOVE", error.localizedDescription, error)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
58
186
|
}
|
package/lib/bundleInfo.js
CHANGED
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.readBundleInfo = readBundleInfo;
|
|
7
7
|
exports.writeBundleInfo = writeBundleInfo;
|
|
8
8
|
exports.updateBundleInfo = updateBundleInfo;
|
|
9
|
-
const
|
|
10
|
-
const BUNDLE_INFO_PATH = `${
|
|
9
|
+
const fs_1 = __importDefault(require("./native/fs"));
|
|
10
|
+
const BUNDLE_INFO_PATH = `${fs_1.default.DocumentDirectoryPath}/bundle-info.json`;
|
|
11
11
|
async function readBundleInfo() {
|
|
12
12
|
try {
|
|
13
|
-
if (!(await
|
|
13
|
+
if (!(await fs_1.default.exists(BUNDLE_INFO_PATH)))
|
|
14
14
|
return null;
|
|
15
|
-
const raw = await
|
|
15
|
+
const raw = await fs_1.default.readFile(BUNDLE_INFO_PATH, 'utf8');
|
|
16
16
|
return JSON.parse(raw);
|
|
17
17
|
}
|
|
18
18
|
catch (e) {
|
|
@@ -22,7 +22,7 @@ async function readBundleInfo() {
|
|
|
22
22
|
}
|
|
23
23
|
async function writeBundleInfo(info) {
|
|
24
24
|
try {
|
|
25
|
-
await
|
|
25
|
+
await fs_1.default.writeFile(BUNDLE_INFO_PATH, JSON.stringify(info, null, 2), 'utf8');
|
|
26
26
|
}
|
|
27
27
|
catch (e) {
|
|
28
28
|
console.warn('⚠️ Failed to write bundle-info.json', e);
|
package/lib/context.js
CHANGED
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BUNDLE_DROP_ROOT = exports.runtimeVersion = exports.isIOS = exports.platform = exports.config = void 0;
|
|
7
7
|
const react_native_1 = require("react-native");
|
|
8
|
-
const
|
|
8
|
+
const fs_1 = __importDefault(require("./native/fs"));
|
|
9
9
|
const loadConfig_1 = require("./loadConfig");
|
|
10
10
|
exports.config = (0, loadConfig_1.loadConfig)();
|
|
11
11
|
exports.platform = react_native_1.Platform.OS === 'ios' ? 'ios' : 'android';
|
|
12
12
|
exports.isIOS = exports.platform === 'ios';
|
|
13
13
|
exports.runtimeVersion = exports.config.runtimeVersion?.[exports.platform];
|
|
14
14
|
exports.BUNDLE_DROP_ROOT = exports.isIOS
|
|
15
|
-
? `${
|
|
16
|
-
: `${
|
|
15
|
+
? `${fs_1.default.LibraryDirectoryPath}/bundle-drop`
|
|
16
|
+
: `${fs_1.default.DocumentDirectoryPath}/bundle-drop`;
|
package/lib/fs/bundlePointer.js
CHANGED
|
@@ -10,16 +10,16 @@ exports.writePreviousBundlePointer = writePreviousBundlePointer;
|
|
|
10
10
|
exports.setCurrentBundlePointer = setCurrentBundlePointer;
|
|
11
11
|
exports.rollbackToPreviousPointer = rollbackToPreviousPointer;
|
|
12
12
|
exports.clearCurrentBundlePointer = clearCurrentBundlePointer;
|
|
13
|
-
const
|
|
13
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
14
14
|
const context_1 = require("../context");
|
|
15
15
|
const fsUtils_1 = require("./fsUtils");
|
|
16
16
|
const CURRENT_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/current.json`;
|
|
17
17
|
const PREVIOUS_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/previous.json`;
|
|
18
18
|
async function readPointer(path) {
|
|
19
19
|
try {
|
|
20
|
-
if (!(await
|
|
20
|
+
if (!(await fs_1.default.exists(path)))
|
|
21
21
|
return null;
|
|
22
|
-
const raw = await
|
|
22
|
+
const raw = await fs_1.default.readFile(path, 'utf8');
|
|
23
23
|
const parsed = JSON.parse(raw);
|
|
24
24
|
if (!parsed?.hash || !parsed?.bundlePath)
|
|
25
25
|
return null;
|
|
@@ -67,8 +67,8 @@ async function rollbackToPreviousPointer() {
|
|
|
67
67
|
}
|
|
68
68
|
async function clearCurrentBundlePointer() {
|
|
69
69
|
try {
|
|
70
|
-
if (await
|
|
71
|
-
await
|
|
70
|
+
if (await fs_1.default.exists(CURRENT_POINTER_PATH)) {
|
|
71
|
+
await fs_1.default.unlink(CURRENT_POINTER_PATH);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
catch {
|
package/lib/fs/fsUtils.js
CHANGED
|
@@ -7,32 +7,32 @@ exports.ensureDir = ensureDir;
|
|
|
7
7
|
exports.atomicWriteJson = atomicWriteJson;
|
|
8
8
|
exports.ensureParentDir = ensureParentDir;
|
|
9
9
|
exports.writeFileAtomicBase64 = writeFileAtomicBase64;
|
|
10
|
-
const
|
|
10
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
11
11
|
async function ensureDir(dir) {
|
|
12
|
-
if (!(await
|
|
13
|
-
await
|
|
12
|
+
if (!(await fs_1.default.exists(dir))) {
|
|
13
|
+
await fs_1.default.mkdir(dir);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
async function atomicWriteJson(path, data) {
|
|
17
17
|
const tmp = `${path}.tmp`;
|
|
18
|
-
await
|
|
19
|
-
if (await
|
|
20
|
-
await
|
|
18
|
+
await fs_1.default.writeFile(tmp, JSON.stringify(data), 'utf8');
|
|
19
|
+
if (await fs_1.default.exists(path)) {
|
|
20
|
+
await fs_1.default.unlink(path);
|
|
21
21
|
}
|
|
22
|
-
await
|
|
22
|
+
await fs_1.default.moveFile(tmp, path);
|
|
23
23
|
}
|
|
24
24
|
async function ensureParentDir(filePath) {
|
|
25
25
|
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
26
|
-
if (!(await
|
|
27
|
-
await
|
|
26
|
+
if (!(await fs_1.default.exists(dir))) {
|
|
27
|
+
await fs_1.default.mkdir(dir);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
async function writeFileAtomicBase64(path, base64) {
|
|
31
31
|
const tmp = `${path}.tmp`;
|
|
32
32
|
await ensureParentDir(path);
|
|
33
|
-
await
|
|
34
|
-
if (await
|
|
35
|
-
await
|
|
33
|
+
await fs_1.default.writeFile(tmp, base64, 'base64');
|
|
34
|
+
if (await fs_1.default.exists(path)) {
|
|
35
|
+
await fs_1.default.unlink(path);
|
|
36
36
|
}
|
|
37
|
-
await
|
|
37
|
+
await fs_1.default.moveFile(tmp, path);
|
|
38
38
|
}
|
package/lib/fs/installId.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getOrCreateInstallId = getOrCreateInstallId;
|
|
7
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
8
8
|
const context_1 = require("../context");
|
|
9
9
|
const fsUtils_1 = require("./fsUtils");
|
|
10
10
|
function getInstallIdPath() {
|
|
@@ -13,7 +13,7 @@ function getInstallIdPath() {
|
|
|
13
13
|
async function getOrCreateInstallId() {
|
|
14
14
|
const path = getInstallIdPath();
|
|
15
15
|
try {
|
|
16
|
-
const existing = await
|
|
16
|
+
const existing = await fs_1.default.readFile(path, 'utf8');
|
|
17
17
|
if (existing?.trim())
|
|
18
18
|
return existing.trim();
|
|
19
19
|
}
|
|
@@ -24,6 +24,6 @@ async function getOrCreateInstallId() {
|
|
|
24
24
|
`${Math.random().toString(36).slice(2, 10)}-` +
|
|
25
25
|
`${Math.random().toString(36).slice(2, 10)}`;
|
|
26
26
|
await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
|
|
27
|
-
await
|
|
27
|
+
await fs_1.default.writeFile(path, id, 'utf8');
|
|
28
28
|
return id;
|
|
29
29
|
}
|
package/lib/fs/userProperties.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.getUserProperties = getUserProperties;
|
|
|
9
9
|
exports.setUserProperty = setUserProperty;
|
|
10
10
|
exports.removeUserProperty = removeUserProperty;
|
|
11
11
|
exports.resetUserProperties = resetUserProperties;
|
|
12
|
-
const
|
|
12
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
13
13
|
const context_1 = require("../context");
|
|
14
14
|
const fsUtils_1 = require("./fsUtils");
|
|
15
15
|
const USER_PROPERTIES_PATH = `${context_1.BUNDLE_DROP_ROOT}/user-properties.json`;
|
|
@@ -36,9 +36,9 @@ async function writeUserProperties(properties) {
|
|
|
36
36
|
}
|
|
37
37
|
async function getCurrentUserProperties() {
|
|
38
38
|
try {
|
|
39
|
-
if (!(await
|
|
39
|
+
if (!(await fs_1.default.exists(USER_PROPERTIES_PATH)))
|
|
40
40
|
return [];
|
|
41
|
-
const raw = await
|
|
41
|
+
const raw = await fs_1.default.readFile(USER_PROPERTIES_PATH, 'utf8');
|
|
42
42
|
const parsed = JSON.parse(raw);
|
|
43
43
|
if (Array.isArray(parsed)) {
|
|
44
44
|
return unique(parsed.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
|
|
@@ -88,8 +88,8 @@ async function removeUserProperty(value) {
|
|
|
88
88
|
}
|
|
89
89
|
async function resetUserProperties() {
|
|
90
90
|
try {
|
|
91
|
-
if (await
|
|
92
|
-
await
|
|
91
|
+
if (await fs_1.default.exists(USER_PROPERTIES_PATH)) {
|
|
92
|
+
await fs_1.default.unlink(USER_PROPERTIES_PATH);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
catch (e) {
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.patchImageResolverWithManifest = patchImageResolverWithManifest;
|
|
7
7
|
exports.injectBundleDropImageResolver = injectBundleDropImageResolver;
|
|
8
8
|
const react_native_1 = require("react-native");
|
|
9
|
-
const
|
|
9
|
+
const fs_1 = __importDefault(require("./native/fs"));
|
|
10
10
|
let hasPatched = false;
|
|
11
11
|
const { BundleDrop } = react_native_1.NativeModules;
|
|
12
12
|
// Build lookup maps: exact keys and basename aliases so we can resolve filename-only URIs.
|
|
@@ -89,7 +89,7 @@ function patchImageResolverWithManifest(manifest) {
|
|
|
89
89
|
}
|
|
90
90
|
if (finalPath) {
|
|
91
91
|
const hasExtension = /\.[a-zA-Z0-9]+$/.test(finalPath);
|
|
92
|
-
const fullPath = `file://${
|
|
92
|
+
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (uri.match(/\.[^.]+$/)?.[0] ?? '')}`;
|
|
93
93
|
console.log(`🧩 Overriding asset path: ${uri} → ${fullPath}`);
|
|
94
94
|
return { ...resolved, uri: fullPath };
|
|
95
95
|
}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.installFromZip = installFromZip;
|
|
7
7
|
const buffer_1 = require("buffer");
|
|
8
8
|
const fflate_1 = require("fflate");
|
|
9
|
-
const
|
|
9
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
10
10
|
const context_1 = require("../context");
|
|
11
11
|
const image_manifest_1 = require("../image-manifest");
|
|
12
12
|
const injectImageResolver_1 = require("../injectImageResolver");
|
|
@@ -60,7 +60,7 @@ async function installFromZip(params) {
|
|
|
60
60
|
// Write other files under bundleDir (e.g., metadata, assets)
|
|
61
61
|
const filePath = `${bundleDir}/${filename}`;
|
|
62
62
|
await (0, fsUtils_1.ensureParentDir)(filePath);
|
|
63
|
-
await
|
|
63
|
+
await fs_1.default.writeFile(filePath, base64, 'base64');
|
|
64
64
|
// Collect runtime manifest entries for assets; support paths with or without "assets/" prefix.
|
|
65
65
|
if (filename.includes('drawable') || filename.startsWith('assets/') || filename.startsWith('res/')) {
|
|
66
66
|
const noExt = filename.replace(/\.[^.]+$/, '');
|
|
@@ -9,7 +9,7 @@ exports.evaluateRollbackOnLaunch = evaluateRollbackOnLaunch;
|
|
|
9
9
|
exports.rollbackToPreviousIfNeeded = rollbackToPreviousIfNeeded;
|
|
10
10
|
exports.getRollbackPolicy = getRollbackPolicy;
|
|
11
11
|
exports.rollbackToPreviousOrNative = rollbackToPreviousOrNative;
|
|
12
|
-
const
|
|
12
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
13
13
|
const context_1 = require("../context");
|
|
14
14
|
const fsUtils_1 = require("../fs/fsUtils");
|
|
15
15
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
@@ -32,9 +32,9 @@ function normalizePolicy(policy) {
|
|
|
32
32
|
}
|
|
33
33
|
async function readState() {
|
|
34
34
|
try {
|
|
35
|
-
if (!(await
|
|
35
|
+
if (!(await fs_1.default.exists(STATE_PATH)))
|
|
36
36
|
return null;
|
|
37
|
-
const raw = await
|
|
37
|
+
const raw = await fs_1.default.readFile(STATE_PATH, 'utf8');
|
|
38
38
|
return JSON.parse(raw);
|
|
39
39
|
}
|
|
40
40
|
catch {
|
|
@@ -170,9 +170,9 @@ async function readBundleMetadata(bundlePath) {
|
|
|
170
170
|
const dir = bundlePath.substring(0, bundlePath.lastIndexOf('/'));
|
|
171
171
|
const metadataFile = context_1.platform === 'android' ? 'metadata-android.json' : 'metadata-ios.json';
|
|
172
172
|
const filePath = `${dir}/${metadataFile}`;
|
|
173
|
-
if (!(await
|
|
173
|
+
if (!(await fs_1.default.exists(filePath)))
|
|
174
174
|
return null;
|
|
175
|
-
const raw = await
|
|
175
|
+
const raw = await fs_1.default.readFile(filePath, 'utf8');
|
|
176
176
|
const parsed = JSON.parse(raw);
|
|
177
177
|
return {
|
|
178
178
|
bundleVersion: parsed?.bundleVersion,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare function exists(path: string): Promise<boolean>;
|
|
2
|
+
declare function readFile(path: string, encoding?: 'utf8' | 'base64'): Promise<string>;
|
|
3
|
+
declare function writeFile(path: string, content: string, encoding?: 'utf8' | 'base64'): Promise<void>;
|
|
4
|
+
declare function mkdir(path: string): Promise<void>;
|
|
5
|
+
declare function unlink(path: string): Promise<void>;
|
|
6
|
+
declare function moveFile(src: string, dest: string): Promise<void>;
|
|
7
|
+
declare const BundleDropFS: {
|
|
8
|
+
DocumentDirectoryPath: string;
|
|
9
|
+
LibraryDirectoryPath: string;
|
|
10
|
+
exists: typeof exists;
|
|
11
|
+
readFile: typeof readFile;
|
|
12
|
+
writeFile: typeof writeFile;
|
|
13
|
+
mkdir: typeof mkdir;
|
|
14
|
+
unlink: typeof unlink;
|
|
15
|
+
moveFile: typeof moveFile;
|
|
16
|
+
};
|
|
17
|
+
export default BundleDropFS;
|
package/lib/native/fs.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_native_1 = require("react-native");
|
|
4
|
+
const { BundleDrop } = react_native_1.NativeModules;
|
|
5
|
+
async function exists(path) {
|
|
6
|
+
return BundleDrop.fsExists(path);
|
|
7
|
+
}
|
|
8
|
+
async function readFile(path, encoding = 'utf8') {
|
|
9
|
+
return BundleDrop.fsReadFile(path, encoding);
|
|
10
|
+
}
|
|
11
|
+
async function writeFile(path, content, encoding = 'utf8') {
|
|
12
|
+
return BundleDrop.fsWriteFile(path, content, encoding);
|
|
13
|
+
}
|
|
14
|
+
async function mkdir(path) {
|
|
15
|
+
return BundleDrop.fsMkdir(path);
|
|
16
|
+
}
|
|
17
|
+
async function unlink(path) {
|
|
18
|
+
return BundleDrop.fsUnlink(path);
|
|
19
|
+
}
|
|
20
|
+
async function moveFile(src, dest) {
|
|
21
|
+
return BundleDrop.fsMoveFile(src, dest);
|
|
22
|
+
}
|
|
23
|
+
const BundleDropFS = {
|
|
24
|
+
DocumentDirectoryPath: (BundleDrop?.DocumentDirectoryPath ?? ''),
|
|
25
|
+
LibraryDirectoryPath: (BundleDrop?.LibraryDirectoryPath ?? ''),
|
|
26
|
+
exists,
|
|
27
|
+
readFile,
|
|
28
|
+
writeFile,
|
|
29
|
+
mkdir,
|
|
30
|
+
unlink,
|
|
31
|
+
moveFile,
|
|
32
|
+
};
|
|
33
|
+
exports.default = BundleDropFS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfean/react-native-bundle-drop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.85",
|
|
4
4
|
"description": "react native ota by gFean",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -68,7 +68,6 @@
|
|
|
68
68
|
"fs-extra": "^11.2.0",
|
|
69
69
|
"plist": "^3.1.0",
|
|
70
70
|
"prompts": "^2.4.2",
|
|
71
|
-
"react-native-fs": "^2.20.0",
|
|
72
71
|
"undici": "^7.8.0"
|
|
73
72
|
},
|
|
74
73
|
"publishConfig": {
|