react-native-update 10.24.1 → 10.24.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,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.24.1",
3
+ "version": "10.24.2",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { CheckResult, ClientOptions, ProgressData, EventType } from './type';
2
- import { emptyObj, joinUrls, log, noop, promiseAny, testUrls } from './utils';
2
+ import {
3
+ assertDev,
4
+ assertWeb,
5
+ emptyObj,
6
+ joinUrls,
7
+ log,
8
+ noop,
9
+ promiseAny,
10
+ testUrls,
11
+ } from './utils';
3
12
  import { EmitterSubscription, Platform } from 'react-native';
4
13
  import { PermissionsAndroid } from './permissions';
5
14
  import {
@@ -17,7 +26,7 @@ import {
17
26
 
18
27
  const SERVER_PRESETS = {
19
28
  // cn
20
- pushy: {
29
+ Pushy: {
21
30
  main: 'https://update.react-native.cn/api',
22
31
  backups: ['https://update.reactnative.cn/api'],
23
32
  queryUrls: [
@@ -26,7 +35,7 @@ const SERVER_PRESETS = {
26
35
  ],
27
36
  },
28
37
  // i18n
29
- cresc: {
38
+ Cresc: {
30
39
  main: 'https://api.cresc.dev',
31
40
  backups: ['https://api.cresc.app'],
32
41
  queryUrls: [
@@ -34,11 +43,8 @@ const SERVER_PRESETS = {
34
43
  ],
35
44
  },
36
45
  };
37
- if (Platform.OS === 'web') {
38
- console.warn(
39
- 'react-native-update does not support hot updates on the web platform and will not perform any operations',
40
- );
41
- }
46
+
47
+ assertWeb();
42
48
 
43
49
  const defaultClientOptions: ClientOptions = {
44
50
  appKey: '',
@@ -52,11 +58,8 @@ const defaultClientOptions: ClientOptions = {
52
58
 
53
59
  // for China users
54
60
  export class Pushy {
55
- options: ClientOptions = {
56
- ...defaultClientOptions,
57
- server: SERVER_PRESETS.pushy,
58
- };
59
- clientType: 'pushy' | 'cresc' = 'pushy';
61
+ options = defaultClientOptions;
62
+ clientType: 'Pushy' | 'Cresc' = 'Pushy';
60
63
  lastChecking?: number;
61
64
  lastRespJson?: Promise<any>;
62
65
 
@@ -85,6 +88,8 @@ export class Pushy {
85
88
  throw new Error('appKey is required');
86
89
  }
87
90
  }
91
+ this.clientType = new.target.name as 'Pushy' | 'Cresc';
92
+ this.options.server = SERVER_PRESETS[this.clientType];
88
93
  this.setOptions(options);
89
94
  if (isRolledBack) {
90
95
  this.report({
@@ -150,6 +155,15 @@ export class Pushy {
150
155
  }
151
156
  return true;
152
157
  };
158
+ assertDebug = () => {
159
+ if (__DEV__ && !this.options.debug) {
160
+ console.info(
161
+ 'You are currently in the development environment and have not enabled debug mode. The hot update check will not be performed. If you need to debug hot updates in the development environment, please set debug to true in the client.',
162
+ );
163
+ return false;
164
+ }
165
+ return true;
166
+ };
153
167
  markSuccess = () => {
154
168
  if (Pushy.marked || __DEV__ || !isFirstTime) {
155
169
  return;
@@ -159,10 +173,7 @@ export class Pushy {
159
173
  this.report({ type: 'markSuccess' });
160
174
  };
161
175
  switchVersion = async (hash: string) => {
162
- if (__DEV__) {
163
- console.warn(
164
- 'switchVersion() is not supported in development environment; no action taken.',
165
- );
176
+ if (!assertDev('switchVersion()')) {
166
177
  return;
167
178
  }
168
179
  if (Pushy.assertHash(hash) && !Pushy.applyingUpdate) {
@@ -173,10 +184,7 @@ export class Pushy {
173
184
  };
174
185
 
175
186
  switchVersionLater = async (hash: string) => {
176
- if (__DEV__) {
177
- console.warn(
178
- 'switchVersionLater() is not supported in development environment; no action taken.',
179
- );
187
+ if (!assertDev('switchVersionLater()')) {
180
188
  return;
181
189
  }
182
190
  if (Pushy.assertHash(hash)) {
@@ -185,14 +193,10 @@ export class Pushy {
185
193
  }
186
194
  };
187
195
  checkUpdate = async (extra?: Record<string, any>) => {
188
- if (__DEV__ && !this.options.debug) {
189
- console.info(
190
- 'You are currently in the development environment and have not enabled debug mode. The hot update check will not be performed. If you need to debug hot updates in the development environment, please set debug to true in the client.',
191
- );
196
+ if (!this.assertDebug()) {
192
197
  return;
193
198
  }
194
- if (Platform.OS === 'web') {
195
- console.warn('web platform does not support hot update check');
199
+ if (!assertWeb()) {
196
200
  return;
197
201
  }
198
202
  if (
@@ -508,10 +512,4 @@ export class Pushy {
508
512
  }
509
513
 
510
514
  // for international users
511
- export class Cresc extends Pushy {
512
- clientType: 'cresc' | 'pushy' = 'cresc';
513
- options: ClientOptions = {
514
- ...defaultClientOptions,
515
- server: SERVER_PRESETS.cresc,
516
- };
517
- }
515
+ export class Cresc extends Pushy {}
package/src/provider.tsx CHANGED
@@ -27,7 +27,9 @@ export const UpdateProvider = ({
27
27
  client: Pushy | Cresc;
28
28
  children: ReactNode;
29
29
  }) => {
30
+ client = useRef(client).current;
30
31
  const { options } = client;
32
+
31
33
  const stateListener = useRef<NativeEventSubscription>();
32
34
  const [updateInfo, setUpdateInfo] = useState<CheckResult>();
33
35
  const updateInfoRef = useRef(updateInfo);
@@ -239,10 +241,7 @@ export const UpdateProvider = ({
239
241
  const markSuccess = client.markSuccess;
240
242
 
241
243
  useEffect(() => {
242
- if (__DEV__ && !options.debug) {
243
- console.info(
244
- '您当前处于开发环境且未启用debug,不会进行热更检查。如需在开发环境中调试热更,请在client中设置debug为true',
245
- );
244
+ if (!client.assertDebug()) {
246
245
  return;
247
246
  }
248
247
  const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options;
@@ -272,7 +271,7 @@ export const UpdateProvider = ({
272
271
  stateListener.current && stateListener.current.remove();
273
272
  clearTimeout(dismissErrorTimer);
274
273
  };
275
- }, [checkUpdate, options, dismissError, markSuccess]);
274
+ }, [checkUpdate, options, dismissError, markSuccess, client]);
276
275
 
277
276
  const parseTestPayload = useCallback(
278
277
  (payload: UpdateTestPayload) => {
package/src/utils.ts CHANGED
@@ -84,3 +84,23 @@ export const testUrls = async (urls?: string[]) => {
84
84
  log('all ping failed, use first url:', urls[0]);
85
85
  return urls[0];
86
86
  };
87
+
88
+ export const assertWeb = () => {
89
+ if (Platform.OS === 'web') {
90
+ console.warn(
91
+ 'react-native-update does not support the Web platform and will not perform any operations',
92
+ );
93
+ return false;
94
+ }
95
+ return true;
96
+ };
97
+
98
+ export const assertDev = (matter: string) => {
99
+ if (__DEV__) {
100
+ console.warn(
101
+ `${matter} is not supported in development environment; no action taken.`,
102
+ );
103
+ return false;
104
+ }
105
+ return true;
106
+ };