react-native-update 8.3.0 → 8.5.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/lib/index.web.js CHANGED
@@ -15,4 +15,4 @@ export const downloadAndInstallApk = noop;
15
15
  export const setCustomEndpoints = noop;
16
16
  export const getCurrentVersionInfo = noop;
17
17
  export const simpleUpdate = (app) => app;
18
- export const onEvents = noop;
18
+ export const onPushyEvents = noop;
package/lib/main.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  UpdateAvailableResult,
17
17
  UpdateEventsListener,
18
18
  } from './type';
19
- import { assertRelease, logger } from './utils';
19
+ import { assertRelease, logger, testUrls } from './utils';
20
20
  export { setCustomEndpoints };
21
21
  const {
22
22
  version: v,
@@ -73,7 +73,7 @@ if (!uuid) {
73
73
  const noop = () => {};
74
74
  let reporter: UpdateEventsListener = noop;
75
75
 
76
- export function onEvents(customReporter: UpdateEventsListener) {
76
+ export function onPushyEvents(customReporter: UpdateEventsListener) {
77
77
  reporter = customReporter;
78
78
  if (isRolledBack) {
79
79
  report({
@@ -255,11 +255,12 @@ export async function downloadUpdate(
255
255
  }
256
256
  let succeeded = false;
257
257
  report({ type: 'downloading' });
258
- if (options.diffUrl) {
258
+ const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
259
+ if (diffUrl) {
259
260
  logger('downloading diff');
260
261
  try {
261
262
  await PushyModule.downloadPatchFromPpk({
262
- updateUrl: options.diffUrl,
263
+ updateUrl: diffUrl,
263
264
  hash: options.hash,
264
265
  originHash: currentVersion,
265
266
  });
@@ -268,28 +269,34 @@ export async function downloadUpdate(
268
269
  logger(`diff error: ${e.message}, try pdiff`);
269
270
  }
270
271
  }
271
- if (!succeeded && options.pdiffUrl) {
272
- logger('downloading pdiff');
273
- try {
274
- await PushyModule.downloadPatchFromPackage({
275
- updateUrl: options.pdiffUrl,
276
- hash: options.hash,
277
- });
278
- succeeded = true;
279
- } catch (e) {
280
- logger(`pdiff error: ${e.message}, try full patch`);
272
+ if (!succeeded) {
273
+ const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
274
+ if (pdiffUrl) {
275
+ logger('downloading pdiff');
276
+ try {
277
+ await PushyModule.downloadPatchFromPackage({
278
+ updateUrl: pdiffUrl,
279
+ hash: options.hash,
280
+ });
281
+ succeeded = true;
282
+ } catch (e) {
283
+ logger(`pdiff error: ${e.message}, try full patch`);
284
+ }
281
285
  }
282
286
  }
283
- if (!succeeded && options.updateUrl) {
284
- logger('downloading full patch');
285
- try {
286
- await PushyModule.downloadFullUpdate({
287
- updateUrl: options.updateUrl,
288
- hash: options.hash,
289
- });
290
- succeeded = true;
291
- } catch (e) {
292
- logger(`full patch error: ${e.message}`);
287
+ if (!succeeded) {
288
+ const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
289
+ if (updateUrl) {
290
+ logger('downloading full patch');
291
+ try {
292
+ await PushyModule.downloadFullUpdate({
293
+ updateUrl: updateUrl,
294
+ hash: options.hash,
295
+ });
296
+ succeeded = true;
297
+ } catch (e) {
298
+ logger(`full patch error: ${e.message}`);
299
+ }
293
300
  }
294
301
  }
295
302
  progressHandler && progressHandler.remove();
@@ -16,20 +16,20 @@ import {
16
16
  switchVersionLater,
17
17
  markSuccess,
18
18
  downloadAndInstallApk,
19
- onEvents,
19
+ onPushyEvents,
20
20
  } from './main';
21
21
  import { UpdateEventsListener } from './type';
22
22
 
23
23
  export function simpleUpdate(
24
24
  WrappedComponent: ComponentType,
25
- options: { appKey?: string; onEvents?: UpdateEventsListener } = {},
25
+ options: { appKey?: string; onPushyEvents?: UpdateEventsListener } = {},
26
26
  ) {
27
- const { appKey, onEvents: eventListeners } = options;
27
+ const { appKey, onPushyEvents: eventListeners } = options;
28
28
  if (!appKey) {
29
29
  throw new Error('appKey is required for simpleUpdate()');
30
30
  }
31
31
  if (typeof eventListeners === 'function') {
32
- onEvents(eventListeners);
32
+ onPushyEvents(eventListeners);
33
33
  }
34
34
  return __DEV__
35
35
  ? WrappedComponent
package/lib/type.ts CHANGED
@@ -19,8 +19,11 @@ export interface UpdateAvailableResult {
19
19
  description: string;
20
20
  metaInfo: string;
21
21
  pdiffUrl: string;
22
+ pdiffUrls?: string[];
22
23
  diffUrl?: string;
24
+ diffUrls?: string[];
23
25
  updateUrl?: string;
26
+ updateUrls?: string[];
24
27
  }
25
28
 
26
29
  export type CheckResult =
package/lib/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Platform } from "react-native";
2
+
1
3
  export function logger(...args: any[]) {
2
4
  console.log('Pushy: ', ...args);
3
5
  }
@@ -7,3 +9,24 @@ export function assertRelease() {
7
9
  throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
8
10
  }
9
11
  }
12
+
13
+ const ping =
14
+ Platform.OS === 'web'
15
+ ? Promise.resolve
16
+ : async (url: string) =>
17
+ Promise.race([
18
+ fetch(url, {
19
+ method: 'HEAD',
20
+ })
21
+ .then(({ status }) => (status === 200 ? url : null))
22
+ .catch(() => null),
23
+ new Promise(r => setTimeout(() => r(null), 2000)),
24
+ ]);
25
+
26
+
27
+ export const testUrls = async (urls?: string[]) => {
28
+ if (!urls?.length) {
29
+ return null;
30
+ }
31
+ return Promise.race(urls.map(ping)).catch(() => null);
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "8.3.0",
3
+ "version": "8.5.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "lib/index.ts",
6
6
  "scripts": {