react-native-update 10.13.2 → 10.14.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.13.2",
3
+ "version": "10.14.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/core.ts CHANGED
@@ -14,7 +14,7 @@ export const PushyModule =
14
14
  : NativeModules.Pushy;
15
15
 
16
16
  if (!PushyModule) {
17
- throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
17
+ throw new Error('react-native-update 模块无法加载,请对照安装文档检查配置。');
18
18
  }
19
19
 
20
20
  const PushyConstants = isTurboModuleEnabled
@@ -33,7 +33,7 @@ let uuid = PushyConstants.uuid;
33
33
 
34
34
  if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
35
35
  throw new Error(
36
- 'react-native-update模块无法加载,请对照文档检查Bundle URL的配置',
36
+ 'react-native-update 模块无法加载,请对照文档检查 Bundle URL 的配置',
37
37
  );
38
38
  }
39
39
 
@@ -0,0 +1,77 @@
1
+ /* eslint-disable no-fallthrough */
2
+
3
+ import { cInfo } from './core';
4
+
5
+ /* eslint-disable no-bitwise */
6
+ function murmurhash3_32_gc(key: string, seed = 0) {
7
+ let remainder, bytes, h1, h1b, c1, c2, k1, i;
8
+
9
+ remainder = key.length & 3; // key.length % 4
10
+ bytes = key.length - remainder;
11
+ h1 = seed;
12
+ c1 = 0xcc9e2d51;
13
+ c2 = 0x1b873593;
14
+ i = 0;
15
+
16
+ while (i < bytes) {
17
+ k1 =
18
+ (key.charCodeAt(i) & 0xff) |
19
+ ((key.charCodeAt(++i) & 0xff) << 8) |
20
+ ((key.charCodeAt(++i) & 0xff) << 16) |
21
+ ((key.charCodeAt(++i) & 0xff) << 24);
22
+ ++i;
23
+
24
+ ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
25
+ k1 = (k1 << 15) | (k1 >>> 17);
26
+ k1 =
27
+ ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
28
+
29
+ h1 ^= k1;
30
+ h1 = (h1 << 13) | (h1 >>> 19);
31
+ h1b =
32
+ ((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) & 0xffffffff;
33
+ h1 = (h1b & 0xffff) + 0x6b64 + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
34
+ }
35
+
36
+ k1 = 0;
37
+
38
+ switch (remainder) {
39
+ case 3:
40
+ k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
41
+ case 2:
42
+ k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
43
+ case 1:
44
+ k1 ^= key.charCodeAt(i) & 0xff;
45
+
46
+ k1 =
47
+ ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
48
+ 0xffffffff;
49
+ k1 = (k1 << 15) | (k1 >>> 17);
50
+ k1 =
51
+ ((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
52
+ 0xffffffff;
53
+ h1 ^= k1;
54
+ }
55
+
56
+ h1 ^= key.length;
57
+
58
+ h1 ^= h1 >>> 16;
59
+ h1 =
60
+ ((h1 & 0xffff) * 0x85ebca6b +
61
+ ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
62
+ 0xffffffff;
63
+ h1 ^= h1 >>> 13;
64
+ h1 =
65
+ ((h1 & 0xffff) * 0xc2b2ae35 +
66
+ ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
67
+ 0xffffffff;
68
+ h1 ^= h1 >>> 16;
69
+
70
+ return h1 >>> 0;
71
+ }
72
+
73
+ const intForUUID = murmurhash3_32_gc(cInfo.uuid);
74
+
75
+ export function isInRollout(rollout: number) {
76
+ return intForUUID % 100 < rollout;
77
+ }
package/src/provider.tsx CHANGED
@@ -22,6 +22,8 @@ import {
22
22
  import { CheckResult, ProgressData, PushyTestPayload } from './type';
23
23
  import { PushyContext } from './context';
24
24
  import { URL } from 'react-native-url-polyfill';
25
+ import { isInRollout } from './isInRollout';
26
+ import { log } from './utils';
25
27
 
26
28
  export const PushyProvider = ({
27
29
  client,
@@ -165,6 +167,14 @@ export const PushyProvider = ({
165
167
  if (!info) {
166
168
  return;
167
169
  }
170
+ const rollout = info.config?.rollout;
171
+ if (rollout) {
172
+ if (!isInRollout(rollout)) {
173
+ log(`not in ${rollout}% rollout, ignored`);
174
+ return;
175
+ }
176
+ log(`in ${rollout}% rollout, continue`);
177
+ }
168
178
  info.description = info.description ?? '';
169
179
  updateInfoRef.current = info;
170
180
  setUpdateInfo(info);
package/src/type.ts CHANGED
@@ -7,6 +7,10 @@ export interface CheckResult {
7
7
  hash?: string;
8
8
  description?: string;
9
9
  metaInfo?: string;
10
+ config?: {
11
+ rollout?: number;
12
+ [key: string]: any;
13
+ };
10
14
  pdiff?: string;
11
15
  diff?: string;
12
16
  full?: string;