1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

chore: lint

This commit is contained in:
sunnylqm 2024-03-07 22:11:44 +08:00
parent 22c4b01ead
commit 94cf96a0e5
No known key found for this signature in database
13 changed files with 627 additions and 383 deletions

View File

@ -1,4 +0,0 @@
{
"root": true,
"extends": "@react-native"
}

4
.eslintrc.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native',
};

View File

@ -41,14 +41,17 @@ export const testFunctionDefaultRegion = functions.https.onCall(data => {
const { type, asError, inputData } = data;
if (!Object.hasOwnProperty.call(SAMPLE_DATA, type)) {
throw new functions.https.HttpsError('invalid-argument', 'Invalid test requested.');
throw new functions.https.HttpsError(
'invalid-argument',
'Invalid test requested.',
);
}
const outputData = SAMPLE_DATA[type];
try {
assert.deepEqual(outputData, inputData);
} catch (e) {
} catch (e: any) {
console.error(e);
throw new functions.https.HttpsError(
'invalid-argument',

View File

@ -1,4 +1,6 @@
module.exports = {
trailingComma: 'all',
arrowParens: 'avoid',
bracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};

View File

@ -190,7 +190,7 @@ export default function TestConsole({visible}) {
}
setAlertVisible(true);
setAlertMsg('done');
} catch (e) {
} catch (e: any) {
setAlertVisible(true);
setAlertMsg(e.message);
}

3
babel.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
};

View File

@ -4,7 +4,8 @@
"description": "react-native hot update",
"main": "src/index.ts",
"scripts": {
"prepublish": "yarn submodule",
"prepack": "yarn submodule && yarn lint",
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
"submodule": "git submodule update --init --recursive",
"test": "echo \"Error: no test specified\" && exit 1",
"build-lib": "yarn submodule && $ANDROID_HOME/ndk/20.1.5948944/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_APPLICATION_MK=android/jni/Application.mk NDK_LIBS_OUT=android/lib",
@ -56,16 +57,20 @@
]
},
"devDependencies": {
"@babel/core": "^7.24.0",
"@react-native/babel-preset": "^0.73.21",
"@react-native/eslint-config": "^0.73.2",
"@react-native/typescript-config": "^0.74.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^29.2.1",
"@types/node": "^20.8.9",
"@types/react": "^18.2.46",
"detox": "^20.5.0",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-plugin-ft-flow": "^3.0.7",
"jest": "^29.7.0",
"firebase-tools": "^11.24.1",
"fs-extra": "^9.1.0",
"jest": "^29.2.1",
"pod-install": "^0.1.37",
"prettier": "^2",
"react": "18.2.0",

View File

@ -37,11 +37,11 @@ export class Pushy {
logger: noop,
};
lastChecking: number;
lastChecking?: number;
lastRespJson?: Promise<any>;
progressHandlers: Record<string, EmitterSubscription> = {};
downloadedHash: string;
downloadedHash?: string;
marked = false;
applyingUpdate = false;
@ -57,6 +57,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;
if (key === 'logger') {
if (isRolledBack) {
@ -163,7 +164,7 @@ export class Pushy {
let resp;
try {
resp = await fetch(this.getCheckUrl(), fetchPayload);
} catch (e) {
} catch (e: any) {
this.report({
type: 'errorChecking',
message: 'Can not connect to update server. Trying backup endpoints.',
@ -172,7 +173,7 @@ export class Pushy {
if (backupEndpoints) {
try {
resp = await Promise.race(
backupEndpoints.map((endpoint) =>
backupEndpoints.map(endpoint =>
fetch(this.getCheckUrl(endpoint), fetchPayload),
),
);
@ -214,7 +215,7 @@ export class Pushy {
new Set([...(server.backups || []), ...remoteEndpoints]),
);
}
} catch (e) {
} catch (e: any) {
log('failed to fetch endpoints from: ', server.queryUrl);
}
}
@ -254,7 +255,7 @@ export class Pushy {
if (onDownloadProgress) {
this.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
'RCTPushyDownloadProgress',
(progressData) => {
progressData => {
if (progressData.hash === hash) {
onDownloadProgress(progressData);
}
@ -273,7 +274,7 @@ export class Pushy {
originHash: currentVersion,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
log(`diff error: ${e.message}, try pdiff`);
}
}
@ -286,7 +287,7 @@ export class Pushy {
hash,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
log(`pdiff error: ${e.message}, try full patch`);
}
}
@ -299,7 +300,7 @@ export class Pushy {
hash,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
log(`full patch error: ${e.message}`);
}
}
@ -338,7 +339,7 @@ export class Pushy {
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return this.report({ type: 'rejectStoragePermission' });
}
} catch (err) {
} catch (e: any) {
return this.report({ type: 'errorStoragePermission' });
}
}

View File

@ -4,7 +4,9 @@ const {
version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const isTurboModuleEnabled =
// @ts-expect-error
global.__turboModuleProxy != null;
export const PushyModule = isTurboModuleEnabled
? require('./turboModuleSpec').default

View File

@ -86,9 +86,9 @@ export const PushyProvider = ({
},
},
]);
} catch (err) {
setLastError(err);
showAlert('更新失败', err.message);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
}
}, [client, showAlert, updateInfo]);
@ -105,9 +105,9 @@ export const PushyProvider = ({
let info: CheckResult;
try {
info = await client.checkUpdate();
} catch (err) {
setLastError(err);
showAlert('更新检查失败', err.message);
} catch (e: any) {
setLastError(e);
showAlert('更新检查失败', e.message);
return;
}
setUpdateInfo(info);
@ -159,7 +159,7 @@ export const PushyProvider = ({
if (strategy === 'both' || strategy === 'onAppResume') {
stateListener.current = AppState.addEventListener(
'change',
(nextAppState) => {
nextAppState => {
if (nextAppState === 'active') {
checkUpdate();
}
@ -198,8 +198,7 @@ export const PushyProvider = ({
progress,
downloadAndInstallApk,
getCurrentVersionInfo,
}}
>
}}>
{children}
</PushyContext.Provider>
);

View File

@ -12,9 +12,8 @@ const ping = async (url: string) =>
Promise.race([
fetch(url, {
method: 'HEAD',
redirect: 'follow',
}).then(({ status }) => status === 200),
new Promise<false>((r) => setTimeout(() => r(false), 2000)),
new Promise<false>(r => setTimeout(() => r(false), 2000)),
]);
const canUseGoogle = ping('https://www.google.com');
@ -23,7 +22,7 @@ export const testUrls = async (urls?: string[]) => {
if (!urls?.length || (await canUseGoogle)) {
return null;
}
return Promise.race(urls.map((url) => ping(url).then(() => url))).catch(
return Promise.race(urls.map(url => ping(url).then(() => url))).catch(
() => null,
);
};

4
tsconfig.json Normal file
View File

@ -0,0 +1,4 @@
{
"extends": "@react-native/typescript-config/tsconfig.json",
"include": ["src/**/*"]
}

924
yarn.lock

File diff suppressed because it is too large Load Diff