@hot-updater/react-native 0.12.7 → 0.13.1
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/generated/java/com/hotupdater/NativeHotUpdaterSpec.java +32 -0
- package/android/generated/jni/HotUpdaterSpec-generated.cpp +6 -0
- package/android/generated/jni/react/renderer/components/HotUpdaterSpec/HotUpdaterSpecJSI-generated.cpp +6 -0
- package/android/generated/jni/react/renderer/components/HotUpdaterSpec/HotUpdaterSpecJSI.h +9 -0
- package/android/src/main/java/com/hotupdater/HotUpdater.kt +47 -1
- package/android/src/newarch/HotUpdaterModule.kt +6 -0
- package/android/src/newarch/ReactIntegrationManager.kt +28 -6
- package/android/src/oldarch/HotUpdaterModule.kt +16 -0
- package/android/src/oldarch/ReactIntegrationManager.kt +15 -1
- package/dist/checkForUpdate.d.ts +2 -3
- package/dist/fetchUpdateInfo.d.ts +2 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +68 -47
- package/dist/index.mjs +67 -47
- package/dist/native.d.ts +8 -0
- package/dist/runUpdateProcess.d.ts +4 -5
- package/dist/store.d.ts +1 -1
- package/dist/wrap.d.ts +2 -1
- package/ios/HotUpdater/HotUpdater.mm +68 -5
- package/ios/generated/HotUpdaterSpec/HotUpdaterSpec-generated.mm +7 -0
- package/ios/generated/HotUpdaterSpec/HotUpdaterSpec.h +37 -1
- package/ios/generated/HotUpdaterSpecJSI-generated.cpp +6 -0
- package/ios/generated/HotUpdaterSpecJSI.h +9 -0
- package/package.json +5 -5
- package/src/checkForUpdate.ts +14 -22
- package/src/fetchUpdateInfo.ts +22 -0
- package/src/index.ts +129 -3
- package/src/native.ts +21 -1
- package/src/runUpdateProcess.ts +11 -10
- package/src/specs/NativeHotUpdater.ts +3 -0
- package/src/store.ts +4 -4
- package/src/wrap.tsx +19 -4
- package/dist/ensureUpdateInfo.d.ts +0 -2
- package/src/ensureUpdateInfo.ts +0 -36
package/src/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
addListener,
|
|
4
4
|
getAppVersion,
|
|
5
5
|
getBundleId,
|
|
6
|
+
getChannel,
|
|
7
|
+
getMinBundleId,
|
|
6
8
|
reload,
|
|
7
9
|
updateBundle,
|
|
8
10
|
} from "./native";
|
|
@@ -16,17 +18,112 @@ export type { HotUpdaterEvent } from "./native";
|
|
|
16
18
|
export * from "./store";
|
|
17
19
|
|
|
18
20
|
addListener("onProgress", ({ progress }) => {
|
|
19
|
-
hotUpdaterStore.
|
|
21
|
+
hotUpdaterStore.setState({
|
|
22
|
+
progress,
|
|
23
|
+
});
|
|
20
24
|
});
|
|
21
25
|
|
|
22
26
|
export const HotUpdater = {
|
|
27
|
+
/**
|
|
28
|
+
* `HotUpdater.wrap` checks for updates at the entry point, and if there is a bundle to update, it downloads the bundle and applies the update strategy.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} options - Configuration options
|
|
31
|
+
* @param {string} options.source - Update server URL
|
|
32
|
+
* @param {object} [options.requestHeaders] - Request headers
|
|
33
|
+
* @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
|
|
34
|
+
* @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
|
|
35
|
+
* @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
|
|
36
|
+
* @param {Function} [options.onProgress] - Callback to track bundle download progress
|
|
37
|
+
* @returns {Function} Higher-order component that wraps the app component
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* export default HotUpdater.wrap({
|
|
42
|
+
* source: "<your-update-server-url>",
|
|
43
|
+
* requestHeaders: {
|
|
44
|
+
* "Authorization": "Bearer <your-access-token>",
|
|
45
|
+
* },
|
|
46
|
+
* })(App);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
23
49
|
wrap,
|
|
24
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Reloads the app.
|
|
52
|
+
*/
|
|
25
53
|
reload,
|
|
54
|
+
/**
|
|
55
|
+
* Fetches the current app version.
|
|
56
|
+
*/
|
|
26
57
|
getAppVersion,
|
|
58
|
+
/**
|
|
59
|
+
* Fetches the current bundle ID of the app.
|
|
60
|
+
*/
|
|
27
61
|
getBundleId,
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the initial bundle ID based on the build time of the native app.
|
|
64
|
+
*/
|
|
65
|
+
getMinBundleId,
|
|
66
|
+
/**
|
|
67
|
+
* Fetches the current release channel of the app.
|
|
68
|
+
*
|
|
69
|
+
* By default, if no channel is specified, the app is assigned to the 'production' channel.
|
|
70
|
+
*
|
|
71
|
+
* @returns {string} The current release channel of the app
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const channel = HotUpdater.getChannel();
|
|
76
|
+
* console.log(`Current channel: ${channel}`);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
getChannel,
|
|
80
|
+
/**
|
|
81
|
+
* Adds a listener to HotUpdater events.
|
|
82
|
+
*
|
|
83
|
+
* @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
|
|
84
|
+
* @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
|
|
85
|
+
* @returns {() => void} A cleanup function that removes the event listener
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
|
|
90
|
+
* console.log(`Update progress: ${progress * 100}%`);
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // Unsubscribe when no longer needed
|
|
94
|
+
* unsubscribe();
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
28
97
|
addListener,
|
|
29
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Manually checks for updates.
|
|
100
|
+
*
|
|
101
|
+
* @param {Object} config - Update check configuration
|
|
102
|
+
* @param {string} config.source - Update server URL
|
|
103
|
+
* @param {Record<string, string>} [config.requestHeaders] - Request headers
|
|
104
|
+
*
|
|
105
|
+
* @returns {Promise<UpdateInfo | null>} Update information or null if up to date
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const updateInfo = await HotUpdater.checkForUpdate({
|
|
110
|
+
* source: "<your-update-server-url>",
|
|
111
|
+
* requestHeaders: {
|
|
112
|
+
* Authorization: "Bearer <your-access-token>",
|
|
113
|
+
* },
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* if (!updateInfo) {
|
|
117
|
+
* console.log("App is up to date");
|
|
118
|
+
* return;
|
|
119
|
+
* }
|
|
120
|
+
*
|
|
121
|
+
* await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
|
|
122
|
+
* if (updateInfo.shouldForceUpdate) {
|
|
123
|
+
* HotUpdater.reload();
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
30
127
|
checkForUpdate,
|
|
31
128
|
/**
|
|
32
129
|
* Manually checks and applies updates for the application.
|
|
@@ -61,5 +158,34 @@ export const HotUpdater = {
|
|
|
61
158
|
* @returns {Promise<RunUpdateProcessResponse>} The result of the update process
|
|
62
159
|
*/
|
|
63
160
|
runUpdateProcess,
|
|
161
|
+
/**
|
|
162
|
+
* Updates the bundle of the app.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} bundleId - The bundle ID of the app
|
|
165
|
+
* @param {string} zipUrl - The URL of the zip file
|
|
166
|
+
*
|
|
167
|
+
* @returns {Promise<boolean>} Whether the update was successful
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const updateInfo = await HotUpdater.checkForUpdate({
|
|
172
|
+
* source: "<your-update-server-url>",
|
|
173
|
+
* requestHeaders: {
|
|
174
|
+
* Authorization: "Bearer <your-access-token>",
|
|
175
|
+
* },
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* if (!updateInfo) {
|
|
179
|
+
* return {
|
|
180
|
+
* status: "UP_TO_DATE",
|
|
181
|
+
* };
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
|
|
185
|
+
* if (updateInfo.shouldForceUpdate) {
|
|
186
|
+
* HotUpdater.reload();
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
64
190
|
updateBundle,
|
|
65
191
|
};
|
package/src/native.ts
CHANGED
|
@@ -4,6 +4,7 @@ const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
|
4
4
|
|
|
5
5
|
const HotUpdater = {
|
|
6
6
|
HOT_UPDATER_BUNDLE_ID: NIL_UUID,
|
|
7
|
+
CHANNEL: "production",
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
const LINKING_ERROR =
|
|
@@ -79,6 +80,17 @@ export const reload = () => {
|
|
|
79
80
|
});
|
|
80
81
|
};
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Fetches the minimum bundle id, which represents the initial bundle of the app
|
|
85
|
+
* since it is created at build time.
|
|
86
|
+
*
|
|
87
|
+
* @returns {string} Resolves with the minimum bundle id or null if not available.
|
|
88
|
+
*/
|
|
89
|
+
export const getMinBundleId = (): string => {
|
|
90
|
+
const constants = HotUpdaterNative.getConstants();
|
|
91
|
+
return constants.MIN_BUNDLE_ID;
|
|
92
|
+
};
|
|
93
|
+
|
|
82
94
|
/**
|
|
83
95
|
* Fetches the current bundle version id.
|
|
84
96
|
*
|
|
@@ -86,5 +98,13 @@ export const reload = () => {
|
|
|
86
98
|
* @returns {Promise<string>} Resolves with the current version id or null if not available.
|
|
87
99
|
*/
|
|
88
100
|
export const getBundleId = (): string => {
|
|
89
|
-
|
|
101
|
+
const minBundleId = getMinBundleId();
|
|
102
|
+
|
|
103
|
+
return minBundleId.localeCompare(HotUpdater.HOT_UPDATER_BUNDLE_ID) >= 0
|
|
104
|
+
? minBundleId
|
|
105
|
+
: HotUpdater.HOT_UPDATER_BUNDLE_ID;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const getChannel = (): string => {
|
|
109
|
+
return HotUpdater.CHANNEL;
|
|
90
110
|
};
|
package/src/runUpdateProcess.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { type CheckForUpdateConfig, checkForUpdate } from "./checkForUpdate";
|
|
2
|
-
import { reload, updateBundle } from "./native";
|
|
2
|
+
import { getBundleId, reload, updateBundle } from "./native";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
| {
|
|
11
|
-
status: "UP_TO_DATE";
|
|
12
|
-
};
|
|
4
|
+
export interface RunUpdateProcessResponse {
|
|
5
|
+
status: "ROLLBACK" | "UPDATE" | "UP_TO_DATE";
|
|
6
|
+
shouldForceUpdate: boolean;
|
|
7
|
+
message: string | null;
|
|
8
|
+
id: string;
|
|
9
|
+
}
|
|
13
10
|
|
|
14
11
|
export interface RunUpdateProcessConfig extends CheckForUpdateConfig {
|
|
15
12
|
/**
|
|
@@ -60,6 +57,9 @@ export const runUpdateProcess = async ({
|
|
|
60
57
|
if (!updateInfo) {
|
|
61
58
|
return {
|
|
62
59
|
status: "UP_TO_DATE",
|
|
60
|
+
shouldForceUpdate: false,
|
|
61
|
+
message: null,
|
|
62
|
+
id: getBundleId(),
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -75,5 +75,6 @@ export const runUpdateProcess = async ({
|
|
|
75
75
|
status: updateInfo.status,
|
|
76
76
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
77
77
|
id: updateInfo.id,
|
|
78
|
+
message: updateInfo.message,
|
|
78
79
|
};
|
|
79
80
|
};
|
|
@@ -10,6 +10,9 @@ interface Spec extends TurboModule {
|
|
|
10
10
|
// EventEmitter
|
|
11
11
|
addListener(eventName: string): void;
|
|
12
12
|
removeListeners(count: number): void;
|
|
13
|
+
readonly getConstants: () => {
|
|
14
|
+
MIN_BUNDLE_ID: string;
|
|
15
|
+
};
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export default TurboModuleRegistry.get<Spec>("HotUpdater");
|
package/src/store.ts
CHANGED
|
@@ -24,10 +24,10 @@ const createHotUpdaterStore = () => {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const setState = (newState: Partial<HotUpdaterState>) => {
|
|
28
28
|
state = {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
...state,
|
|
30
|
+
...newState,
|
|
31
31
|
};
|
|
32
32
|
emitChange();
|
|
33
33
|
};
|
|
@@ -37,7 +37,7 @@ const createHotUpdaterStore = () => {
|
|
|
37
37
|
return () => listeners.delete(listener);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
return { getSnapshot,
|
|
40
|
+
return { getSnapshot, setState, subscribe };
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export const hotUpdaterStore = createHotUpdaterStore();
|
package/src/wrap.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { useEffect, useLayoutEffect, useState } from "react";
|
|
3
3
|
import { type CheckForUpdateConfig, checkForUpdate } from "./checkForUpdate";
|
|
4
4
|
import { HotUpdaterError } from "./error";
|
|
5
5
|
import { useEventCallback } from "./hooks/useEventCallback";
|
|
6
|
-
import { reload, updateBundle } from "./native";
|
|
6
|
+
import { getBundleId, reload, updateBundle } from "./native";
|
|
7
7
|
import type { RunUpdateProcessResponse } from "./runUpdateProcess";
|
|
8
8
|
import { useHotUpdaterStore } from "./store";
|
|
9
9
|
|
|
@@ -37,6 +37,7 @@ export interface HotUpdaterConfig extends CheckForUpdateConfig {
|
|
|
37
37
|
fallbackComponent?: React.FC<{
|
|
38
38
|
status: Exclude<UpdateStatus, "UPDATE_PROCESS_COMPLETED">;
|
|
39
39
|
progress: number;
|
|
40
|
+
message: string | null;
|
|
40
41
|
}>;
|
|
41
42
|
onError?: (error: HotUpdaterError) => void;
|
|
42
43
|
onProgress?: (progress: number) => void;
|
|
@@ -62,9 +63,10 @@ export function wrap<P>(
|
|
|
62
63
|
return (WrappedComponent) => {
|
|
63
64
|
const HotUpdaterHOC: React.FC<P> = () => {
|
|
64
65
|
const progress = useHotUpdaterStore((state) => state.progress);
|
|
66
|
+
|
|
67
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
65
68
|
const [updateStatus, setUpdateStatus] =
|
|
66
69
|
useState<UpdateStatus>("CHECK_FOR_UPDATE");
|
|
67
|
-
|
|
68
70
|
const initHotUpdater = useEventCallback(async () => {
|
|
69
71
|
try {
|
|
70
72
|
setUpdateStatus("CHECK_FOR_UPDATE");
|
|
@@ -72,9 +74,14 @@ export function wrap<P>(
|
|
|
72
74
|
source: restConfig.source,
|
|
73
75
|
requestHeaders: restConfig.requestHeaders,
|
|
74
76
|
});
|
|
77
|
+
setMessage(updateInfo?.message ?? null);
|
|
78
|
+
|
|
75
79
|
if (!updateInfo) {
|
|
76
80
|
restConfig.onUpdateProcessCompleted?.({
|
|
77
81
|
status: "UP_TO_DATE",
|
|
82
|
+
shouldForceUpdate: false,
|
|
83
|
+
message: null,
|
|
84
|
+
id: getBundleId(),
|
|
78
85
|
});
|
|
79
86
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
80
87
|
return;
|
|
@@ -86,6 +93,7 @@ export function wrap<P>(
|
|
|
86
93
|
id: updateInfo.id,
|
|
87
94
|
status: updateInfo.status,
|
|
88
95
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
96
|
+
message: updateInfo.message,
|
|
89
97
|
});
|
|
90
98
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
91
99
|
return;
|
|
@@ -111,6 +119,7 @@ export function wrap<P>(
|
|
|
111
119
|
id: updateInfo.id,
|
|
112
120
|
status: updateInfo.status,
|
|
113
121
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
122
|
+
message: updateInfo.message,
|
|
114
123
|
});
|
|
115
124
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
116
125
|
} catch (error) {
|
|
@@ -135,7 +144,13 @@ export function wrap<P>(
|
|
|
135
144
|
updateStatus !== "UPDATE_PROCESS_COMPLETED"
|
|
136
145
|
) {
|
|
137
146
|
const Fallback = restConfig.fallbackComponent;
|
|
138
|
-
return
|
|
147
|
+
return (
|
|
148
|
+
<Fallback
|
|
149
|
+
progress={progress}
|
|
150
|
+
status={updateStatus}
|
|
151
|
+
message={message}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
139
154
|
}
|
|
140
155
|
|
|
141
156
|
return <WrappedComponent />;
|
package/src/ensureUpdateInfo.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Bundle,
|
|
3
|
-
BundleArg,
|
|
4
|
-
GetBundlesArgs,
|
|
5
|
-
UpdateInfo,
|
|
6
|
-
} from "@hot-updater/core";
|
|
7
|
-
|
|
8
|
-
export const ensureUpdateInfo = async (
|
|
9
|
-
source: BundleArg,
|
|
10
|
-
{ appVersion, bundleId, platform }: GetBundlesArgs,
|
|
11
|
-
requestHeaders?: Record<string, string>,
|
|
12
|
-
): Promise<Bundle[] | UpdateInfo> => {
|
|
13
|
-
try {
|
|
14
|
-
let bundles: Bundle[] | null = null;
|
|
15
|
-
if (typeof source === "string") {
|
|
16
|
-
if (source.startsWith("http")) {
|
|
17
|
-
return await fetch(source, {
|
|
18
|
-
headers: {
|
|
19
|
-
"x-app-platform": platform,
|
|
20
|
-
"x-app-version": appVersion,
|
|
21
|
-
"x-bundle-id": bundleId,
|
|
22
|
-
...requestHeaders,
|
|
23
|
-
},
|
|
24
|
-
}).then((res) => res.json());
|
|
25
|
-
}
|
|
26
|
-
} else if (typeof source === "function") {
|
|
27
|
-
bundles = await source();
|
|
28
|
-
} else {
|
|
29
|
-
bundles = source;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return bundles ?? [];
|
|
33
|
-
} catch {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
};
|