react-native-update 10.5.1 → 10.5.3

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.5.1",
3
+ "version": "10.5.3",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
@@ -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 { PermissionsAndroid } from './permissions';
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 &&
package/src/core.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
- import { log } from './utils';
2
+ import { EmptyModule, log } from './utils';
3
3
  const {
4
4
  version: v,
5
5
  } = require('react-native/Libraries/Core/ReactNativeVersion');
@@ -8,9 +8,12 @@ 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
+ export const PushyModule =
12
+ Platform.OS === 'web'
13
+ ? new EmptyModule()
14
+ : isTurboModuleEnabled
15
+ ? require('./NativePushy').default
16
+ : NativeModules.Pushy;
14
17
 
15
18
  if (!PushyModule) {
16
19
  throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
@@ -0,0 +1 @@
1
+ export { PermissionsAndroid } from 'react-native';
@@ -0,0 +1,4 @@
1
+ import type { PermissionsAndroidStatic } from 'react-native';
2
+ import { EmptyModule } from './utils';
3
+
4
+ export const PermissionsAndroid = new EmptyModule() as PermissionsAndroidStatic;
@@ -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,30 @@
1
+ import { Platform } from 'react-native';
2
+
1
3
  export function log(...args: any[]) {
2
4
  console.log('pushy: ', ...args);
3
5
  }
4
6
 
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
- ]);
7
+ const noop = () => {};
8
+ export class EmptyModule {
9
+ constructor() {
10
+ return new Proxy(this, {
11
+ get() {
12
+ return noop;
13
+ },
14
+ });
15
+ }
16
+ }
17
+
18
+ const ping =
19
+ Platform.OS === 'web'
20
+ ? () => Promise.resolve(true)
21
+ : async (url: string) =>
22
+ Promise.race([
23
+ fetch(url, {
24
+ method: 'HEAD',
25
+ }).then(({ status }) => status === 200),
26
+ new Promise<false>(r => setTimeout(() => r(false), 2000)),
27
+ ]);
12
28
 
13
29
  const canUseGoogle = ping('https://www.google.com');
14
30
 
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