Skip to content

Commit

Permalink
v10.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Aug 26, 2024
1 parent d000c40 commit 94d2e18
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
25 changes: 11 additions & 14 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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';
Expand Down
4 changes: 1 addition & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 4 additions & 6 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 94d2e18

Please sign in to comment.