react-native-update 10.2.4 → 10.2.6
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/.eslintrc.js +4 -0
- package/.github/workflows/scripts/functions/src/testFunctionDefaultRegion.ts +5 -2
- package/.prettierrc.js +3 -1
- package/babel.config.js +3 -0
- package/package.json +9 -4
- package/src/client.tsx +11 -10
- package/src/core.ts +3 -1
- package/src/provider.tsx +43 -33
- package/src/utils.ts +2 -3
- package/tsconfig.json +4 -0
package/.eslintrc.js
ADDED
|
@@ -41,14 +41,17 @@ export const testFunctionDefaultRegion = functions.https.onCall(data => {
|
|
|
41
41
|
|
|
42
42
|
const { type, asError, inputData } = data;
|
|
43
43
|
if (!Object.hasOwnProperty.call(SAMPLE_DATA, type)) {
|
|
44
|
-
throw new functions.https.HttpsError(
|
|
44
|
+
throw new functions.https.HttpsError(
|
|
45
|
+
'invalid-argument',
|
|
46
|
+
'Invalid test requested.',
|
|
47
|
+
);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
const outputData = SAMPLE_DATA[type];
|
|
48
51
|
|
|
49
52
|
try {
|
|
50
53
|
assert.deepEqual(outputData, inputData);
|
|
51
|
-
} catch (e) {
|
|
54
|
+
} catch (e: any) {
|
|
52
55
|
console.error(e);
|
|
53
56
|
throw new functions.https.HttpsError(
|
|
54
57
|
'invalid-argument',
|
package/.prettierrc.js
CHANGED
package/babel.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.6",
|
|
4
4
|
"description": "react-native hot update",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"prepack": "yarn submodule && yarn lint",
|
|
8
|
+
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
|
|
8
9
|
"submodule": "git submodule update --init --recursive",
|
|
9
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
11
|
"build-lib": "yarn submodule && $ANDROID_HOME/ndk/20.1.5948944/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_APPLICATION_MK=android/jni/Application.mk NDK_LIBS_OUT=android/lib",
|
|
@@ -56,16 +57,20 @@
|
|
|
56
57
|
]
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
60
|
+
"@babel/core": "^7.24.0",
|
|
61
|
+
"@react-native/babel-preset": "^0.73.21",
|
|
59
62
|
"@react-native/eslint-config": "^0.73.2",
|
|
63
|
+
"@react-native/typescript-config": "^0.74.0",
|
|
60
64
|
"@types/fs-extra": "^9.0.13",
|
|
61
65
|
"@types/jest": "^29.2.1",
|
|
62
66
|
"@types/node": "^20.8.9",
|
|
63
67
|
"@types/react": "^18.2.46",
|
|
64
68
|
"detox": "^20.5.0",
|
|
65
|
-
"eslint": "^8.
|
|
69
|
+
"eslint": "^8.57.0",
|
|
70
|
+
"eslint-plugin-ft-flow": "^3.0.7",
|
|
66
71
|
"firebase-tools": "^11.24.1",
|
|
67
72
|
"fs-extra": "^9.1.0",
|
|
68
|
-
"jest": "^29.
|
|
73
|
+
"jest": "^29.7.0",
|
|
69
74
|
"pod-install": "^0.1.37",
|
|
70
75
|
"prettier": "^2",
|
|
71
76
|
"react": "18.2.0",
|
package/src/client.tsx
CHANGED
|
@@ -37,11 +37,11 @@ export class Pushy {
|
|
|
37
37
|
logger: noop,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
lastChecking
|
|
40
|
+
lastChecking?: number;
|
|
41
41
|
lastRespJson?: Promise<any>;
|
|
42
42
|
|
|
43
43
|
progressHandlers: Record<string, EmitterSubscription> = {};
|
|
44
|
-
downloadedHash
|
|
44
|
+
downloadedHash?: string;
|
|
45
45
|
|
|
46
46
|
marked = false;
|
|
47
47
|
applyingUpdate = false;
|
|
@@ -57,6 +57,7 @@ export class Pushy {
|
|
|
57
57
|
setOptions = (options: Partial<PushyOptions>) => {
|
|
58
58
|
for (const [key, value] of Object.entries(options)) {
|
|
59
59
|
if (value !== undefined) {
|
|
60
|
+
// @ts-expect-error
|
|
60
61
|
this.options[key] = value;
|
|
61
62
|
if (key === 'logger') {
|
|
62
63
|
if (isRolledBack) {
|
|
@@ -163,7 +164,7 @@ export class Pushy {
|
|
|
163
164
|
let resp;
|
|
164
165
|
try {
|
|
165
166
|
resp = await fetch(this.getCheckUrl(), fetchPayload);
|
|
166
|
-
} catch (e) {
|
|
167
|
+
} catch (e: any) {
|
|
167
168
|
this.report({
|
|
168
169
|
type: 'errorChecking',
|
|
169
170
|
message: 'Can not connect to update server. Trying backup endpoints.',
|
|
@@ -172,7 +173,7 @@ export class Pushy {
|
|
|
172
173
|
if (backupEndpoints) {
|
|
173
174
|
try {
|
|
174
175
|
resp = await Promise.race(
|
|
175
|
-
backupEndpoints.map(
|
|
176
|
+
backupEndpoints.map(endpoint =>
|
|
176
177
|
fetch(this.getCheckUrl(endpoint), fetchPayload),
|
|
177
178
|
),
|
|
178
179
|
);
|
|
@@ -214,7 +215,7 @@ export class Pushy {
|
|
|
214
215
|
new Set([...(server.backups || []), ...remoteEndpoints]),
|
|
215
216
|
);
|
|
216
217
|
}
|
|
217
|
-
} catch (e) {
|
|
218
|
+
} catch (e: any) {
|
|
218
219
|
log('failed to fetch endpoints from: ', server.queryUrl);
|
|
219
220
|
}
|
|
220
221
|
}
|
|
@@ -254,7 +255,7 @@ export class Pushy {
|
|
|
254
255
|
if (onDownloadProgress) {
|
|
255
256
|
this.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
|
|
256
257
|
'RCTPushyDownloadProgress',
|
|
257
|
-
|
|
258
|
+
progressData => {
|
|
258
259
|
if (progressData.hash === hash) {
|
|
259
260
|
onDownloadProgress(progressData);
|
|
260
261
|
}
|
|
@@ -273,7 +274,7 @@ export class Pushy {
|
|
|
273
274
|
originHash: currentVersion,
|
|
274
275
|
});
|
|
275
276
|
succeeded = true;
|
|
276
|
-
} catch (e) {
|
|
277
|
+
} catch (e: any) {
|
|
277
278
|
log(`diff error: ${e.message}, try pdiff`);
|
|
278
279
|
}
|
|
279
280
|
}
|
|
@@ -286,7 +287,7 @@ export class Pushy {
|
|
|
286
287
|
hash,
|
|
287
288
|
});
|
|
288
289
|
succeeded = true;
|
|
289
|
-
} catch (e) {
|
|
290
|
+
} catch (e: any) {
|
|
290
291
|
log(`pdiff error: ${e.message}, try full patch`);
|
|
291
292
|
}
|
|
292
293
|
}
|
|
@@ -299,7 +300,7 @@ export class Pushy {
|
|
|
299
300
|
hash,
|
|
300
301
|
});
|
|
301
302
|
succeeded = true;
|
|
302
|
-
} catch (e) {
|
|
303
|
+
} catch (e: any) {
|
|
303
304
|
log(`full patch error: ${e.message}`);
|
|
304
305
|
}
|
|
305
306
|
}
|
|
@@ -338,7 +339,7 @@ export class Pushy {
|
|
|
338
339
|
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
|
|
339
340
|
return this.report({ type: 'rejectStoragePermission' });
|
|
340
341
|
}
|
|
341
|
-
} catch (
|
|
342
|
+
} catch (e: any) {
|
|
342
343
|
return this.report({ type: 'errorStoragePermission' });
|
|
343
344
|
}
|
|
344
345
|
}
|
package/src/core.ts
CHANGED
|
@@ -4,7 +4,9 @@ const {
|
|
|
4
4
|
version: v,
|
|
5
5
|
} = require('react-native/Libraries/Core/ReactNativeVersion');
|
|
6
6
|
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
|
|
7
|
-
const isTurboModuleEnabled =
|
|
7
|
+
const isTurboModuleEnabled =
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
global.__turboModuleProxy != null;
|
|
8
10
|
|
|
9
11
|
export const PushyModule = isTurboModuleEnabled
|
|
10
12
|
? require('./turboModuleSpec').default
|
package/src/provider.tsx
CHANGED
|
@@ -32,8 +32,10 @@ export const PushyProvider = ({
|
|
|
32
32
|
const { options } = client;
|
|
33
33
|
const stateListener = useRef<NativeEventSubscription>();
|
|
34
34
|
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
|
|
35
|
+
const updateInfoRef = useRef(updateInfo);
|
|
35
36
|
const [progress, setProgress] = useState<ProgressData>();
|
|
36
37
|
const [lastError, setLastError] = useState<Error>();
|
|
38
|
+
const lastChecking = useRef(0);
|
|
37
39
|
|
|
38
40
|
const dismissError = useCallback(() => {
|
|
39
41
|
setLastError(undefined);
|
|
@@ -60,37 +62,40 @@ export const PushyProvider = ({
|
|
|
60
62
|
}
|
|
61
63
|
}, [client, updateInfo]);
|
|
62
64
|
|
|
63
|
-
const downloadUpdate = useCallback(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const hash = await client.downloadUpdate(updateInfo, setProgress);
|
|
69
|
-
if (!hash) {
|
|
65
|
+
const downloadUpdate = useCallback(
|
|
66
|
+
async (info: CheckResult | undefined = updateInfoRef.current) => {
|
|
67
|
+
if (!info || !info.update) {
|
|
70
68
|
return;
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
try {
|
|
71
|
+
const hash = await client.downloadUpdate(info, setProgress);
|
|
72
|
+
if (!hash) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
stateListener.current && stateListener.current.remove();
|
|
76
|
+
showAlert('提示', '下载完毕,是否立即更新?', [
|
|
77
|
+
{
|
|
78
|
+
text: '下次再说',
|
|
79
|
+
style: 'cancel',
|
|
80
|
+
onPress: () => {
|
|
81
|
+
client.switchVersionLater(hash);
|
|
82
|
+
},
|
|
79
83
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
{
|
|
85
|
+
text: '立即更新',
|
|
86
|
+
style: 'default',
|
|
87
|
+
onPress: () => {
|
|
88
|
+
client.switchVersion(hash);
|
|
89
|
+
},
|
|
86
90
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
91
|
+
]);
|
|
92
|
+
} catch (e: any) {
|
|
93
|
+
setLastError(e);
|
|
94
|
+
showAlert('更新失败', e.message);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
[client, showAlert],
|
|
98
|
+
);
|
|
94
99
|
|
|
95
100
|
const downloadAndInstallApk = useCallback(
|
|
96
101
|
async (downloadUrl: string) => {
|
|
@@ -102,14 +107,20 @@ export const PushyProvider = ({
|
|
|
102
107
|
);
|
|
103
108
|
|
|
104
109
|
const checkUpdate = useCallback(async () => {
|
|
110
|
+
const now = Date.now();
|
|
111
|
+
if (lastChecking.current && now - lastChecking.current < 1000) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
lastChecking.current = now;
|
|
105
115
|
let info: CheckResult;
|
|
106
116
|
try {
|
|
107
117
|
info = await client.checkUpdate();
|
|
108
|
-
} catch (
|
|
109
|
-
setLastError(
|
|
110
|
-
showAlert('更新检查失败',
|
|
118
|
+
} catch (e: any) {
|
|
119
|
+
setLastError(e);
|
|
120
|
+
showAlert('更新检查失败', e.message);
|
|
111
121
|
return;
|
|
112
122
|
}
|
|
123
|
+
updateInfoRef.current = info;
|
|
113
124
|
setUpdateInfo(info);
|
|
114
125
|
if (info.expired) {
|
|
115
126
|
const { downloadUrl } = info;
|
|
@@ -159,7 +170,7 @@ export const PushyProvider = ({
|
|
|
159
170
|
if (strategy === 'both' || strategy === 'onAppResume') {
|
|
160
171
|
stateListener.current = AppState.addEventListener(
|
|
161
172
|
'change',
|
|
162
|
-
|
|
173
|
+
nextAppState => {
|
|
163
174
|
if (nextAppState === 'active') {
|
|
164
175
|
checkUpdate();
|
|
165
176
|
}
|
|
@@ -198,8 +209,7 @@ export const PushyProvider = ({
|
|
|
198
209
|
progress,
|
|
199
210
|
downloadAndInstallApk,
|
|
200
211
|
getCurrentVersionInfo,
|
|
201
|
-
}}
|
|
202
|
-
>
|
|
212
|
+
}}>
|
|
203
213
|
{children}
|
|
204
214
|
</PushyContext.Provider>
|
|
205
215
|
);
|
package/src/utils.ts
CHANGED
|
@@ -12,9 +12,8 @@ const ping = async (url: string) =>
|
|
|
12
12
|
Promise.race([
|
|
13
13
|
fetch(url, {
|
|
14
14
|
method: 'HEAD',
|
|
15
|
-
redirect: 'follow',
|
|
16
15
|
}).then(({ status }) => status === 200),
|
|
17
|
-
new Promise<false>(
|
|
16
|
+
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
|
18
17
|
]);
|
|
19
18
|
|
|
20
19
|
const canUseGoogle = ping('https://www.google.com');
|
|
@@ -23,7 +22,7 @@ export const testUrls = async (urls?: string[]) => {
|
|
|
23
22
|
if (!urls?.length || (await canUseGoogle)) {
|
|
24
23
|
return null;
|
|
25
24
|
}
|
|
26
|
-
return Promise.race(urls.map(
|
|
25
|
+
return Promise.race(urls.map(url => ping(url).then(() => url))).catch(
|
|
27
26
|
() => null,
|
|
28
27
|
);
|
|
29
28
|
};
|
package/tsconfig.json
ADDED