react-native-update 8.5.6 → 8.5.7
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/.cursor/mcp.json +11 -0
- package/dist/endpoint.js +4 -8
- package/dist/main.js +13 -13
- package/dist/simpleUpdate.d.ts +1 -1
- package/dist/simpleUpdate.js +18 -9
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +31 -8
- package/lib/endpoint.ts +1 -4
- package/lib/main.ts +3 -3
- package/lib/utils.ts +32 -4
- package/package.json +2 -2
- package/.swcrc +0 -15
package/.cursor/mcp.json
ADDED
package/dist/endpoint.js
CHANGED
|
@@ -9,13 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.updateBackupEndpoints = updateBackupEndpoints;
|
|
13
|
+
exports.getCheckUrl = getCheckUrl;
|
|
14
|
+
exports.setCustomEndpoints = setCustomEndpoints;
|
|
13
15
|
const utils_1 = require("./utils");
|
|
14
16
|
let currentEndpoint = 'https://update.react-native.cn/api';
|
|
15
|
-
let backupEndpoints = [
|
|
16
|
-
'https://pushy-koa-qgbgqmcpis.cn-beijing.fcapp.run',
|
|
17
|
-
'https://update.reactnative.cn/api',
|
|
18
|
-
];
|
|
17
|
+
let backupEndpoints = ['https://update.reactnative.cn/api'];
|
|
19
18
|
let backupEndpointsQueryUrls = [
|
|
20
19
|
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
|
|
21
20
|
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
|
|
@@ -39,11 +38,9 @@ function updateBackupEndpoints() {
|
|
|
39
38
|
return backupEndpoints;
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
|
-
exports.updateBackupEndpoints = updateBackupEndpoints;
|
|
43
41
|
function getCheckUrl(APPKEY, endpoint = currentEndpoint) {
|
|
44
42
|
return `${endpoint}/checkUpdate/${APPKEY}`;
|
|
45
43
|
}
|
|
46
|
-
exports.getCheckUrl = getCheckUrl;
|
|
47
44
|
/**
|
|
48
45
|
* @param {string} main - The main api endpoint
|
|
49
46
|
* @param {string[]} [backups] - The back up endpoints.
|
|
@@ -59,4 +56,3 @@ function setCustomEndpoints({ main, backups, backupQueryUrls, }) {
|
|
|
59
56
|
backupEndpointsQueryUrls = backupQueryUrls;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
|
-
exports.setCustomEndpoints = setCustomEndpoints;
|
package/dist/main.js
CHANGED
|
@@ -9,7 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.cInfo = exports.buildTime = exports.isRolledBack = exports.isFirstTime = exports.currentVersion = exports.packageVersion = exports.downloadRootDir = exports.PushyModule = exports.setCustomEndpoints = void 0;
|
|
13
|
+
exports.getCurrentVersionInfo = getCurrentVersionInfo;
|
|
14
|
+
exports.onPushyEvents = onPushyEvents;
|
|
15
|
+
exports.checkUpdate = checkUpdate;
|
|
16
|
+
exports.downloadUpdate = downloadUpdate;
|
|
17
|
+
exports.switchVersion = switchVersion;
|
|
18
|
+
exports.switchVersionLater = switchVersionLater;
|
|
19
|
+
exports.markSuccess = markSuccess;
|
|
20
|
+
exports.downloadAndInstallApk = downloadAndInstallApk;
|
|
13
21
|
const endpoint_1 = require("./endpoint");
|
|
14
22
|
Object.defineProperty(exports, "setCustomEndpoints", { enumerable: true, get: function () { return endpoint_1.setCustomEndpoints; } });
|
|
15
23
|
const react_native_1 = require("react-native");
|
|
@@ -46,7 +54,6 @@ function getCurrentVersionInfo() {
|
|
|
46
54
|
return exports.currentVersion ? (yield getLocalHashInfo(exports.currentVersion)) || {} : {};
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
|
-
exports.getCurrentVersionInfo = getCurrentVersionInfo;
|
|
50
57
|
const eventEmitter = new react_native_1.NativeEventEmitter(exports.PushyModule);
|
|
51
58
|
if (!uuid) {
|
|
52
59
|
uuid = require('nanoid/non-secure').nanoid();
|
|
@@ -65,7 +72,6 @@ function onPushyEvents(customReporter) {
|
|
|
65
72
|
});
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
|
-
exports.onPushyEvents = onPushyEvents;
|
|
69
75
|
function report({ type, message = '', data = {}, }) {
|
|
70
76
|
(0, utils_1.logger)(type + ' ' + message);
|
|
71
77
|
reporter({
|
|
@@ -119,7 +125,7 @@ function checkUpdate(APPKEY) {
|
|
|
119
125
|
};
|
|
120
126
|
let resp;
|
|
121
127
|
try {
|
|
122
|
-
resp = yield
|
|
128
|
+
resp = yield (0, utils_1.enhancedFetch)((0, endpoint_1.getCheckUrl)(APPKEY), fetchPayload);
|
|
123
129
|
}
|
|
124
130
|
catch (e) {
|
|
125
131
|
report({
|
|
@@ -129,7 +135,7 @@ function checkUpdate(APPKEY) {
|
|
|
129
135
|
const backupEndpoints = yield (0, endpoint_1.updateBackupEndpoints)();
|
|
130
136
|
if (backupEndpoints) {
|
|
131
137
|
try {
|
|
132
|
-
resp = yield (0, utils_1.promiseAny)(backupEndpoints.map((endpoint) =>
|
|
138
|
+
resp = yield (0, utils_1.promiseAny)(backupEndpoints.map((endpoint) => (0, utils_1.enhancedFetch)((0, endpoint_1.getCheckUrl)(APPKEY, endpoint), fetchPayload)));
|
|
133
139
|
}
|
|
134
140
|
catch (_a) { }
|
|
135
141
|
}
|
|
@@ -155,7 +161,6 @@ function checkUpdate(APPKEY) {
|
|
|
155
161
|
return result;
|
|
156
162
|
});
|
|
157
163
|
}
|
|
158
|
-
exports.checkUpdate = checkUpdate;
|
|
159
164
|
function checkOperation(op) {
|
|
160
165
|
if (!Array.isArray(op)) {
|
|
161
166
|
return;
|
|
@@ -267,7 +272,6 @@ function downloadUpdate(options, eventListeners) {
|
|
|
267
272
|
return options.hash;
|
|
268
273
|
});
|
|
269
274
|
}
|
|
270
|
-
exports.downloadUpdate = downloadUpdate;
|
|
271
275
|
function assertHash(hash) {
|
|
272
276
|
if (!downloadedHash) {
|
|
273
277
|
(0, utils_1.logger)(`no downloaded hash`);
|
|
@@ -286,7 +290,6 @@ function switchVersion(hash) {
|
|
|
286
290
|
exports.PushyModule.reloadUpdate({ hash });
|
|
287
291
|
}
|
|
288
292
|
}
|
|
289
|
-
exports.switchVersion = switchVersion;
|
|
290
293
|
function switchVersionLater(hash) {
|
|
291
294
|
(0, utils_1.assertRelease)();
|
|
292
295
|
if (assertHash(hash)) {
|
|
@@ -294,7 +297,6 @@ function switchVersionLater(hash) {
|
|
|
294
297
|
exports.PushyModule.setNeedUpdate({ hash });
|
|
295
298
|
}
|
|
296
299
|
}
|
|
297
|
-
exports.switchVersionLater = switchVersionLater;
|
|
298
300
|
let marked = false;
|
|
299
301
|
function markSuccess() {
|
|
300
302
|
(0, utils_1.assertRelease)();
|
|
@@ -306,9 +308,8 @@ function markSuccess() {
|
|
|
306
308
|
exports.PushyModule.markSuccess();
|
|
307
309
|
report({ type: 'markSuccess' });
|
|
308
310
|
}
|
|
309
|
-
|
|
310
|
-
function
|
|
311
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
311
|
+
function downloadAndInstallApk(_a) {
|
|
312
|
+
return __awaiter(this, arguments, void 0, function* ({ url, onDownloadProgress, }) {
|
|
312
313
|
if (react_native_1.Platform.OS !== 'android') {
|
|
313
314
|
return;
|
|
314
315
|
}
|
|
@@ -343,4 +344,3 @@ function downloadAndInstallApk({ url, onDownloadProgress, }) {
|
|
|
343
344
|
progressHandler && progressHandler.remove();
|
|
344
345
|
});
|
|
345
346
|
}
|
|
346
|
-
exports.downloadAndInstallApk = downloadAndInstallApk;
|
package/dist/simpleUpdate.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function simpleUpdate(WrappedComponent: ComponentType, options?:
|
|
|
5
5
|
appKey?: string;
|
|
6
6
|
onPushyEvents?: UpdateEventsListener;
|
|
7
7
|
}): React.ComponentType | {
|
|
8
|
-
new (props: {}
|
|
8
|
+
new (props: {}): {
|
|
9
9
|
stateListener: NativeEventSubscription | null;
|
|
10
10
|
componentDidMount(): void;
|
|
11
11
|
componentWillUnmount(): void;
|
package/dist/simpleUpdate.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -32,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
42
|
});
|
|
33
43
|
};
|
|
34
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.simpleUpdate =
|
|
45
|
+
exports.simpleUpdate = simpleUpdate;
|
|
36
46
|
const react_1 = __importStar(require("react"));
|
|
37
47
|
const react_native_1 = require("react-native");
|
|
38
48
|
const main_1 = require("./main");
|
|
@@ -143,4 +153,3 @@ function simpleUpdate(WrappedComponent, options = {}) {
|
|
|
143
153
|
}
|
|
144
154
|
};
|
|
145
155
|
}
|
|
146
|
-
exports.simpleUpdate = simpleUpdate;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function promiseAny<T>(promises: Promise<T>[]): Promise<T>;
|
|
2
2
|
export declare function logger(...args: any[]): void;
|
|
3
3
|
export declare function assertRelease(): void;
|
|
4
|
-
export declare const testUrls: (urls?: string[]) => Promise<
|
|
4
|
+
export declare const testUrls: (urls?: string[]) => Promise<any>;
|
|
5
|
+
export declare const enhancedFetch: (url: string, params: Parameters<typeof fetch>[1], isRetry?: boolean) => any;
|
package/dist/utils.js
CHANGED
|
@@ -9,7 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.enhancedFetch = exports.testUrls = void 0;
|
|
13
|
+
exports.promiseAny = promiseAny;
|
|
14
|
+
exports.logger = logger;
|
|
15
|
+
exports.assertRelease = assertRelease;
|
|
13
16
|
const react_native_1 = require("react-native");
|
|
14
17
|
function promiseAny(promises) {
|
|
15
18
|
return new Promise((resolve, reject) => {
|
|
@@ -26,31 +29,28 @@ function promiseAny(promises) {
|
|
|
26
29
|
});
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
|
-
exports.promiseAny = promiseAny;
|
|
30
32
|
function logger(...args) {
|
|
31
33
|
console.log('Pushy: ', ...args);
|
|
32
34
|
}
|
|
33
|
-
exports.logger = logger;
|
|
34
35
|
function assertRelease() {
|
|
35
36
|
if (__DEV__) {
|
|
36
37
|
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
exports.assertRelease = assertRelease;
|
|
40
40
|
const ping = react_native_1.Platform.OS === 'web'
|
|
41
41
|
? Promise.resolve
|
|
42
42
|
: (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
let pingFinished = false;
|
|
44
44
|
return Promise.race([
|
|
45
|
-
|
|
45
|
+
(0, exports.enhancedFetch)(url, {
|
|
46
46
|
method: 'HEAD',
|
|
47
47
|
})
|
|
48
|
-
.then(({ status, statusText }) => {
|
|
48
|
+
.then(({ status, statusText, url: finalUrl }) => {
|
|
49
49
|
pingFinished = true;
|
|
50
50
|
if (status === 200) {
|
|
51
|
-
return
|
|
51
|
+
return finalUrl;
|
|
52
52
|
}
|
|
53
|
-
logger('ping failed',
|
|
53
|
+
logger('ping failed', finalUrl, status, statusText);
|
|
54
54
|
throw new Error('Ping failed');
|
|
55
55
|
})
|
|
56
56
|
.catch((e) => {
|
|
@@ -81,3 +81,26 @@ const testUrls = (urls) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
81
81
|
return urls[0];
|
|
82
82
|
});
|
|
83
83
|
exports.testUrls = testUrls;
|
|
84
|
+
// export const isAndroid70AndBelow = () => {
|
|
85
|
+
// // android 7.0 and below devices do not support letsencrypt cert
|
|
86
|
+
// // https://letsencrypt.org/2023/07/10/cross-sign-expiration/
|
|
87
|
+
// return Platform.OS === 'android' && Platform.Version <= 24;
|
|
88
|
+
// };
|
|
89
|
+
const enhancedFetch = (url_1, params_1, ...args_1) => __awaiter(void 0, [url_1, params_1, ...args_1], void 0, function* (url, params, isRetry = false) {
|
|
90
|
+
return fetch(url, params)
|
|
91
|
+
.then((r) => {
|
|
92
|
+
if (r.ok) {
|
|
93
|
+
return r;
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`${r.status} ${r.statusText}`);
|
|
96
|
+
})
|
|
97
|
+
.catch((e) => {
|
|
98
|
+
logger('fetch error', url, e);
|
|
99
|
+
if (isRetry) {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
logger('trying fallback to http');
|
|
103
|
+
return (0, exports.enhancedFetch)(url.replace('https', 'http'), params, true);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
exports.enhancedFetch = enhancedFetch;
|
package/lib/endpoint.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { logger, promiseAny } from './utils';
|
|
2
2
|
|
|
3
3
|
let currentEndpoint = 'https://update.react-native.cn/api';
|
|
4
|
-
let backupEndpoints: string[] = [
|
|
5
|
-
'https://pushy-koa-qgbgqmcpis.cn-beijing.fcapp.run',
|
|
6
|
-
'https://update.reactnative.cn/api',
|
|
7
|
-
];
|
|
4
|
+
let backupEndpoints: string[] = ['https://update.reactnative.cn/api'];
|
|
8
5
|
let backupEndpointsQueryUrls = [
|
|
9
6
|
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
|
|
10
7
|
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
|
package/lib/main.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
UpdateAvailableResult,
|
|
17
17
|
UpdateEventsListener,
|
|
18
18
|
} from './type';
|
|
19
|
-
import { assertRelease, logger, promiseAny, testUrls } from './utils';
|
|
19
|
+
import { assertRelease, enhancedFetch, logger, promiseAny, testUrls } from './utils';
|
|
20
20
|
export { setCustomEndpoints };
|
|
21
21
|
const {
|
|
22
22
|
version: v,
|
|
@@ -153,7 +153,7 @@ export async function checkUpdate(APPKEY: string) {
|
|
|
153
153
|
};
|
|
154
154
|
let resp;
|
|
155
155
|
try {
|
|
156
|
-
resp = await
|
|
156
|
+
resp = await enhancedFetch(getCheckUrl(APPKEY), fetchPayload);
|
|
157
157
|
} catch (e: any) {
|
|
158
158
|
report({
|
|
159
159
|
type: 'errorChecking',
|
|
@@ -164,7 +164,7 @@ export async function checkUpdate(APPKEY: string) {
|
|
|
164
164
|
try {
|
|
165
165
|
resp = await promiseAny(
|
|
166
166
|
backupEndpoints.map((endpoint) =>
|
|
167
|
-
|
|
167
|
+
enhancedFetch(getCheckUrl(APPKEY, endpoint), fetchPayload),
|
|
168
168
|
),
|
|
169
169
|
);
|
|
170
170
|
} catch {}
|
package/lib/utils.ts
CHANGED
|
@@ -33,15 +33,15 @@ const ping =
|
|
|
33
33
|
: async (url: string) => {
|
|
34
34
|
let pingFinished = false;
|
|
35
35
|
return Promise.race([
|
|
36
|
-
|
|
36
|
+
enhancedFetch(url, {
|
|
37
37
|
method: 'HEAD',
|
|
38
38
|
})
|
|
39
|
-
.then(({ status, statusText }) => {
|
|
39
|
+
.then(({ status, statusText, url: finalUrl }) => {
|
|
40
40
|
pingFinished = true;
|
|
41
41
|
if (status === 200) {
|
|
42
|
-
return
|
|
42
|
+
return finalUrl;
|
|
43
43
|
}
|
|
44
|
-
logger('ping failed',
|
|
44
|
+
logger('ping failed', finalUrl, status, statusText);
|
|
45
45
|
throw new Error('Ping failed');
|
|
46
46
|
})
|
|
47
47
|
.catch((e) => {
|
|
@@ -73,3 +73,31 @@ export const testUrls = async (urls?: string[]) => {
|
|
|
73
73
|
logger('all ping failed, use first url:', urls[0]);
|
|
74
74
|
return urls[0];
|
|
75
75
|
};
|
|
76
|
+
|
|
77
|
+
// export const isAndroid70AndBelow = () => {
|
|
78
|
+
// // android 7.0 and below devices do not support letsencrypt cert
|
|
79
|
+
// // https://letsencrypt.org/2023/07/10/cross-sign-expiration/
|
|
80
|
+
// return Platform.OS === 'android' && Platform.Version <= 24;
|
|
81
|
+
// };
|
|
82
|
+
|
|
83
|
+
export const enhancedFetch = async (
|
|
84
|
+
url: string,
|
|
85
|
+
params: Parameters<typeof fetch>[1],
|
|
86
|
+
isRetry = false,
|
|
87
|
+
) => {
|
|
88
|
+
return fetch(url, params)
|
|
89
|
+
.then((r) => {
|
|
90
|
+
if (r.ok) {
|
|
91
|
+
return r;
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`${r.status} ${r.statusText}`);
|
|
94
|
+
})
|
|
95
|
+
.catch((e) => {
|
|
96
|
+
logger('fetch error', url, e);
|
|
97
|
+
if (isRetry) {
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
logger('trying fallback to http');
|
|
101
|
+
return enhancedFetch(url.replace('https', 'http'), params, true);
|
|
102
|
+
});
|
|
103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.7",
|
|
4
4
|
"description": "react-native hot update",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"prepublishOnly": "yarn submodule && yarn build",
|
|
9
9
|
"build": "yarn clean && tsc",
|
|
10
10
|
"clean": "rm -rf dist",
|
|
11
11
|
"submodule": "git submodule update --init --recursive",
|