@take-out/native-hot-update 0.4.3 → 0.4.4
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/dist/cjs/createHotUpdater.cjs +180 -136
- package/dist/cjs/createHotUpdater.native.js +189 -151
- package/dist/cjs/createHotUpdater.native.js.map +1 -1
- package/dist/cjs/helpers.cjs +15 -11
- package/dist/cjs/helpers.native.js +17 -13
- package/dist/cjs/helpers.native.js.map +1 -1
- package/dist/cjs/index.cjs +14 -12
- package/dist/cjs/index.native.js +14 -12
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/mmkv.cjs +12 -10
- package/dist/cjs/mmkv.native.js +12 -10
- package/dist/cjs/mmkv.native.js.map +1 -1
- package/dist/cjs/types.cjs +7 -5
- package/dist/cjs/types.native.js +7 -5
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/esm/createHotUpdater.mjs +152 -110
- package/dist/esm/createHotUpdater.mjs.map +1 -1
- package/dist/esm/createHotUpdater.native.js +161 -125
- package/dist/esm/createHotUpdater.native.js.map +1 -1
- package/dist/esm/helpers.mjs +3 -1
- package/dist/esm/helpers.mjs.map +1 -1
- package/dist/esm/helpers.native.js +3 -1
- package/dist/esm/helpers.native.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,171 +2,215 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var createHotUpdater_exports = {};
|
|
33
35
|
__export(createHotUpdater_exports, {
|
|
34
36
|
createHotUpdater: () => createHotUpdater
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(createHotUpdater_exports);
|
|
37
|
-
var import_react_native = require("@hot-updater/react-native")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const INITIAL_OTA_ID = "00000000-0000-0000-0000-000000000000"
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
var import_react_native = require("@hot-updater/react-native");
|
|
40
|
+
var Application = __toESM(require("expo-application"), 1);
|
|
41
|
+
var import_react = require("react");
|
|
42
|
+
var import_react_native2 = require("react-native-web");
|
|
43
|
+
const INITIAL_OTA_ID = "00000000-0000-0000-0000-000000000000";
|
|
44
|
+
const BUNDLE_ID_KEY_PREFIX = "hotUpdater.bundleId";
|
|
45
|
+
const PRE_RELEASE_BUNDLE_ID_KEY = "hotUpdater.preReleaseBundleId";
|
|
44
46
|
function createHotUpdater(config) {
|
|
45
47
|
const {
|
|
46
48
|
storage,
|
|
47
49
|
updateStrategy = "appVersion"
|
|
48
50
|
} = config;
|
|
49
|
-
let isUpdatePending =
|
|
51
|
+
let isUpdatePending = false;
|
|
50
52
|
const getAppliedOta = () => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
53
|
+
const id = import_react_native.HotUpdater.getBundleId();
|
|
54
|
+
if (id === INITIAL_OTA_ID) return null;
|
|
55
|
+
if (id === import_react_native.HotUpdater.getMinBundleId()) return null;
|
|
56
|
+
return id;
|
|
57
|
+
};
|
|
58
|
+
const getShortOtaId = () => {
|
|
59
|
+
const fullId = getAppliedOta();
|
|
60
|
+
return fullId ? fullId.slice(-12) : null;
|
|
61
|
+
};
|
|
62
|
+
const getIsUpdatePending = () => {
|
|
63
|
+
return isUpdatePending;
|
|
64
|
+
};
|
|
65
|
+
const getPreReleaseBundleId = () => {
|
|
66
|
+
return storage.get(PRE_RELEASE_BUNDLE_ID_KEY);
|
|
67
|
+
};
|
|
68
|
+
const handleUpdateDownloaded = (id, options = {}) => {
|
|
69
|
+
const appVersion = Application.nativeApplicationVersion;
|
|
70
|
+
if (appVersion) {
|
|
71
|
+
storage.set(`${BUNDLE_ID_KEY_PREFIX}.${appVersion}`, id);
|
|
72
|
+
}
|
|
73
|
+
if (options.isPreRelease) {
|
|
74
|
+
storage.set(PRE_RELEASE_BUNDLE_ID_KEY, id);
|
|
75
|
+
} else {
|
|
76
|
+
storage.delete(PRE_RELEASE_BUNDLE_ID_KEY);
|
|
77
|
+
}
|
|
78
|
+
isUpdatePending = true;
|
|
79
|
+
};
|
|
80
|
+
const useOtaUpdater = (options = {}) => {
|
|
81
|
+
const {
|
|
82
|
+
enabled = true,
|
|
83
|
+
onUpdateDownloaded: onUpdateDownloadedCallback,
|
|
84
|
+
onError
|
|
85
|
+
} = options;
|
|
86
|
+
const progress = (0, import_react_native.useHotUpdaterStore)(state => state.progress);
|
|
87
|
+
const isUpdating = progress > 0.01;
|
|
88
|
+
const [isUserClearedForAccess, setIsUserClearedForAccess] = (0, import_react.useState)(false);
|
|
89
|
+
const isUserClearedForAccessRef = (0, import_react.useRef)(isUserClearedForAccess);
|
|
90
|
+
isUserClearedForAccessRef.current = isUserClearedForAccess;
|
|
91
|
+
(0, import_react.useEffect)(() => {
|
|
92
|
+
if (!isUpdating) {
|
|
83
93
|
const timer = setTimeout(() => {
|
|
84
|
-
isUserClearedForAccessRef.current
|
|
85
|
-
|
|
94
|
+
if (!isUserClearedForAccessRef.current) {
|
|
95
|
+
setIsUserClearedForAccess(true);
|
|
96
|
+
}
|
|
97
|
+
}, 5e3);
|
|
86
98
|
return () => clearTimeout(timer);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
}
|
|
100
|
+
return void 0;
|
|
101
|
+
}, [isUpdating]);
|
|
102
|
+
(0, import_react.useEffect)(() => {
|
|
103
|
+
const timer = setTimeout(() => {
|
|
104
|
+
if (!isUserClearedForAccessRef.current) {
|
|
105
|
+
setIsUserClearedForAccess(true);
|
|
106
|
+
}
|
|
107
|
+
}, 2e4);
|
|
108
|
+
return () => clearTimeout(timer);
|
|
109
|
+
}, []);
|
|
110
|
+
(0, import_react.useEffect)(() => {
|
|
111
|
+
let shouldContinue = true;
|
|
112
|
+
(async () => {
|
|
113
|
+
try {
|
|
114
|
+
if (!enabled) {
|
|
115
|
+
setIsUserClearedForAccess(true);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!shouldContinue) return;
|
|
119
|
+
const updateInfo = await import_react_native.HotUpdater.checkForUpdate({
|
|
120
|
+
updateStrategy
|
|
121
|
+
});
|
|
122
|
+
if (!updateInfo) {
|
|
123
|
+
setIsUserClearedForAccess(true);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!shouldContinue) return;
|
|
127
|
+
if (updateInfo.status === "ROLLBACK") {
|
|
128
|
+
const preReleaseBundleId = getPreReleaseBundleId();
|
|
129
|
+
const currentBundleId = import_react_native.HotUpdater.getBundleId();
|
|
130
|
+
if (preReleaseBundleId && preReleaseBundleId === currentBundleId && currentBundleId > updateInfo.id) {
|
|
131
|
+
import_react_native2.Alert.alert("Update Skipped", "Skipped rollback because you are using a newer pre-release bundle.");
|
|
132
|
+
setIsUserClearedForAccess(true);
|
|
93
133
|
return;
|
|
94
134
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
135
|
+
}
|
|
136
|
+
if (!updateInfo.shouldForceUpdate) {
|
|
137
|
+
setIsUserClearedForAccess(true);
|
|
138
|
+
}
|
|
139
|
+
if (!shouldContinue) return;
|
|
140
|
+
await updateInfo.updateBundle();
|
|
141
|
+
handleUpdateDownloaded(updateInfo.id);
|
|
142
|
+
const info = {
|
|
143
|
+
id: updateInfo.id,
|
|
144
|
+
isCriticalUpdate: updateInfo.shouldForceUpdate,
|
|
145
|
+
fileUrl: updateInfo.fileUrl,
|
|
146
|
+
message: updateInfo.message
|
|
147
|
+
};
|
|
148
|
+
onUpdateDownloadedCallback?.(info);
|
|
149
|
+
if (!shouldContinue) return;
|
|
150
|
+
if (updateInfo.shouldForceUpdate) {
|
|
151
|
+
if (!isUserClearedForAccessRef.current) {
|
|
152
|
+
import_react_native.HotUpdater.reload();
|
|
101
153
|
return;
|
|
102
154
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (updateInfo.shouldForceUpdate || setIsUserClearedForAccess(!0), !shouldContinue) return;
|
|
113
|
-
await updateInfo.updateBundle(), handleUpdateDownloaded(updateInfo.id);
|
|
114
|
-
const info = {
|
|
115
|
-
id: updateInfo.id,
|
|
116
|
-
isCriticalUpdate: updateInfo.shouldForceUpdate,
|
|
117
|
-
fileUrl: updateInfo.fileUrl,
|
|
118
|
-
message: updateInfo.message
|
|
119
|
-
};
|
|
120
|
-
if (onUpdateDownloadedCallback?.(info), !shouldContinue) return;
|
|
121
|
-
if (updateInfo.shouldForceUpdate) {
|
|
122
|
-
if (!isUserClearedForAccessRef.current) {
|
|
123
|
-
import_react_native.HotUpdater.reload();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
import_react_native2.Alert.alert("Update Downloaded", "An important update has been downloaded. Reload now to apply it?", [{
|
|
127
|
-
text: "Later",
|
|
128
|
-
style: "cancel"
|
|
129
|
-
}, {
|
|
130
|
-
text: "Reload Now",
|
|
131
|
-
onPress: () => import_react_native.HotUpdater.reload()
|
|
132
|
-
}]);
|
|
133
|
-
}
|
|
134
|
-
} catch (error) {
|
|
135
|
-
onError?.(error), setIsUserClearedForAccess(!0);
|
|
136
|
-
} finally {
|
|
137
|
-
isUserClearedForAccessRef.current || setIsUserClearedForAccess(!0);
|
|
155
|
+
import_react_native2.Alert.alert("Update Downloaded", "An important update has been downloaded. Reload now to apply it?", [{
|
|
156
|
+
text: "Later",
|
|
157
|
+
style: "cancel"
|
|
158
|
+
}, {
|
|
159
|
+
text: "Reload Now",
|
|
160
|
+
onPress: () => import_react_native.HotUpdater.reload()
|
|
161
|
+
}]);
|
|
138
162
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
} catch (error) {
|
|
164
|
+
onError?.(error);
|
|
165
|
+
setIsUserClearedForAccess(true);
|
|
166
|
+
} finally {
|
|
167
|
+
if (!isUserClearedForAccessRef.current) {
|
|
168
|
+
setIsUserClearedForAccess(true);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
})();
|
|
172
|
+
return () => {
|
|
173
|
+
shouldContinue = false;
|
|
146
174
|
};
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
175
|
+
}, [enabled, onUpdateDownloadedCallback, onError]);
|
|
176
|
+
return {
|
|
177
|
+
userClearedForAccess: isUserClearedForAccess,
|
|
178
|
+
progress,
|
|
179
|
+
isUpdatePending: getIsUpdatePending()
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
const checkForUpdate = async (options = {}) => {
|
|
183
|
+
const {
|
|
184
|
+
channel,
|
|
185
|
+
isPreRelease = false
|
|
186
|
+
} = options;
|
|
187
|
+
const requestHeaders = {};
|
|
188
|
+
if (channel) {
|
|
189
|
+
requestHeaders["X-Channel"] = channel;
|
|
190
|
+
}
|
|
191
|
+
const updateInfo = await import_react_native.HotUpdater.checkForUpdate({
|
|
192
|
+
updateStrategy,
|
|
193
|
+
...(Object.keys(requestHeaders).length > 0 && {
|
|
194
|
+
requestHeaders
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
if (updateInfo) {
|
|
198
|
+
await updateInfo.updateBundle();
|
|
199
|
+
handleUpdateDownloaded(updateInfo.id, {
|
|
162
200
|
isPreRelease
|
|
163
|
-
})
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
164
203
|
id: updateInfo.id,
|
|
165
204
|
isCriticalUpdate: updateInfo.shouldForceUpdate,
|
|
166
205
|
fileUrl: updateInfo.fileUrl,
|
|
167
206
|
message: updateInfo.message
|
|
168
|
-
}
|
|
169
|
-
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
useOtaUpdater,
|
|
213
|
+
checkForUpdate,
|
|
170
214
|
getAppliedOta,
|
|
171
215
|
getShortOtaId,
|
|
172
216
|
getIsUpdatePending,
|