react-native-update 8.1.0 → 8.2.0

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 CHANGED
@@ -9,12 +9,13 @@
9
9
  ### 优势
10
10
 
11
11
  1. 基于阿里云高速 CDN 分发,对比其他服务器在国外的热更新服务,分发更稳定,更新成功率极高。
12
- 2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在 1-10KB 之间(其他全量热更新服务所需流量通常在 1-10MB 级别)。
13
- 3. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
14
- 4. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
15
- 5. 支持崩溃回滚,安全可靠。
16
- 6. meta 信息及开放 API,提供更高扩展性。
17
- 7. 提供付费的专人技术支持。
12
+ 2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在几十 KB 级别(其他全量热更新服务所需流量通常在几十 MB 级别)。
13
+ 3. 始终跟进 RN 最新正式版本,第一时间提供支持。支持 hermes 字节码格式。(暂不支持新架构,会待其相对稳定后跟进)
14
+ 4. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新。
15
+ 5. 命令行工具 & 网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
16
+ 6. 支持崩溃回滚,安全可靠。
17
+ 7. meta 信息及开放 API,提供更高扩展性。
18
+ 8. 提供付费的专人技术支持。
18
19
 
19
20
  ### 本地开发
20
21
 
@@ -1,2 +1,3 @@
1
1
  -keepnames class cn.reactnative.modules.update.DownloadTask { *; }
2
+ -keepnames class cn.reactnative.modules.update.UpdateModule { *; }
2
3
  -keepnames class com.facebook.react.ReactInstanceManager { *; }
@@ -1 +1 @@
1
- 1654072539
1
+ 1574665292
package/lib/main.js CHANGED
@@ -58,34 +58,42 @@ if (!uuid) {
58
58
  Pushy.setUuid(uuid);
59
59
  }
60
60
 
61
- function logger(text) {
62
- console.log(`Pushy: ${text}`);
61
+ function logger(...args) {
62
+ console.log('Pushy: ', ...args);
63
63
  }
64
64
 
65
- function report(hash, type) {
66
- logger(type);
67
- fetch(getReportUrl(), {
68
- method: 'POST',
69
- headers: {
70
- Accept: 'application/json',
71
- 'Content-Type': 'application/json',
72
- },
73
- body: JSON.stringify({
74
- hash,
75
- type,
65
+ const noop = () => {};
66
+ let reporter = noop;
67
+
68
+ export function onEvents(customReporter) {
69
+ reporter = customReporter;
70
+ if (isRolledBack) {
71
+ report({
72
+ type: 'rollback',
73
+ data: {
74
+ rolledBackVersion,
75
+ },
76
+ });
77
+ }
78
+ }
79
+
80
+ function report({ type, message = '', data = {} }) {
81
+ logger(type + ' ' + message);
82
+ reporter({
83
+ type,
84
+ data: {
85
+ currentVersion,
76
86
  cInfo,
77
87
  packageVersion,
78
88
  buildTime,
79
- }),
80
- }).catch((_e) => {});
89
+ message,
90
+ ...data,
91
+ },
92
+ });
81
93
  }
82
94
 
83
95
  logger('uuid: ' + uuid);
84
96
 
85
- if (isRolledBack) {
86
- report(rolledBackVersion, 'rollback');
87
- }
88
-
89
97
  export const cInfo = {
90
98
  pushy: require('../package.json').version,
91
99
  rn: RNVersion,
@@ -99,28 +107,30 @@ function assertRelease() {
99
107
  }
100
108
  }
101
109
 
102
- let checkingThrottling = false;
110
+ let lastChecking;
111
+ const empty = {};
112
+ let lastResult;
103
113
  export async function checkUpdate(APPKEY, isRetry) {
114
+ if (typeof APPKEY !== 'string') {
115
+ throw new Error('未检查到合法的APPKEY,请查看update.json文件是否正确生成');
116
+ }
104
117
  assertRelease();
105
- if (checkingThrottling) {
106
- logger('repeated checking, ignored');
107
- return;
118
+ const now = Date.now();
119
+ if (lastResult && lastChecking && now - lastChecking < 1000 * 60) {
120
+ // logger('repeated checking, ignored');
121
+ return lastResult;
108
122
  }
109
- checkingThrottling = true;
110
- setTimeout(() => {
111
- checkingThrottling = false;
112
- }, 3000);
123
+ lastChecking = now;
113
124
  if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
114
- throw new Error(
115
- `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
125
+ report({
126
+ type: 'errorChecking',
127
+ message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
116
128
  blockUpdate.until * 1000,
117
129
  ).toLocaleString()}"之后重试。`,
118
- );
119
- }
120
- if (typeof APPKEY !== 'string') {
121
- throw new Error('未检查到合法的APPKEY,请查看update.json文件是否正确生成');
130
+ });
131
+ return lastResult || empty;
122
132
  }
123
- logger('checking update');
133
+ report({ type: 'checking' });
124
134
  let resp;
125
135
  try {
126
136
  resp = await fetch(getCheckUrl(APPKEY), {
@@ -138,16 +148,25 @@ export async function checkUpdate(APPKEY, isRetry) {
138
148
  });
139
149
  } catch (e) {
140
150
  if (isRetry) {
141
- throw new Error('无法连接更新服务器,请检查网络连接后重试');
151
+ report({
152
+ type: 'errorChecking',
153
+ message: '无法连接更新服务器,请检查网络连接后重试',
154
+ });
155
+ return lastResult || empty;
142
156
  }
143
157
  await tryBackupEndpoints();
144
158
  return checkUpdate(APPKEY, true);
145
159
  }
146
160
  const result = await resp.json();
161
+ lastResult = result;
162
+
147
163
  checkOperation(result.op);
148
164
 
149
165
  if (resp.status !== 200) {
150
- throw new Error(result.message);
166
+ report({
167
+ type: 'errorChecking',
168
+ message: result.message,
169
+ });
151
170
  }
152
171
 
153
172
  return result;
@@ -206,6 +225,7 @@ export async function downloadUpdate(options, eventListeners) {
206
225
  }
207
226
  }
208
227
  let succeeded = false;
228
+ report({ type: 'downloading' });
209
229
  if (options.diffUrl) {
210
230
  logger('downloading diff');
211
231
  try {
@@ -245,8 +265,7 @@ export async function downloadUpdate(options, eventListeners) {
245
265
  }
246
266
  progressHandler && progressHandler.remove();
247
267
  if (!succeeded) {
248
- report(options.hash, 'error');
249
- throw new Error('all update attempts failed');
268
+ return report({ type: 'errorUpdate', data: { newVersion: options.hash } });
250
269
  }
251
270
  setLocalHashInfo(options.hash, {
252
271
  name: options.name,
@@ -305,10 +324,10 @@ export async function downloadAndInstallApk({ url, onDownloadProgress }) {
305
324
  PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
306
325
  );
307
326
  if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
308
- return;
327
+ return report({ type: 'rejectStoragePermission' });
309
328
  }
310
329
  } catch (err) {
311
- console.warn(err);
330
+ return report({ type: 'errorStoragePermission' });
312
331
  }
313
332
  }
314
333
  let hash = Date.now().toString();
@@ -327,6 +346,8 @@ export async function downloadAndInstallApk({ url, onDownloadProgress }) {
327
346
  url,
328
347
  target: 'update.apk',
329
348
  hash,
349
+ }).catch(() => {
350
+ report({ type: 'errowDownloadAndInstallApk' });
330
351
  });
331
352
  progressHandler && progressHandler.remove();
332
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {