react-native-update 10.3.1 → 10.4.1

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.3.1",
3
+ "version": "10.4.1",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/src/client.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
2
- import { assertRelease, log, testUrls } from './utils';
2
+ import { log, testUrls } from './utils';
3
3
  import {
4
4
  EmitterSubscription,
5
5
  PermissionsAndroid,
@@ -35,6 +35,7 @@ export class Pushy {
35
35
  useAlert: true,
36
36
  strategy: 'both',
37
37
  logger: noop,
38
+ debug: false,
38
39
  };
39
40
 
40
41
  lastChecking?: number;
@@ -112,8 +113,7 @@ export class Pushy {
112
113
  return true;
113
114
  };
114
115
  markSuccess = () => {
115
- assertRelease();
116
- if (this.marked) {
116
+ if (this.marked || __DEV__) {
117
117
  return;
118
118
  }
119
119
  this.marked = true;
@@ -121,7 +121,12 @@ export class Pushy {
121
121
  this.report({ type: 'markSuccess' });
122
122
  };
123
123
  switchVersion = (hash: string) => {
124
- assertRelease();
124
+ if (__DEV__) {
125
+ console.warn(
126
+ '您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。',
127
+ );
128
+ return;
129
+ }
125
130
  if (this.assertHash(hash) && !this.applyingUpdate) {
126
131
  log('switchVersion: ' + hash);
127
132
  this.applyingUpdate = true;
@@ -130,14 +135,24 @@ export class Pushy {
130
135
  };
131
136
 
132
137
  switchVersionLater = (hash: string) => {
133
- assertRelease();
138
+ if (__DEV__) {
139
+ console.warn(
140
+ '您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。',
141
+ );
142
+ return;
143
+ }
134
144
  if (this.assertHash(hash)) {
135
145
  log('switchVersionLater: ' + hash);
136
146
  PushyModule.setNeedUpdate({ hash });
137
147
  }
138
148
  };
139
149
  checkUpdate = async () => {
140
- assertRelease();
150
+ if (__DEV__ && !this.options.debug) {
151
+ console.info(
152
+ '您当前处于开发环境且未启用debug,不会进行热更检查。如需在开发环境中调试热更,请在client中设置debug为true',
153
+ );
154
+ return;
155
+ }
141
156
  const now = Date.now();
142
157
  if (
143
158
  this.lastRespJson &&
@@ -148,18 +163,22 @@ export class Pushy {
148
163
  }
149
164
  this.lastChecking = now;
150
165
  this.report({ type: 'checking' });
166
+ const fetchBody = {
167
+ packageVersion,
168
+ hash: currentVersion,
169
+ buildTime,
170
+ cInfo,
171
+ };
172
+ if (__DEV__) {
173
+ delete fetchBody.buildTime;
174
+ }
151
175
  const fetchPayload = {
152
176
  method: 'POST',
153
177
  headers: {
154
178
  Accept: 'application/json',
155
179
  'Content-Type': 'application/json',
156
180
  },
157
- body: JSON.stringify({
158
- packageVersion,
159
- hash: currentVersion,
160
- buildTime,
161
- cInfo,
162
- }),
181
+ body: JSON.stringify(fetchBody),
163
182
  };
164
183
  let resp;
165
184
  try {
@@ -225,7 +244,6 @@ export class Pushy {
225
244
  info: CheckResult,
226
245
  onDownloadProgress?: (data: ProgressData) => void,
227
246
  ) => {
228
- assertRelease();
229
247
  const {
230
248
  hash,
231
249
  diffUrl: _diffUrl,
@@ -275,7 +293,11 @@ export class Pushy {
275
293
  });
276
294
  succeeded = true;
277
295
  } catch (e: any) {
278
- log(`diff error: ${e.message}, try pdiff`);
296
+ if (__DEV__) {
297
+ succeeded = true;
298
+ } else {
299
+ log(`diff error: ${e.message}, try pdiff`);
300
+ }
279
301
  }
280
302
  }
281
303
  const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
@@ -288,7 +310,11 @@ export class Pushy {
288
310
  });
289
311
  succeeded = true;
290
312
  } catch (e: any) {
291
- log(`pdiff error: ${e.message}, try full patch`);
313
+ if (__DEV__) {
314
+ succeeded = true;
315
+ } else {
316
+ log(`pdiff error: ${e.message}, try full patch`);
317
+ }
292
318
  }
293
319
  }
294
320
  const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
@@ -301,13 +327,20 @@ export class Pushy {
301
327
  });
302
328
  succeeded = true;
303
329
  } catch (e: any) {
304
- log(`full patch error: ${e.message}`);
330
+ if (__DEV__) {
331
+ succeeded = true;
332
+ } else {
333
+ log(`full patch error: ${e.message}`);
334
+ }
305
335
  }
306
336
  }
307
337
  if (this.progressHandlers[hash]) {
308
338
  this.progressHandlers[hash].remove();
309
339
  delete this.progressHandlers[hash];
310
340
  }
341
+ if (__DEV__) {
342
+ return hash;
343
+ }
311
344
  if (!succeeded) {
312
345
  return this.report({
313
346
  type: 'errorUpdate',
package/src/type.ts CHANGED
@@ -70,7 +70,8 @@ export interface PushyOptions {
70
70
  server?: PushyServerConfig;
71
71
  logger?: UpdateEventsLogger;
72
72
  useAlert?: boolean;
73
- strategy?: 'onAppStart' | 'onAppResume' | 'both';
73
+ strategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
74
74
  autoMarkSuccess?: boolean;
75
75
  dismissErrorAfter?: number;
76
+ debug?: boolean;
76
77
  }
package/src/utils.ts CHANGED
@@ -2,12 +2,6 @@ export function log(...args: any[]) {
2
2
  console.log('pushy: ', ...args);
3
3
  }
4
4
 
5
- export function assertRelease() {
6
- if (__DEV__) {
7
- throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
8
- }
9
- }
10
-
11
5
  const ping = async (url: string) =>
12
6
  Promise.race([
13
7
  fetch(url, {