react-native-update 9.0.0 → 9.0.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/lib/main.ts +20 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  1. 基于阿里云高速 CDN 分发,对比其他服务器在国外的热更新服务,分发更稳定,更新成功率极高。
12
12
  2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在几十 KB 级别(其他全量热更新服务所需流量通常在几十 MB 级别)。
13
- 3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。(暂不支持新架构,会待其相对稳定后跟进)
13
+ 3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。支持新架构。
14
14
  4. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
15
15
  5. 命令行工具 & 网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
16
16
  6. 支持崩溃回滚,安全可靠。
package/lib/main.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  PermissionsAndroid,
11
11
  } from 'react-native';
12
12
  import {
13
+ CheckResult,
13
14
  EventType,
14
15
  ProgressData,
15
16
  UpdateAvailableResult,
@@ -125,30 +126,29 @@ export const cInfo = {
125
126
  };
126
127
 
127
128
  function assertRelease() {
128
- // @ts-expect-error
129
129
  if (__DEV__) {
130
130
  throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
131
131
  }
132
132
  }
133
133
 
134
- let checkingThrottling = false;
134
+ let lastChecking = Date.now();
135
+ let lastResult:CheckResult;
135
136
  export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
136
137
  assertRelease();
137
- if (checkingThrottling) {
138
+ const now = Date.now();
139
+ if (lastResult && now - lastChecking < 1000 * 60) {
138
140
  logger('repeated checking, ignored');
139
- return;
141
+ return lastResult;
140
142
  }
141
- checkingThrottling = true;
142
- setTimeout(() => {
143
- checkingThrottling = false;
144
- }, 3000);
143
+ lastChecking = now;
145
144
  if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
146
- return report({
145
+ report({
147
146
  type: 'errorChecking',
148
147
  message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
149
148
  blockUpdate.until * 1000,
150
149
  ).toLocaleString()}"之后重试。`,
151
150
  });
151
+ return;
152
152
  }
153
153
  report({ type: 'checking' });
154
154
  let resp;
@@ -168,19 +168,27 @@ export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
168
168
  });
169
169
  } catch (e) {
170
170
  if (isRetry) {
171
- return report({
171
+ report({
172
172
  type: 'errorChecking',
173
173
  message: '无法连接更新服务器,请检查网络连接后重试',
174
174
  });
175
+ return;
175
176
  }
176
177
  await tryBackupEndpoints();
177
178
  return checkUpdate(APPKEY, true);
178
179
  }
179
- const result = await resp.json();
180
+ const result: CheckResult = await resp.json();
181
+ lastResult = result;
182
+ // @ts-ignore
180
183
  checkOperation(result.op);
181
184
 
182
185
  if (resp.status !== 200) {
183
- return report({ type: 'errorChecking', message: result.message });
186
+ report({
187
+ type: 'errorChecking',
188
+ //@ts-ignore
189
+ message: result.message,
190
+ });
191
+ return;
184
192
  }
185
193
 
186
194
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
4
4
  "description": "react-native hot update",
5
5
  "main": "lib/index.ts",
6
6
  "scripts": {