@hot-updater/react-native 0.16.1 → 0.16.2
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/checkForUpdate.d.ts +2 -1
- package/dist/fetchUpdateInfo.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/dist/wrap.d.ts +1 -1
- package/package.json +3 -3
- package/src/checkForUpdate.ts +2 -2
- package/src/fetchUpdateInfo.ts +7 -1
- package/src/wrap.tsx +12 -6
package/dist/checkForUpdate.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { AppUpdateInfo, GetBundlesArgs } from "@hot-updater/core";
|
|
2
|
-
export
|
|
2
|
+
export type UpdateSource = string | (() => Promise<AppUpdateInfo | null>);
|
|
3
|
+
export declare const fetchUpdateInfo: (source: UpdateSource, { appVersion, bundleId, platform, minBundleId, channel }: GetBundlesArgs, requestHeaders?: Record<string, string>, onError?: (error: Error) => void, requestTimeout?: number) => Promise<AppUpdateInfo | null>;
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,7 @@ var __webpack_exports__ = {};
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBundleId, channel }, requestHeaders, onError, requestTimeout = 5000)=>{
|
|
70
|
+
if ("function" == typeof source) return source();
|
|
70
71
|
const controller = new AbortController();
|
|
71
72
|
const timeoutId = setTimeout(()=>{
|
|
72
73
|
controller.abort();
|
|
@@ -237,7 +238,7 @@ var __webpack_exports__ = {};
|
|
|
237
238
|
function wrap(options) {
|
|
238
239
|
const { reloadOnForceUpdate = true, ...restOptions } = options;
|
|
239
240
|
return (WrappedComponent)=>{
|
|
240
|
-
const HotUpdaterHOC = ()=>{
|
|
241
|
+
const HotUpdaterHOC = (props)=>{
|
|
241
242
|
const progress = useHotUpdaterStore((state)=>state.progress);
|
|
242
243
|
const [message, setMessage] = (0, external_react_namespaceObject.useState)(null);
|
|
243
244
|
const [updateStatus, setUpdateStatus] = (0, external_react_namespaceObject.useState)("CHECK_FOR_UPDATE");
|
|
@@ -304,7 +305,7 @@ var __webpack_exports__ = {};
|
|
|
304
305
|
message: message
|
|
305
306
|
});
|
|
306
307
|
}
|
|
307
|
-
return /*#__PURE__*/ external_react_default().createElement(WrappedComponent,
|
|
308
|
+
return /*#__PURE__*/ external_react_default().createElement(WrappedComponent, props);
|
|
308
309
|
};
|
|
309
310
|
return HotUpdaterHOC;
|
|
310
311
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -42,6 +42,7 @@ class HotUpdaterError extends Error {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBundleId, channel }, requestHeaders, onError, requestTimeout = 5000)=>{
|
|
45
|
+
if ("function" == typeof source) return source();
|
|
45
46
|
const controller = new AbortController();
|
|
46
47
|
const timeoutId = setTimeout(()=>{
|
|
47
48
|
controller.abort();
|
|
@@ -208,7 +209,7 @@ function useEventCallback(fn) {
|
|
|
208
209
|
function wrap(options) {
|
|
209
210
|
const { reloadOnForceUpdate = true, ...restOptions } = options;
|
|
210
211
|
return (WrappedComponent)=>{
|
|
211
|
-
const HotUpdaterHOC = ()=>{
|
|
212
|
+
const HotUpdaterHOC = (props)=>{
|
|
212
213
|
const progress = useHotUpdaterStore((state)=>state.progress);
|
|
213
214
|
const [message, setMessage] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(null);
|
|
214
215
|
const [updateStatus, setUpdateStatus] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)("CHECK_FOR_UPDATE");
|
|
@@ -275,7 +276,7 @@ function wrap(options) {
|
|
|
275
276
|
message: message
|
|
276
277
|
});
|
|
277
278
|
}
|
|
278
|
-
return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(WrappedComponent,
|
|
279
|
+
return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(WrappedComponent, props);
|
|
279
280
|
};
|
|
280
281
|
return HotUpdaterHOC;
|
|
281
282
|
};
|
package/dist/wrap.d.ts
CHANGED
|
@@ -46,5 +46,5 @@ export interface HotUpdaterOptions extends CheckForUpdateOptions {
|
|
|
46
46
|
*/
|
|
47
47
|
onUpdateProcessCompleted?: (response: RunUpdateProcessResponse) => void;
|
|
48
48
|
}
|
|
49
|
-
export declare function wrap<P>(options: HotUpdaterOptions): (WrappedComponent: React.ComponentType) => React.ComponentType<P>;
|
|
49
|
+
export declare function wrap<P extends React.JSX.IntrinsicAttributes = object>(options: HotUpdaterOptions): (WrappedComponent: React.ComponentType<P>) => React.ComponentType<P>;
|
|
50
50
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/react-native",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "React Native OTA solution for self-hosted",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"use-sync-external-store": "1.4.0",
|
|
84
|
-
"@hot-updater/js": "0.16.
|
|
85
|
-
"@hot-updater/core": "0.16.
|
|
84
|
+
"@hot-updater/js": "0.16.2",
|
|
85
|
+
"@hot-updater/core": "0.16.2"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "rslib build",
|
package/src/checkForUpdate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Platform } from "react-native";
|
|
2
2
|
import { HotUpdaterError } from "./error";
|
|
3
|
-
import { fetchUpdateInfo } from "./fetchUpdateInfo";
|
|
3
|
+
import { type UpdateSource, fetchUpdateInfo } from "./fetchUpdateInfo";
|
|
4
4
|
import {
|
|
5
5
|
getAppVersion,
|
|
6
6
|
getBundleId,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./native";
|
|
10
10
|
|
|
11
11
|
export interface CheckForUpdateOptions {
|
|
12
|
-
source:
|
|
12
|
+
source: UpdateSource;
|
|
13
13
|
requestHeaders?: Record<string, string>;
|
|
14
14
|
onError?: (error: Error) => void;
|
|
15
15
|
/**
|
package/src/fetchUpdateInfo.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { AppUpdateInfo, GetBundlesArgs } from "@hot-updater/core";
|
|
2
2
|
|
|
3
|
+
export type UpdateSource = string | (() => Promise<AppUpdateInfo | null>);
|
|
4
|
+
|
|
3
5
|
export const fetchUpdateInfo = async (
|
|
4
|
-
source:
|
|
6
|
+
source: UpdateSource,
|
|
5
7
|
{ appVersion, bundleId, platform, minBundleId, channel }: GetBundlesArgs,
|
|
6
8
|
requestHeaders?: Record<string, string>,
|
|
7
9
|
onError?: (error: Error) => void,
|
|
8
10
|
requestTimeout = 5000,
|
|
9
11
|
): Promise<AppUpdateInfo | null> => {
|
|
12
|
+
if (typeof source === "function") {
|
|
13
|
+
return source();
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
const controller = new AbortController();
|
|
11
17
|
const timeoutId = setTimeout(() => {
|
|
12
18
|
controller.abort();
|
package/src/wrap.tsx
CHANGED
|
@@ -56,25 +56,29 @@ export interface HotUpdaterOptions extends CheckForUpdateOptions {
|
|
|
56
56
|
onUpdateProcessCompleted?: (response: RunUpdateProcessResponse) => void;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export function wrap<P>(
|
|
59
|
+
export function wrap<P extends React.JSX.IntrinsicAttributes = object>(
|
|
60
60
|
options: HotUpdaterOptions,
|
|
61
|
-
): (WrappedComponent: React.ComponentType) => React.ComponentType<P> {
|
|
61
|
+
): (WrappedComponent: React.ComponentType<P>) => React.ComponentType<P> {
|
|
62
62
|
const { reloadOnForceUpdate = true, ...restOptions } = options;
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
|
|
64
|
+
return (WrappedComponent: React.ComponentType<P>) => {
|
|
65
|
+
const HotUpdaterHOC: React.FC<P> = (props: P) => {
|
|
65
66
|
const progress = useHotUpdaterStore((state) => state.progress);
|
|
66
67
|
|
|
67
68
|
const [message, setMessage] = useState<string | null>(null);
|
|
68
69
|
const [updateStatus, setUpdateStatus] =
|
|
69
70
|
useState<UpdateStatus>("CHECK_FOR_UPDATE");
|
|
71
|
+
|
|
70
72
|
const initHotUpdater = useEventCallback(async () => {
|
|
71
73
|
try {
|
|
72
74
|
setUpdateStatus("CHECK_FOR_UPDATE");
|
|
75
|
+
|
|
73
76
|
const updateInfo = await checkForUpdate({
|
|
74
77
|
source: restOptions.source,
|
|
75
78
|
requestHeaders: restOptions.requestHeaders,
|
|
76
79
|
onError: restOptions.onError,
|
|
77
80
|
});
|
|
81
|
+
|
|
78
82
|
setMessage(updateInfo?.message ?? null);
|
|
79
83
|
|
|
80
84
|
if (!updateInfo) {
|
|
@@ -106,6 +110,7 @@ export function wrap<P>(
|
|
|
106
110
|
updateInfo.id,
|
|
107
111
|
updateInfo.fileUrl,
|
|
108
112
|
);
|
|
113
|
+
|
|
109
114
|
if (!isSuccess) {
|
|
110
115
|
throw new Error(
|
|
111
116
|
"New update was found but failed to download the bundle.",
|
|
@@ -122,6 +127,7 @@ export function wrap<P>(
|
|
|
122
127
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
123
128
|
message: updateInfo.message,
|
|
124
129
|
});
|
|
130
|
+
|
|
125
131
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
126
132
|
} catch (error) {
|
|
127
133
|
if (error instanceof HotUpdaterError) {
|
|
@@ -154,9 +160,9 @@ export function wrap<P>(
|
|
|
154
160
|
);
|
|
155
161
|
}
|
|
156
162
|
|
|
157
|
-
return <WrappedComponent />;
|
|
163
|
+
return <WrappedComponent {...props} />;
|
|
158
164
|
};
|
|
159
165
|
|
|
160
|
-
return HotUpdaterHOC
|
|
166
|
+
return HotUpdaterHOC as React.ComponentType<P>;
|
|
161
167
|
};
|
|
162
168
|
}
|