react-native-update 10.5.0 → 10.5.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.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.5.0",
3
+ "version": "10.5.2",
4
4
  "description": "react-native hot update",
5
- "main": "src/index.ts",
5
+ "main": "src/index",
6
6
  "scripts": {
7
7
  "prepack": "yarn submodule && yarn lint",
8
8
  "lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
@@ -1,10 +1,7 @@
1
1
  import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
2
2
  import { log, testUrls } from './utils';
3
- import {
4
- EmitterSubscription,
5
- PermissionsAndroid,
6
- Platform,
7
- } from 'react-native';
3
+ import { EmitterSubscription, Platform } from 'react-native';
4
+ import type { PermissionsAndroidStatic } from 'react-native';
8
5
  import {
9
6
  PushyModule,
10
7
  buildTime,
@@ -27,6 +24,10 @@ const defaultServer = {
27
24
  const empty = {};
28
25
  const noop = () => {};
29
26
 
27
+ if (Platform.OS === 'web') {
28
+ console.warn('react-native-update 不支持 web 端热更,不会执行操作');
29
+ }
30
+
30
31
  export class Pushy {
31
32
  options: PushyOptions = {
32
33
  appKey: '',
@@ -149,10 +150,14 @@ export class Pushy {
149
150
  checkUpdate = async () => {
150
151
  if (__DEV__ && !this.options.debug) {
151
152
  console.info(
152
- '您当前处于开发环境且未启用debug,不会进行热更检查。如需在开发环境中调试热更,请在client中设置debug为true',
153
+ '您当前处于开发环境且未启用 debug,不会进行热更检查。如需在开发环境中调试热更,请在 client 中设置 debug true',
153
154
  );
154
155
  return;
155
156
  }
157
+ if (Platform.OS === 'web') {
158
+ console.warn('web 端不支持热更新检查');
159
+ return;
160
+ }
156
161
  const now = Date.now();
157
162
  if (
158
163
  this.lastRespJson &&
@@ -366,6 +371,8 @@ export class Pushy {
366
371
  this.report({ type: 'downloadingApk' });
367
372
  if (Platform.Version <= 23) {
368
373
  try {
374
+ const PermissionsAndroid =
375
+ require('react-native/Libraries/PermissionsAndroid/PermissionsAndroid') as PermissionsAndroidStatic;
369
376
  const granted = await PermissionsAndroid.request(
370
377
  PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
371
378
  );
package/src/core.ts CHANGED
@@ -8,9 +8,23 @@ const isTurboModuleEnabled =
8
8
  // @ts-expect-error
9
9
  global.__turboModuleProxy != null;
10
10
 
11
- export const PushyModule = isTurboModuleEnabled
12
- ? require('./NativePushy').default
13
- : NativeModules.Pushy;
11
+ const noop = () => {};
12
+ class EmptyModule {
13
+ constructor() {
14
+ return new Proxy(this, {
15
+ get() {
16
+ return noop;
17
+ },
18
+ });
19
+ }
20
+ }
21
+
22
+ export const PushyModule =
23
+ Platform.OS === 'web'
24
+ ? new EmptyModule()
25
+ : isTurboModuleEnabled
26
+ ? require('./NativePushy').default
27
+ : NativeModules.Pushy;
14
28
 
15
29
  if (!PushyModule) {
16
30
  throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
@@ -12,7 +12,7 @@ import {
12
12
  Platform,
13
13
  Linking,
14
14
  } from 'react-native';
15
- import { Pushy } from './client.native';
15
+ import { Pushy } from './client';
16
16
  import {
17
17
  currentVersion,
18
18
  isFirstTime,
package/src/utils.ts CHANGED
@@ -1,14 +1,18 @@
1
+ import { Platform } from 'react-native';
1
2
  export function log(...args: any[]) {
2
3
  console.log('pushy: ', ...args);
3
4
  }
4
5
 
5
- const ping = async (url: string) =>
6
- Promise.race([
7
- fetch(url, {
8
- method: 'HEAD',
9
- }).then(({ status }) => status === 200),
10
- new Promise<false>(r => setTimeout(() => r(false), 2000)),
11
- ]);
6
+ const ping =
7
+ Platform.OS === 'web'
8
+ ? () => Promise.resolve(true)
9
+ : async (url: string) =>
10
+ Promise.race([
11
+ fetch(url, {
12
+ method: 'HEAD',
13
+ }).then(({ status }) => status === 200),
14
+ new Promise<false>(r => setTimeout(() => r(false), 2000)),
15
+ ]);
12
16
 
13
17
  const canUseGoogle = ping('https://www.google.com');
14
18
 
package/src/client.js DELETED
@@ -1,13 +0,0 @@
1
- const noop = () => {};
2
- export class Pushy {
3
- constructor() {
4
- console.warn(
5
- 'react-native-update is not supported and will do nothing on web.',
6
- );
7
- return new Proxy(this, {
8
- get() {
9
- return noop;
10
- },
11
- });
12
- }
13
- }
@@ -1,3 +0,0 @@
1
- export { Pushy } from './client.native';
2
- export { PushyContext, usePushy } from './context';
3
- export { PushyProvider } from './provider.native';
package/src/provider.jsx DELETED
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export const PushyProvider = ({ children }) => <>{children}</>;
File without changes