react-native-update 10.2.4 → 10.2.5
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 +14 -9
- 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.5",
|
|
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
|
@@ -34,6 +34,7 @@ export const PushyProvider = ({
|
|
|
34
34
|
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
|
|
35
35
|
const [progress, setProgress] = useState<ProgressData>();
|
|
36
36
|
const [lastError, setLastError] = useState<Error>();
|
|
37
|
+
const lastChecking = useRef(0);
|
|
37
38
|
|
|
38
39
|
const dismissError = useCallback(() => {
|
|
39
40
|
setLastError(undefined);
|
|
@@ -86,9 +87,9 @@ export const PushyProvider = ({
|
|
|
86
87
|
},
|
|
87
88
|
},
|
|
88
89
|
]);
|
|
89
|
-
} catch (
|
|
90
|
-
setLastError(
|
|
91
|
-
showAlert('更新失败',
|
|
90
|
+
} catch (e: any) {
|
|
91
|
+
setLastError(e);
|
|
92
|
+
showAlert('更新失败', e.message);
|
|
92
93
|
}
|
|
93
94
|
}, [client, showAlert, updateInfo]);
|
|
94
95
|
|
|
@@ -102,12 +103,17 @@ export const PushyProvider = ({
|
|
|
102
103
|
);
|
|
103
104
|
|
|
104
105
|
const checkUpdate = useCallback(async () => {
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
if (lastChecking.current && now - lastChecking.current < 1000) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
lastChecking.current = now;
|
|
105
111
|
let info: CheckResult;
|
|
106
112
|
try {
|
|
107
113
|
info = await client.checkUpdate();
|
|
108
|
-
} catch (
|
|
109
|
-
setLastError(
|
|
110
|
-
showAlert('更新检查失败',
|
|
114
|
+
} catch (e: any) {
|
|
115
|
+
setLastError(e);
|
|
116
|
+
showAlert('更新检查失败', e.message);
|
|
111
117
|
return;
|
|
112
118
|
}
|
|
113
119
|
setUpdateInfo(info);
|
|
@@ -159,7 +165,7 @@ export const PushyProvider = ({
|
|
|
159
165
|
if (strategy === 'both' || strategy === 'onAppResume') {
|
|
160
166
|
stateListener.current = AppState.addEventListener(
|
|
161
167
|
'change',
|
|
162
|
-
|
|
168
|
+
nextAppState => {
|
|
163
169
|
if (nextAppState === 'active') {
|
|
164
170
|
checkUpdate();
|
|
165
171
|
}
|
|
@@ -198,8 +204,7 @@ export const PushyProvider = ({
|
|
|
198
204
|
progress,
|
|
199
205
|
downloadAndInstallApk,
|
|
200
206
|
getCurrentVersionInfo,
|
|
201
|
-
}}
|
|
202
|
-
>
|
|
207
|
+
}}>
|
|
203
208
|
{children}
|
|
204
209
|
</PushyContext.Provider>
|
|
205
210
|
);
|
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