react-native-update 10.11.8 → 10.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.11.8",
3
+ "version": "10.13.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
2
- import { log, testUrls } from './utils';
2
+ import { joinUrls, log, testUrls } from './utils';
3
3
  import { EmitterSubscription, Platform } from 'react-native';
4
4
  import { PermissionsAndroid } from './permissions';
5
5
  import {
@@ -64,8 +64,7 @@ export class Pushy {
64
64
  setOptions = (options: Partial<PushyOptions>) => {
65
65
  for (const [key, value] of Object.entries(options)) {
66
66
  if (value !== undefined) {
67
- // @ts-expect-error
68
- this.options[key] = value;
67
+ (this.options as any)[key] = value;
69
68
  if (key === 'logger') {
70
69
  if (isRolledBack) {
71
70
  this.report({
@@ -163,6 +162,13 @@ export class Pushy {
163
162
  console.warn('web 端不支持热更新检查');
164
163
  return;
165
164
  }
165
+ if (
166
+ this.options.beforeCheckUpdate &&
167
+ (await this.options.beforeCheckUpdate()) === false
168
+ ) {
169
+ log('beforeCheckUpdate 返回 false, 忽略检查');
170
+ return;
171
+ }
166
172
  const now = Date.now();
167
173
  if (
168
174
  this.lastRespJson &&
@@ -265,16 +271,21 @@ export class Pushy {
265
271
  ) => {
266
272
  const {
267
273
  hash,
268
- diffUrl: _diffUrl,
269
- diffUrls,
270
- pdiffUrl: _pdiffUrl,
271
- pdiffUrls,
272
- updateUrl: _updateUrl,
273
- updateUrls,
274
+ diff,
275
+ pdiff,
276
+ full,
277
+ paths = [],
274
278
  name,
275
279
  description,
276
280
  metaInfo,
277
281
  } = info;
282
+ if (
283
+ this.options.beforeDownloadUpdate &&
284
+ (await this.options.beforeDownloadUpdate(info)) === false
285
+ ) {
286
+ log('beforeDownloadUpdate 返回 false, 忽略下载');
287
+ return;
288
+ }
278
289
  if (!info.update || !hash) {
279
290
  return;
280
291
  }
@@ -302,7 +313,7 @@ export class Pushy {
302
313
  let succeeded = '';
303
314
  this.report({ type: 'downloading' });
304
315
  let lastError: any;
305
- const diffUrl = (await testUrls(diffUrls)) || _diffUrl;
316
+ const diffUrl = await testUrls(joinUrls(paths, diff));
306
317
  if (diffUrl) {
307
318
  log('downloading diff');
308
319
  try {
@@ -321,7 +332,7 @@ export class Pushy {
321
332
  }
322
333
  }
323
334
  }
324
- const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
335
+ const pdiffUrl = await testUrls(joinUrls(paths, pdiff));
325
336
  if (!succeeded && pdiffUrl) {
326
337
  log('downloading pdiff');
327
338
  try {
@@ -339,12 +350,12 @@ export class Pushy {
339
350
  }
340
351
  }
341
352
  }
342
- const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
343
- if (!succeeded && updateUrl) {
353
+ const fullUrl = await testUrls(joinUrls(paths, full));
354
+ if (!succeeded && fullUrl) {
344
355
  log('downloading full patch');
345
356
  try {
346
357
  await PushyModule.downloadFullUpdate({
347
- updateUrl: updateUrl,
358
+ updateUrl: fullUrl,
348
359
  hash,
349
360
  });
350
361
  succeeded = 'full';
package/src/core.ts CHANGED
@@ -4,9 +4,7 @@ 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 =
8
- // @ts-expect-error
9
- global.__turboModuleProxy != null;
7
+ const isTurboModuleEnabled = (global as any).__turboModuleProxy != null;
10
8
 
11
9
  export const PushyModule =
12
10
  Platform.OS === 'web'
package/src/type.ts CHANGED
@@ -7,12 +7,10 @@ export interface CheckResult {
7
7
  hash?: string;
8
8
  description?: string;
9
9
  metaInfo?: string;
10
- pdiffUrl?: string;
11
- pdiffUrls?: string[];
12
- diffUrl?: string;
13
- diffUrls?: string[];
14
- updateUrl?: string;
15
- updateUrls?: string[];
10
+ pdiff?: string;
11
+ diff?: string;
12
+ full?: string;
13
+ paths?: string[];
16
14
  paused?: 'app' | 'package';
17
15
  message?: string;
18
16
  }
@@ -81,6 +79,8 @@ export interface PushyOptions {
81
79
  dismissErrorAfter?: number;
82
80
  debug?: boolean;
83
81
  throwError?: boolean;
82
+ beforeCheckUpdate?: () => Promise<boolean>;
83
+ beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
84
84
  }
85
85
 
86
86
  export interface PushyTestPayload {
package/src/utils.ts CHANGED
@@ -31,9 +31,18 @@ const ping =
31
31
 
32
32
  const canUseGoogle = ping('https://www.google.com');
33
33
 
34
+ export function joinUrls(paths: string[], fileName?: string) {
35
+ if (fileName) {
36
+ return paths.map(path => 'https://' + path + '/' + fileName);
37
+ }
38
+ }
39
+
34
40
  export const testUrls = async (urls?: string[]) => {
35
- if (!urls?.length || (await canUseGoogle)) {
41
+ if (!urls?.length) {
36
42
  return null;
37
43
  }
44
+ if (await canUseGoogle) {
45
+ return urls[0];
46
+ }
38
47
  return Promise.race(urls.map(ping)).catch(() => null);
39
48
  };