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; const { type, asError, inputData } = data;
if (!Object.hasOwnProperty.call(SAMPLE_DATA, type)) { 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]; const outputData = SAMPLE_DATA[type];
try { try {
assert.deepEqual(outputData, inputData); assert.deepEqual(outputData, inputData);
} catch (e) { } catch (e: any) {
console.error(e); console.error(e);
throw new functions.https.HttpsError( throw new functions.https.HttpsError(
'invalid-argument', 'invalid-argument',

View File

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

View File

@ -190,7 +190,7 @@ export default function TestConsole({visible}) {
} }
setAlertVisible(true); setAlertVisible(true);
setAlertMsg('done'); setAlertMsg('done');
} catch (e) { } catch (e: any) {
setAlertVisible(true); setAlertVisible(true);
setAlertMsg(e.message); 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", "description": "react-native hot update",
"main": "src/index.ts", "main": "src/index.ts",
"scripts": { "scripts": {
"prepublish": "yarn submodule", "prepack": "yarn submodule && yarn lint",
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
"submodule": "git submodule update --init --recursive", "submodule": "git submodule update --init --recursive",
"test": "echo \"Error: no test specified\" && exit 1", "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", "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": { "devDependencies": {
"@babel/core": "^7.24.0",
"@react-native/babel-preset": "^0.73.21",
"@react-native/eslint-config": "^0.73.2", "@react-native/eslint-config": "^0.73.2",
"@react-native/typescript-config": "^0.74.0",
"@types/fs-extra": "^9.0.13", "@types/fs-extra": "^9.0.13",
"@types/jest": "^29.2.1", "@types/jest": "^29.2.1",
"@types/node": "^20.8.9", "@types/node": "^20.8.9",
"@types/react": "^18.2.46", "@types/react": "^18.2.46",
"detox": "^20.5.0", "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", "firebase-tools": "^11.24.1",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"jest": "^29.2.1",
"pod-install": "^0.1.37", "pod-install": "^0.1.37",
"prettier": "^2", "prettier": "^2",
"react": "18.2.0", "react": "18.2.0",

View File

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

View File

@ -4,7 +4,9 @@ const {
version: v, version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion'); } = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`; 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 export const PushyModule = isTurboModuleEnabled
? require('./turboModuleSpec').default ? require('./turboModuleSpec').default

View File

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

View File

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