react-native-update 10.23.0 → 10.24.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/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
  ### 本地开发
23
23
 
24
24
  ```
25
- $ git clone git@github.com:reactnativecn/react-native-pushy.git
25
+ $ git clone git@github.com:reactnativecn/react-native-update.git
26
26
  $ cd react-native-pushy/Example/testHotUpdate
27
27
  $ yarn
28
28
  $ yarn start
@@ -34,4 +34,4 @@ $ yarn start
34
34
 
35
35
  本组件由[React Native 中文网](https://reactnative.cn/)独家发布,如有定制需求可以[联系我们](https://reactnative.cn/about.html#content)。
36
36
 
37
- 关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-pushy/issues)发帖提问。
37
+ 关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-update/issues)发帖提问。
@@ -0,0 +1 @@
1
+ ["https://cresc-server-pthxtmvcnf.ap-southeast-1.fcapp.run"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.23.0",
3
+ "version": "10.24.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "git+https://github.com/reactnativecn/react-native-pushy.git"
29
+ "url": "git+https://github.com/reactnativecn/react-native-update.git"
30
30
  },
31
31
  "keywords": [
32
32
  "react-native",
@@ -37,13 +37,13 @@
37
37
  "author": "reactnativecn",
38
38
  "license": "MIT",
39
39
  "bugs": {
40
- "url": "https://github.com/reactnativecn/react-native-pushy/issues"
40
+ "url": "https://github.com/reactnativecn/react-native-update/issues"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=16.8.0",
44
44
  "react-native": ">=0.59.0"
45
45
  },
46
- "homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
46
+ "homepage": "https://github.com/reactnativecn/react-native-update#readme",
47
47
  "dependencies": {
48
48
  "nanoid": "^3.3.3",
49
49
  "react-native-url-polyfill": "^2.0.0"
@@ -74,6 +74,5 @@
74
74
  "react-native": "0.73",
75
75
  "ts-jest": "^29.2.5",
76
76
  "typescript": "^5.6.3"
77
- },
78
- "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
77
+ }
79
78
  }
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
18
18
  s.cocoapods_version = '>= 1.6.0'
19
19
  s.platform = :ios, "8.0"
20
20
  s.platforms = { :ios => "11.0" }
21
- s.source = { :git => 'https://github.com/reactnativecn/react-native-pushy.git', :tag => '#{s.version}' }
21
+ s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' }
22
22
  s.source_files = "ios/**/*.{h,m,mm,swift}"
23
23
  s.libraries = 'bz2', 'z'
24
24
  s.vendored_libraries = 'RCTPushy/libRCTPushy.a'
package/src/client.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
1
+ import { CheckResult, ClientOptions, ProgressData, EventType } from './type';
2
2
  import { emptyObj, joinUrls, log, noop, promiseAny, testUrls } from './utils';
3
3
  import { EmitterSubscription, Platform } from 'react-native';
4
4
  import { PermissionsAndroid } from './permissions';
@@ -15,31 +15,48 @@ import {
15
15
  isRolledBack,
16
16
  } from './core';
17
17
 
18
- const defaultServer = {
19
- main: 'https://update.react-native.cn/api',
20
- backups: ['https://update.reactnative.cn/api'],
21
- queryUrls: [
22
- 'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
23
- 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
24
- ],
18
+ const SERVER_PRESETS = {
19
+ // cn
20
+ pushy: {
21
+ main: 'https://update.react-native.cn/api',
22
+ backups: ['https://update.reactnative.cn/api'],
23
+ queryUrls: [
24
+ 'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
25
+ 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints.json',
26
+ ],
27
+ },
28
+ // i18n
29
+ cresc: {
30
+ main: 'https://api.cresc.dev',
31
+ backups: ['https://api.cresc.app'],
32
+ queryUrls: [
33
+ 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints_cresc.json',
34
+ ],
35
+ },
25
36
  };
26
-
27
37
  if (Platform.OS === 'web') {
28
- console.warn('react-native-update 不支持 web 端热更,不会执行操作');
38
+ console.warn(
39
+ 'react-native-update does not support hot updates on the web platform and will not perform any operations',
40
+ );
29
41
  }
30
42
 
43
+ const defaultClientOptions: ClientOptions = {
44
+ appKey: '',
45
+ autoMarkSuccess: true,
46
+ updateStrategy: __DEV__ ? 'alwaysAlert' : 'alertUpdateAndIgnoreError',
47
+ checkStrategy: 'both',
48
+ logger: noop,
49
+ debug: false,
50
+ throwError: false,
51
+ };
52
+
53
+ // for China users
31
54
  export class Pushy {
32
- options: PushyOptions = {
33
- appKey: '',
34
- server: defaultServer,
35
- autoMarkSuccess: true,
36
- updateStrategy: __DEV__ ? 'alwaysAlert' : 'alertUpdateAndIgnoreError',
37
- checkStrategy: 'both',
38
- logger: noop,
39
- debug: false,
40
- throwError: false,
55
+ options: ClientOptions = {
56
+ ...defaultClientOptions,
57
+ server: SERVER_PRESETS.pushy,
41
58
  };
42
-
59
+ clientType: 'pushy' | 'cresc' = 'pushy';
43
60
  lastChecking?: number;
44
61
  lastRespJson?: Promise<any>;
45
62
 
@@ -50,7 +67,7 @@ export class Pushy {
50
67
 
51
68
  static marked = false;
52
69
  static applyingUpdate = false;
53
- version = cInfo.pushy;
70
+ version = cInfo.rnu;
54
71
  loggerPromise = (() => {
55
72
  let resolve: (value?: unknown) => void = () => {};
56
73
  const promise = new Promise(res => {
@@ -62,7 +79,7 @@ export class Pushy {
62
79
  };
63
80
  })();
64
81
 
65
- constructor(options: PushyOptions) {
82
+ constructor(options: ClientOptions) {
66
83
  if (Platform.OS === 'ios' || Platform.OS === 'android') {
67
84
  if (!options.appKey) {
68
85
  throw new Error('appKey is required');
@@ -79,7 +96,7 @@ export class Pushy {
79
96
  }
80
97
  }
81
98
 
82
- setOptions = (options: Partial<PushyOptions>) => {
99
+ setOptions = (options: Partial<ClientOptions>) => {
83
100
  for (const [key, value] of Object.entries(options)) {
84
101
  if (value !== undefined) {
85
102
  (this.options as any)[key] = value;
@@ -124,10 +141,10 @@ export class Pushy {
124
141
  return `${endpoint}/checkUpdate/${this.options.appKey}`;
125
142
  };
126
143
  static assertHash = (hash: string) => {
127
- if (!Pushy.downloadedHash) {
144
+ if (!this.downloadedHash) {
128
145
  return;
129
146
  }
130
- if (hash !== Pushy.downloadedHash) {
147
+ if (hash !== this.downloadedHash) {
131
148
  log(`use downloaded hash ${Pushy.downloadedHash} first`);
132
149
  return;
133
150
  }
@@ -144,7 +161,7 @@ export class Pushy {
144
161
  switchVersion = async (hash: string) => {
145
162
  if (__DEV__) {
146
163
  console.warn(
147
- '您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。',
164
+ 'switchVersion() is not supported in development environment; no action taken.',
148
165
  );
149
166
  return;
150
167
  }
@@ -158,7 +175,7 @@ export class Pushy {
158
175
  switchVersionLater = async (hash: string) => {
159
176
  if (__DEV__) {
160
177
  console.warn(
161
- '您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。',
178
+ 'switchVersionLater() is not supported in development environment; no action taken.',
162
179
  );
163
180
  return;
164
181
  }
@@ -170,19 +187,19 @@ export class Pushy {
170
187
  checkUpdate = async (extra?: Record<string, any>) => {
171
188
  if (__DEV__ && !this.options.debug) {
172
189
  console.info(
173
- '您当前处于开发环境且未启用 debug,不会进行热更检查。如需在开发环境中调试热更,请在 client 中设置 debug true',
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.',
174
191
  );
175
192
  return;
176
193
  }
177
194
  if (Platform.OS === 'web') {
178
- console.warn('web 端不支持热更新检查');
195
+ console.warn('web platform does not support hot update check');
179
196
  return;
180
197
  }
181
198
  if (
182
199
  this.options.beforeCheckUpdate &&
183
200
  (await this.options.beforeCheckUpdate()) === false
184
201
  ) {
185
- log('beforeCheckUpdate 返回 false, 忽略检查');
202
+ log('beforeCheckUpdate returned false, skipping check');
186
203
  return;
187
204
  }
188
205
  const now = Date.now();
@@ -310,7 +327,7 @@ export class Pushy {
310
327
  this.options.beforeDownloadUpdate &&
311
328
  (await this.options.beforeDownloadUpdate(info)) === false
312
329
  ) {
313
- log('beforeDownloadUpdate 返回 false, 忽略下载');
330
+ log('beforeDownloadUpdate returned false, skipping download');
314
331
  return;
315
332
  }
316
333
  if (!info.update || !hash) {
@@ -489,3 +506,12 @@ export class Pushy {
489
506
  }
490
507
  };
491
508
  }
509
+
510
+ // 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
+ }
package/src/context.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createContext, useContext } from 'react';
2
2
  import { CheckResult, ProgressData } from './type';
3
- import { Pushy } from './client';
3
+ import { Pushy, Cresc } from './client';
4
4
 
5
5
  const noop = () => {};
6
6
  const asyncNoop = () => Promise.resolve();
@@ -19,7 +19,7 @@ export const defaultContext = {
19
19
  packageVersion: '',
20
20
  };
21
21
 
22
- export const PushyContext = createContext<{
22
+ export const UpdateContext = createContext<{
23
23
  checkUpdate: () => Promise<void>;
24
24
  switchVersion: () => Promise<void>;
25
25
  switchVersionLater: () => Promise<void>;
@@ -35,10 +35,14 @@ export const PushyContext = createContext<{
35
35
  parseTestQrCode: (code: string) => boolean;
36
36
  currentHash: string;
37
37
  packageVersion: string;
38
- client?: Pushy;
38
+ client?: Pushy | Cresc;
39
39
  progress?: ProgressData;
40
40
  updateInfo?: CheckResult;
41
41
  lastError?: Error;
42
42
  }>(defaultContext);
43
43
 
44
- export const usePushy = () => useContext(PushyContext);
44
+ export const useUpdate = () => useContext(UpdateContext);
45
+
46
+ export const usePushy = useUpdate;
47
+
48
+ export const useCresc = useUpdate;
package/src/core.ts CHANGED
@@ -13,8 +13,12 @@ export const PushyModule =
13
13
  ? require('./NativePushy').default
14
14
  : NativeModules.Pushy;
15
15
 
16
+ export const UpdateModule = PushyModule;
17
+
16
18
  if (!PushyModule) {
17
- throw new Error('react-native-update 模块无法加载,请对照安装文档检查配置。');
19
+ throw new Error(
20
+ 'Failed to load react-native-update native module, please try to recompile',
21
+ );
18
22
  }
19
23
 
20
24
  const PushyConstants = isTurboModuleEnabled
@@ -31,12 +35,6 @@ export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
31
35
  export const buildTime: string = PushyConstants.buildTime;
32
36
  let uuid = PushyConstants.uuid;
33
37
 
34
- if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
35
- throw new Error(
36
- 'react-native-update 模块无法加载,请对照文档检查 Bundle URL 的配置',
37
- );
38
- }
39
-
40
38
  export function setLocalHashInfo(hash: string, info: Record<string, any>) {
41
39
  PushyModule.setLocalHashInfo(hash, JSON.stringify(info));
42
40
  }
@@ -63,7 +61,7 @@ if (!uuid) {
63
61
  log('uuid: ' + uuid);
64
62
 
65
63
  export const cInfo = {
66
- pushy: require('../package.json').version,
64
+ rnu: require('../package.json').version,
67
65
  rn: RNVersion,
68
66
  os: Platform.OS + ' ' + Platform.Version,
69
67
  uuid,
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { Pushy } from './client';
2
- export { PushyContext, usePushy } from './context';
3
- export { PushyProvider } from './provider';
4
- export { PushyModule } from './core';
1
+ export { Pushy, Cresc } from './client';
2
+ export { UpdateContext, usePushy, useCresc } from './context';
3
+ export { PushyProvider, UpdateProvider } from './provider';
4
+ export { PushyModule, UpdateModule } from './core';
package/src/provider.tsx CHANGED
@@ -12,19 +12,19 @@ import {
12
12
  Platform,
13
13
  Linking,
14
14
  } from 'react-native';
15
- import { Pushy } from './client';
15
+ import { Pushy, Cresc } from './client';
16
16
  import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
17
- import { CheckResult, ProgressData, PushyTestPayload } from './type';
18
- import { PushyContext } from './context';
17
+ import { CheckResult, ProgressData, UpdateTestPayload } from './type';
18
+ import { UpdateContext } from './context';
19
19
  import { URL } from 'react-native-url-polyfill';
20
20
  import { isInRollout } from './isInRollout';
21
21
  import { log } from './utils';
22
22
 
23
- export const PushyProvider = ({
23
+ export const UpdateProvider = ({
24
24
  client,
25
25
  children,
26
26
  }: {
27
- client: Pushy;
27
+ client: Pushy | Cresc;
28
28
  children: ReactNode;
29
29
  }) => {
30
30
  const { options } = client;
@@ -275,8 +275,8 @@ export const PushyProvider = ({
275
275
  }, [checkUpdate, options, dismissError, markSuccess]);
276
276
 
277
277
  const parseTestPayload = useCallback(
278
- (payload: PushyTestPayload) => {
279
- if (payload && payload.type && payload.type.startsWith('__rnPushy')) {
278
+ (payload: UpdateTestPayload) => {
279
+ if (payload && payload.type && payload.type.startsWith('__rnUpdate')) {
280
280
  const logger = options.logger || (() => {});
281
281
  options.logger = ({ type, data }) => {
282
282
  logger({ type, data });
@@ -286,8 +286,8 @@ export const PushyProvider = ({
286
286
  checkUpdate({ extra: { toHash: payload.data } }).then(() => {
287
287
  if (updateInfoRef.current && updateInfoRef.current.upToDate) {
288
288
  Alert.alert(
289
- '提示',
290
- '当前尚未检测到更新版本,如果是首次扫码,请等待服务器端生成补丁包后再试(约10秒)',
289
+ 'Info',
290
+ 'No update found, please wait 10s for the server to generate the patch package',
291
291
  );
292
292
  }
293
293
  options.logger = logger;
@@ -301,7 +301,7 @@ export const PushyProvider = ({
301
301
  );
302
302
 
303
303
  const parseTestQrCode = useCallback(
304
- (code: string | PushyTestPayload) => {
304
+ (code: string | UpdateTestPayload) => {
305
305
  try {
306
306
  const payload = typeof code === 'string' ? JSON.parse(code) : code;
307
307
  return parseTestPayload(payload);
@@ -335,7 +335,7 @@ export const PushyProvider = ({
335
335
  }, [parseTestPayload]);
336
336
 
337
337
  return (
338
- <PushyContext.Provider
338
+ <UpdateContext.Provider
339
339
  value={{
340
340
  checkUpdate,
341
341
  switchVersion,
@@ -354,6 +354,8 @@ export const PushyProvider = ({
354
354
  parseTestQrCode,
355
355
  }}>
356
356
  {children}
357
- </PushyContext.Provider>
357
+ </UpdateContext.Provider>
358
358
  );
359
359
  };
360
+
361
+ export const PushyProvider = UpdateProvider;
package/src/type.ts CHANGED
@@ -44,7 +44,7 @@ export type EventType =
44
44
  export interface EventData {
45
45
  currentVersion: string;
46
46
  cInfo: {
47
- pushy: string;
47
+ rnu: string;
48
48
  rn: string;
49
49
  os: string;
50
50
  uuid: string;
@@ -65,15 +65,15 @@ export type UpdateEventsLogger = ({
65
65
  data: EventData;
66
66
  }) => void;
67
67
 
68
- export interface PushyServerConfig {
68
+ export interface UpdateServerConfig {
69
69
  main: string;
70
70
  backups?: string[];
71
71
  queryUrls?: string[];
72
72
  }
73
73
 
74
- export interface PushyOptions {
74
+ export interface ClientOptions {
75
75
  appKey: string;
76
- server?: PushyServerConfig;
76
+ server?: UpdateServerConfig;
77
77
  logger?: UpdateEventsLogger;
78
78
  updateStrategy?:
79
79
  | 'alwaysAlert'
@@ -90,7 +90,7 @@ export interface PushyOptions {
90
90
  beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
91
91
  }
92
92
 
93
- export interface PushyTestPayload {
93
+ export interface UpdateTestPayload {
94
94
  type: '__rnPushyVersionHash' | string | null;
95
95
  data: any;
96
96
  }
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Platform } from 'react-native';
2
2
 
3
3
  export function log(...args: any[]) {
4
- console.log('pushy: ', ...args);
4
+ console.log('react-native-update: ', ...args);
5
5
  }
6
6
 
7
7
  export function promiseAny<T>(promises: Promise<T>[]) {