diff --git a/package.json b/package.json index 2ca371e1..906afe16 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/client.ts b/src/client.ts index 5c91ba3c..246574c3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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) => { 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'; diff --git a/src/core.ts b/src/core.ts index 6d76da12..d96e7b9e 100644 --- a/src/core.ts +++ b/src/core.ts @@ -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' diff --git a/src/type.ts b/src/type.ts index 175ee405..ed442a75 100644 --- a/src/type.ts +++ b/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; } diff --git a/src/utils.ts b/src/utils.ts index e93515c3..ff05a472 100644 --- a/src/utils.ts +++ b/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); };