From b147e57c1c7ea1884be471799d292ec55c97d379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 15 Nov 2025 14:00:27 +0800 Subject: [PATCH] Refactor TypeScript configs to use shared base Introduced tsconfig.base.json for shared TypeScript configuration and updated all package tsconfig.json files to extend from it, reducing duplication and improving maintainability. Also updated typecheck script in package.json and fixed import in prebuild-loader.ts. --- package.json | 2 +- packages/napcat-core/tsconfig.json | 44 +------------------- packages/napcat-develop/tsconfig.json | 41 +------------------ packages/napcat-framework/tsconfig.json | 44 +------------------- packages/napcat-image-size/tsconfig.json | 45 +-------------------- packages/napcat-onebot/tsconfig.json | 44 +------------------- packages/napcat-plugin/tsconfig.json | 40 +----------------- packages/napcat-pty/prebuild-loader.ts | 2 +- packages/napcat-qrcode/tsconfig.json | 40 +----------------- packages/napcat-shell/tsconfig.json | 44 +------------------- packages/napcat-universal/tsconfig.json | 40 +----------------- packages/napcat-vite/tsconfig.json | 38 +---------------- packages/napcat-webui-backend/tsconfig.json | 44 +------------------- tsconfig.base.json | 40 ++++++++++++++++++ 14 files changed, 53 insertions(+), 455 deletions(-) create mode 100644 tsconfig.base.json diff --git a/package.json b/package.json index eb3abff7..cc34876c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:framework": "pnpm --filter napcat-framework run build || exit 1", "build:webui": "pnpm --filter napcat-webui-frontend run build || exit 1", "dev:shell": "pnpm --filter napcat-develop run dev || exit 1", - "typecheck": "pnpm -w -r --filter napcat-shell --filter napcat-framework --filter napcat-webui-backend --filter napcat-onebot --filter napcat-core --filter napcat-webui-frontend run typecheck" + "typecheck": "pnpm -r --if-present run typecheck" }, "devDependencies": { "@rollup/plugin-node-resolve": "^16.0.3", diff --git a/packages/napcat-core/tsconfig.json b/packages/napcat-core/tsconfig.json index 070ded28..48d3a03b 100644 --- a/packages/napcat-core/tsconfig.json +++ b/packages/napcat-core/tsconfig.json @@ -1,47 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "@/*": [ - "../*" - ] - }, - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-develop/tsconfig.json b/packages/napcat-develop/tsconfig.json index e8b7d5c2..c498219a 100644 --- a/packages/napcat-develop/tsconfig.json +++ b/packages/napcat-develop/tsconfig.json @@ -1,44 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "rootDir": "./", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": "./", - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "allowJs": true - }, + "extends": "../../tsconfig.base.json", "include": [ "**/*.cjs" ], diff --git a/packages/napcat-framework/tsconfig.json b/packages/napcat-framework/tsconfig.json index 070ded28..48d3a03b 100644 --- a/packages/napcat-framework/tsconfig.json +++ b/packages/napcat-framework/tsconfig.json @@ -1,47 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "@/*": [ - "../*" - ] - }, - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-image-size/tsconfig.json b/packages/napcat-image-size/tsconfig.json index 7244a40b..473a385a 100644 --- a/packages/napcat-image-size/tsconfig.json +++ b/packages/napcat-image-size/tsconfig.json @@ -1,48 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "rootDir": "src", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": true, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "@/*": [ - "../*" - ] - }, - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "src/**/*.ts" ], diff --git a/packages/napcat-onebot/tsconfig.json b/packages/napcat-onebot/tsconfig.json index 070ded28..48d3a03b 100644 --- a/packages/napcat-onebot/tsconfig.json +++ b/packages/napcat-onebot/tsconfig.json @@ -1,47 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "@/*": [ - "../*" - ] - }, - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-plugin/tsconfig.json b/packages/napcat-plugin/tsconfig.json index d1744ff4..48d3a03b 100644 --- a/packages/napcat-plugin/tsconfig.json +++ b/packages/napcat-plugin/tsconfig.json @@ -1,43 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "rootDir": ".", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-pty/prebuild-loader.ts b/packages/napcat-pty/prebuild-loader.ts index 552c7504..20241280 100644 --- a/packages/napcat-pty/prebuild-loader.ts +++ b/packages/napcat-pty/prebuild-loader.ts @@ -1,4 +1,4 @@ -import { require_dlopen } from '.'; +import { require_dlopen } from 'index'; export function pty_loader () { let pty: any; try { diff --git a/packages/napcat-qrcode/tsconfig.json b/packages/napcat-qrcode/tsconfig.json index d1744ff4..48d3a03b 100644 --- a/packages/napcat-qrcode/tsconfig.json +++ b/packages/napcat-qrcode/tsconfig.json @@ -1,43 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "rootDir": ".", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-shell/tsconfig.json b/packages/napcat-shell/tsconfig.json index 070ded28..48d3a03b 100644 --- a/packages/napcat-shell/tsconfig.json +++ b/packages/napcat-shell/tsconfig.json @@ -1,47 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "@/*": [ - "../*" - ] - }, - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-universal/tsconfig.json b/packages/napcat-universal/tsconfig.json index d1744ff4..48d3a03b 100644 --- a/packages/napcat-universal/tsconfig.json +++ b/packages/napcat-universal/tsconfig.json @@ -1,43 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "rootDir": ".", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "**/*.ts" diff --git a/packages/napcat-vite/tsconfig.json b/packages/napcat-vite/tsconfig.json index 18530ede..fce4a04c 100644 --- a/packages/napcat-vite/tsconfig.json +++ b/packages/napcat-vite/tsconfig.json @@ -1,42 +1,6 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "rootDir": "./", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": "./", - "skipLibCheck": true, - "skipDefaultLibCheck": true, "allowJs": true }, "include": [ diff --git a/packages/napcat-webui-backend/tsconfig.json b/packages/napcat-webui-backend/tsconfig.json index 13e14b6b..8df94291 100644 --- a/packages/napcat-webui-backend/tsconfig.json +++ b/packages/napcat-webui-backend/tsconfig.json @@ -1,47 +1,5 @@ { - "compilerOptions": { - "target": "ES2021", - "module": "ESNext", - "moduleResolution": "Node", - "lib": [ - "ES2021" - ], - "typeRoots": [ - "./node_modules/@types" - ], - "esModuleInterop": true, - "outDir": "dist", - "noEmit": false, - "sourceMap": true, - "strict": true, - "noImplicitAny": true, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "alwaysStrict": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "useUnknownInCatchVariables": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "useDefineForClassFields": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "@/*": [ - "../*" - ] - }, - "skipLibCheck": true, - "skipDefaultLibCheck": true - }, + "extends": "../../tsconfig.base.json", "include": [ "*.ts", "src/**/*.ts", diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..d860242a --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,40 @@ +{ + "compilerOptions": { + "target": "ES2021", + "module": "ESNext", + "moduleResolution": "Node", + "lib": [ + "ES2021" + ], + "esModuleInterop": true, + "outDir": "dist", + "noEmit": false, + "sourceMap": true, + "strict": true, + "noImplicitAny": false, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "alwaysStrict": true, + "noImplicitThis": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": false, + "forceConsistentCasingInFileNames": true, + "useUnknownInCatchVariables": true, + "noImplicitOverride": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "useDefineForClassFields": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "baseUrl": ".", + "paths": { + "@/*": ["packages/*"] + }, + "skipLibCheck": true, + "skipDefaultLibCheck": true + } +} \ No newline at end of file