diff --git a/.gitignore b/.gitignore index 1a51769..2b07fdf 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,6 @@ next-env.d.ts .next .env public/*.js -bun.lockb \ No newline at end of file +bun.lockb +react.d.ts +server.d.ts diff --git a/package.json b/package.json index 6ac197c..23ef7dd 100644 --- a/package.json +++ b/package.json @@ -36,15 +36,19 @@ "module": "es/index.js", "types": "es/index.d.ts", "files": [ - "es" + "es", + "server.d.ts", + "react.d.ts" ], "scripts": { - "build": "father build", + "build": "father build && npm run build:entry", + "build:entry": "tsx scripts/build-entries.ts", "ci": "npm run lint && npm run type-check", + "clean": "rm react.d.ts server.d.ts", "dev": "father dev", "docs:build": "npm run setup && npm run build && dumi build", "docs:build-analyze": "ANALYZE=1 dumi build", - "docs:dev": "npm run setup && dumi dev", + "docs:dev": "npm run clean && npm run setup && dumi dev", "doctor": "father doctor", "lint": "eslint \"{src,api,lib}/**/*.{js,jsx,ts,tsx}\" --fix", "lint:md": "remark . --quiet --frail --output", @@ -115,6 +119,7 @@ "remark": "^14", "remark-cli": "^11", "semantic-release": "^21", + "tsx": "^4.1.2", "typescript": "^5", "vercel": "^28" }, diff --git a/scripts/build-entries.ts b/scripts/build-entries.ts new file mode 100644 index 0000000..f4d9bb5 --- /dev/null +++ b/scripts/build-entries.ts @@ -0,0 +1,17 @@ +import { writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// 获取当前模块文件的路径 +const __filename = fileURLToPath(import.meta.url); + +// 获取当前模块文件的目录路径 +const __dirname = path.dirname(__filename); + +const dir = path.join(__dirname, '..'); + +const entries = ['react', 'server']; + +entries.forEach((name) => { + writeFileSync(path.join(dir, `${name}.d.ts`), `export * from './es/${name}';`); +}); diff --git a/tsconfig.entry.json b/tsconfig.entry.json new file mode 100644 index 0000000..dc1be5f --- /dev/null +++ b/tsconfig.entry.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "declaration": true, + "downlevelIteration": true, + "esModuleInterop": true, + "jsx": "react-jsx", + "lib": ["dom", "dom.iterable", "esnext"], + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "strict": true, + "emitDeclarationOnly": true + }, + "include": ["react.ts", "server.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index 2eff07c..ffabd71 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,8 @@ "jsx": "react-jsx", "lib": ["dom", "dom.iterable", "esnext"], "resolveJsonModule": true, + "module": "ESNext", + "moduleResolution": "node", "skipLibCheck": true, "strict": true, "paths": { @@ -16,5 +18,6 @@ "@lobehub/tts/*": ["src/*"] } }, + "exclude": ["react.d.ts", "server.d.ts"], "include": ["src", "docs", "lib", ".dumirc.ts", "api", "**/*.ts", "**/*.d.ts", "**/*.tsx"] }