mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 10:21:37 +08:00
v10.13.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.12.0",
|
||||
"version": "10.13.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
||||
import { log, testUrls } from './utils';
|
||||
import { joinUrls, log, testUrls } from './utils';
|
||||
import { EmitterSubscription, Platform } from 'react-native';
|
||||
import { PermissionsAndroid } from './permissions';
|
||||
import {
|
||||
@@ -64,8 +64,7 @@ export class Pushy {
|
||||
setOptions = (options: Partial<PushyOptions>) => {
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (value !== undefined) {
|
||||
// @ts-expect-error
|
||||
this.options[key] = value;
|
||||
(this.options as any)[key] = value;
|
||||
if (key === 'logger') {
|
||||
if (isRolledBack) {
|
||||
this.report({
|
||||
@@ -272,12 +271,10 @@ export class Pushy {
|
||||
) => {
|
||||
const {
|
||||
hash,
|
||||
diffUrl: _diffUrl,
|
||||
diffUrls,
|
||||
pdiffUrl: _pdiffUrl,
|
||||
pdiffUrls,
|
||||
updateUrl: _updateUrl,
|
||||
updateUrls,
|
||||
diff,
|
||||
pdiff,
|
||||
full,
|
||||
paths = [],
|
||||
name,
|
||||
description,
|
||||
metaInfo,
|
||||
@@ -316,7 +313,7 @@ export class Pushy {
|
||||
let succeeded = '';
|
||||
this.report({ type: 'downloading' });
|
||||
let lastError: any;
|
||||
const diffUrl = (await testUrls(diffUrls)) || _diffUrl;
|
||||
const diffUrl = await testUrls(joinUrls(paths, diff));
|
||||
if (diffUrl) {
|
||||
log('downloading diff');
|
||||
try {
|
||||
@@ -335,7 +332,7 @@ export class Pushy {
|
||||
}
|
||||
}
|
||||
}
|
||||
const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
|
||||
const pdiffUrl = await testUrls(joinUrls(paths, pdiff));
|
||||
if (!succeeded && pdiffUrl) {
|
||||
log('downloading pdiff');
|
||||
try {
|
||||
@@ -353,12 +350,12 @@ export class Pushy {
|
||||
}
|
||||
}
|
||||
}
|
||||
const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
|
||||
if (!succeeded && updateUrl) {
|
||||
const fullUrl = await testUrls(joinUrls(paths, full));
|
||||
if (!succeeded && fullUrl) {
|
||||
log('downloading full patch');
|
||||
try {
|
||||
await PushyModule.downloadFullUpdate({
|
||||
updateUrl: updateUrl,
|
||||
updateUrl: fullUrl,
|
||||
hash,
|
||||
});
|
||||
succeeded = 'full';
|
||||
|
@@ -4,9 +4,7 @@ const {
|
||||
version: v,
|
||||
} = require('react-native/Libraries/Core/ReactNativeVersion');
|
||||
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
|
||||
const isTurboModuleEnabled =
|
||||
// @ts-expect-error
|
||||
global.__turboModuleProxy != null;
|
||||
const isTurboModuleEnabled = (global as any).__turboModuleProxy != null;
|
||||
|
||||
export const PushyModule =
|
||||
Platform.OS === 'web'
|
||||
|
10
src/type.ts
10
src/type.ts
@@ -7,12 +7,10 @@ export interface CheckResult {
|
||||
hash?: string;
|
||||
description?: string;
|
||||
metaInfo?: string;
|
||||
pdiffUrl?: string;
|
||||
pdiffUrls?: string[];
|
||||
diffUrl?: string;
|
||||
diffUrls?: string[];
|
||||
updateUrl?: string;
|
||||
updateUrls?: string[];
|
||||
pdiff?: string;
|
||||
diff?: string;
|
||||
full?: string;
|
||||
paths?: string[];
|
||||
paused?: 'app' | 'package';
|
||||
message?: string;
|
||||
}
|
||||
|
11
src/utils.ts
11
src/utils.ts
@@ -31,9 +31,18 @@ const ping =
|
||||
|
||||
const canUseGoogle = ping('https://www.google.com');
|
||||
|
||||
export function joinUrls(paths: string[], fileName?: string) {
|
||||
if (fileName) {
|
||||
return paths.map(path => 'https://' + path + '/' + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
export const testUrls = async (urls?: string[]) => {
|
||||
if (!urls?.length || (await canUseGoogle)) {
|
||||
if (!urls?.length) {
|
||||
return null;
|
||||
}
|
||||
if (await canUseGoogle) {
|
||||
return urls[0];
|
||||
}
|
||||
return Promise.race(urls.map(ping)).catch(() => null);
|
||||
};
|
||||
|
Reference in New Issue
Block a user