react-native-update 10.15.2 → 10.15.3
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/README.md +1 -1
- package/package.json +1 -1
- package/src/client.ts +4 -7
- package/src/utils.ts +21 -5
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
1. 对中国用户使用阿里云高速 CDN 分发,对比其他服务器在国外的热更新服务,分发更稳定,更新成功率极高。对国外用户则智能分流至 cloudflare,同样享受高速更新服务。
|
|
12
12
|
2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在几十 KB 级别(其他全量热更新服务所需流量通常在几十 MB 级别)。
|
|
13
|
-
3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes
|
|
13
|
+
3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。支持新架构(注:安卓 0.73.0 ~ 0.76.0 的新架构因官方 bug 不支持,0.73 以下或 0.76.1 以上的新架构可用)。
|
|
14
14
|
4. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
|
|
15
15
|
5. 命令行工具 & 网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
|
|
16
16
|
6. 支持崩溃回滚,安全可靠。
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
|
2
|
-
import { joinUrls, log, testUrls } from './utils';
|
|
2
|
+
import { emptyObj, joinUrls, log, noop, promiseAny, testUrls } from './utils';
|
|
3
3
|
import { EmitterSubscription, Platform } from 'react-native';
|
|
4
4
|
import { PermissionsAndroid } from './permissions';
|
|
5
5
|
import {
|
|
@@ -24,9 +24,6 @@ const defaultServer = {
|
|
|
24
24
|
],
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const empty = {};
|
|
28
|
-
const noop = () => {};
|
|
29
|
-
|
|
30
27
|
if (Platform.OS === 'web') {
|
|
31
28
|
console.warn('react-native-update 不支持 web 端热更,不会执行操作');
|
|
32
29
|
}
|
|
@@ -230,7 +227,7 @@ export class Pushy {
|
|
|
230
227
|
const backupEndpoints = await this.getBackupEndpoints();
|
|
231
228
|
if (backupEndpoints) {
|
|
232
229
|
try {
|
|
233
|
-
resp = await
|
|
230
|
+
resp = await promiseAny(
|
|
234
231
|
backupEndpoints.map(endpoint =>
|
|
235
232
|
fetch(this.getCheckUrl(endpoint), fetchPayload),
|
|
236
233
|
),
|
|
@@ -248,7 +245,7 @@ export class Pushy {
|
|
|
248
245
|
message: 'Can not connect to update server. Please check your network.',
|
|
249
246
|
});
|
|
250
247
|
this.throwIfEnabled(new Error('errorChecking'));
|
|
251
|
-
return this.lastRespJson ? await this.lastRespJson :
|
|
248
|
+
return this.lastRespJson ? await this.lastRespJson : emptyObj;
|
|
252
249
|
}
|
|
253
250
|
this.lastRespJson = resp.json();
|
|
254
251
|
|
|
@@ -273,7 +270,7 @@ export class Pushy {
|
|
|
273
270
|
}
|
|
274
271
|
if (server.queryUrls) {
|
|
275
272
|
try {
|
|
276
|
-
const resp = await
|
|
273
|
+
const resp = await promiseAny(
|
|
277
274
|
server.queryUrls.map(queryUrl => fetch(queryUrl)),
|
|
278
275
|
);
|
|
279
276
|
const remoteEndpoints = await resp.json();
|
package/src/utils.ts
CHANGED
|
@@ -4,7 +4,25 @@ export function log(...args: any[]) {
|
|
|
4
4
|
console.log('pushy: ', ...args);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export function promiseAny<T>(promises: Promise<T>[]) {
|
|
8
|
+
return new Promise<T>((resolve, reject) => {
|
|
9
|
+
let count = 0;
|
|
10
|
+
|
|
11
|
+
promises.forEach(promise => {
|
|
12
|
+
Promise.resolve(promise)
|
|
13
|
+
.then(resolve)
|
|
14
|
+
.catch(() => {
|
|
15
|
+
count++;
|
|
16
|
+
if (count === promises.length) {
|
|
17
|
+
reject(new Error('All promises were rejected'));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const emptyObj = {};
|
|
25
|
+
export const noop = () => {};
|
|
8
26
|
class EmptyModule {
|
|
9
27
|
constructor() {
|
|
10
28
|
return new Proxy(this, {
|
|
@@ -23,9 +41,7 @@ const ping =
|
|
|
23
41
|
Promise.race([
|
|
24
42
|
fetch(url, {
|
|
25
43
|
method: 'HEAD',
|
|
26
|
-
})
|
|
27
|
-
.then(({ status }) => (status === 200 ? url : null))
|
|
28
|
-
.catch(() => null),
|
|
44
|
+
}).then(({ status }) => (status === 200 ? url : null)),
|
|
29
45
|
new Promise(r => setTimeout(() => r(null), 2000)),
|
|
30
46
|
]);
|
|
31
47
|
|
|
@@ -44,5 +60,5 @@ export const testUrls = async (urls?: string[]) => {
|
|
|
44
60
|
if (await canUseGoogle) {
|
|
45
61
|
return urls[0];
|
|
46
62
|
}
|
|
47
|
-
return
|
|
63
|
+
return promiseAny(urls.map(ping)).catch(() => null);
|
|
48
64
|
};
|