react-native-update 10.23.1 → 10.24.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/endpoints_cresc.json +1 -0
- package/package.json +2 -3
- package/src/client.ts +57 -31
- package/src/context.ts +8 -4
- package/src/core.ts +6 -8
- package/src/index.ts +4 -4
- package/src/provider.tsx +14 -12
- package/src/type.ts +5 -5
- package/src/utils.ts +1 -1
|
@@ -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.
|
|
3
|
+
"version": "10.24.1",
|
|
4
4
|
"description": "react-native hot update",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"scripts": {
|
|
@@ -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
|
}
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CheckResult,
|
|
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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'https://
|
|
23
|
-
|
|
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(
|
|
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:
|
|
33
|
-
|
|
34
|
-
server:
|
|
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.
|
|
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:
|
|
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<
|
|
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 (!
|
|
144
|
+
if (!this.downloadedHash) {
|
|
128
145
|
return;
|
|
129
146
|
}
|
|
130
|
-
if (hash !==
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
-
'
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|
-
console.warn(
|
|
36
|
-
'react-native-update 没有检测到 Bundle URL 的配置,这可能是因为您使用了某种懒加载机制(比如使用 expo,可忽略本警告),或是 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
|
-
|
|
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 {
|
|
3
|
-
export { PushyProvider } from './provider';
|
|
4
|
-
export { PushyModule } from './core';
|
|
1
|
+
export { Pushy, Cresc } from './client';
|
|
2
|
+
export { UpdateContext, usePushy, useCresc, useUpdate } 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,
|
|
18
|
-
import {
|
|
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
|
|
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:
|
|
279
|
-
if (payload && payload.type && payload.type.startsWith('
|
|
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
|
-
'
|
|
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 |
|
|
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
|
-
<
|
|
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
|
-
</
|
|
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
|
-
|
|
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
|
|
68
|
+
export interface UpdateServerConfig {
|
|
69
69
|
main: string;
|
|
70
70
|
backups?: string[];
|
|
71
71
|
queryUrls?: string[];
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export interface
|
|
74
|
+
export interface ClientOptions {
|
|
75
75
|
appKey: string;
|
|
76
|
-
server?:
|
|
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
|
|
93
|
+
export interface UpdateTestPayload {
|
|
94
94
|
type: '__rnPushyVersionHash' | string | null;
|
|
95
95
|
data: any;
|
|
96
96
|
}
|