diff --git a/.vscode/settings.json b/.vscode/settings.json index cf7c4e3..4dd2396 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,12 @@ "editor.formatOnSaveMode": "file", "editor.codeActionsOnSave": { "source.fixAll.eslint": "always" + }, + "files.autoSave": "afterDelay", + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + ".env": "*.env", + "tsconfig.json": "tsconfig.*.json, env.d.ts, tsup.*.ts, tsdown.*.ts", + "package.json": "package-lock.json, pnpm*, .yarnrc*, yarn*, .eslint*, eslint*, .prettier*, prettier*, .editorconfig, CHANGELOG*.md, CODE_OF_CONDUCT.md, *.gitignore, LICENSE, README.md, .release*.json, .gitattributes" } } \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index 83eb42c..8e7e96c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -13,7 +13,7 @@ const neostandard = require('neostandard') export default tseslint.config( ...neostandard(), { - ignores: ['eslint.config.js', 'tsup.config.ts', 'dist', 'test', 'docs' ,'tsup.modules', 'tsup.modules.ts'], + ignores: ['eslint.config.js', 'tsdown.config.ts', 'dist', 'test', 'docs' , 'tsup.modules.ts'], }, tseslint.configs.recommended, tseslint.configs.recommendedTypeChecked, diff --git a/package.json b/package.json index 64239a5..1f5ea15 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "README.md" ], "scripts": { - "build": "tsc --noEmit && tsup && tsup --tsconfig tsconfig.module.json --config tsup.modules.ts", + "build": "tsc --noEmit && tsdown", "build:docs": "pnpm run build:typedoc && pnpm run docs:build", "build:pages": "vitepress build docs", "build:typedoc": "typedoc --options typedoc.json", @@ -109,7 +109,7 @@ "globals": "^16.0.0", "neostandard": "^0.12.1", "tsc-alias": "^1.8.11", - "tsup": "^8.4.0", + "tsdown": "^0.12.9", "tsx": "^4.19.3", "typedoc": "^0.28.1", "typedoc-plugin-markdown": "^4.6.1", @@ -121,5 +121,14 @@ "vuepress": "2.0.0-rc.20", "vuepress-theme-plume": "1.0.0-rc.140" }, - "packageManager": "pnpm@9.13.2" + "engines": { + "node": ">=20.0.0" + }, + "pnpm": { + "onlyBuiltDependencies": [ + "esbuild", + "unrs-resolver", + "@parcel/watcher" + ] + } } \ No newline at end of file diff --git a/tsconfig.module.json b/tsconfig.module.json deleted file mode 100644 index f53b73d..0000000 --- a/tsconfig.module.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "./dist/exports", - "rootDir": "./src/exports", - } -} \ No newline at end of file diff --git a/tsdown.config.ts b/tsdown.config.ts new file mode 100644 index 0000000..f01c94d --- /dev/null +++ b/tsdown.config.ts @@ -0,0 +1,89 @@ +import { defineConfig, type Options } from 'tsdown' +import fs from 'node:fs' +import path, { dirname } from 'node:path' +import { fileURLToPath } from 'node:url' + + +export const options: Options =({ + entry: ['src/index.ts', 'src/root.ts'], // 入口文件 + format: ['cjs', 'esm'], // ESM格式 + nodeProtocol: true, // 转换node:protocol + unbundle: false, // 保持目录结构 + fixedExtension: true, // 统一扩展名 + dts: true, // 生成类型声明文件 + clean: true, // 清理dist目录 + minify: true, // 压缩生产环境代码 + target: 'node22', // 指定ECMAScript目标版本 + sourcemap: false, // 生成sourcemap + treeshake: true, // 启用树摇优化 + platform: 'node', // 指定为Node.js环境 + outputOptions: { + exports: 'named', + }, + outDir: 'dist', // 指定输出目录 + hooks(hooks) { + hooks.hook('build:done', () => { + copyFiles() + }) + }, +}) + +export const expOptions: Options = ({ + entry: ['src/exports/*.ts'], // 入口文件 + format: ['cjs', 'esm'], // ESM格式 + unbundle: false, // 保持目录结构 + nodeProtocol: true, // 转换node:protocol + fixedExtension: true, // 统一扩展名 + dts: true, // 生成类型声明文件 + clean: true, // 清理dist目录 + minify: true, // 压缩生产环境代码 + target: 'node22', // 指定ECMAScript目标版本 + sourcemap: false, // 生成sourcemap + treeshake: true, // 启用树摇优化 + platform: 'node', // 指定为Node.js环境 + outDir: 'dist/exports', // 指定输出目录 + hooks(hooks) { + hooks.hook('build:done', () => { + copyExpFiles() + }) + }, +}) + +export default [defineConfig(options), defineConfig(expOptions)] + +const copyFiles = () => { + const file_name_path = fileURLToPath(import.meta.url) + const file_path = dirname(file_name_path) + + const distDir = path.join(file_path, 'dist') + + // 删除 .d.cts 文件 + fs.readdirSync(distDir).forEach((file) => { + if (file.endsWith('.d.cts')) { + fs.rmSync(path.join(distDir, file)) + } + if (file.endsWith('.js')) { + const oldPath = path.join(distDir, file) + const newPath = path.join(distDir, file.replace('.js', '.mjs')) + fs.renameSync(oldPath, newPath) + } + }) + + console.log('构建目录成功!') +} + +const copyExpFiles = () => { + const file_name_path = fileURLToPath(import.meta.url) + const file_path = dirname(file_name_path) + + const distDir = path.join(file_path, 'dist', 'exports') + + fs.readdirSync(distDir).forEach((file) => { + // 删除 .d.cts 文件 + if (file.endsWith('.d.cts')) { + fs.rmSync(path.join(distDir, file)) + } + }) + + console.log('构建导出依赖目录成功!') +} \ No newline at end of file diff --git a/tsup.config.ts b/tsup.config.ts deleted file mode 100644 index d8ac5e9..0000000 --- a/tsup.config.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { defineConfig, type Options } from 'tsup' -import fs from 'node:fs' -import path, { dirname } from 'node:path' -import { fileURLToPath, URL } from 'node:url' - -const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8')) - -export const options: Options =({ - entry: ['src/index.ts', 'src/root.ts'], // 入口文件 - format: ['cjs', 'esm'], // ESM格式 - bundle: true, // 打包依赖 - dts: true, // 生成类型声明文件 - clean: true, // 清理dist目录 - minify: true, // 压缩生产环境代码 - target: 'node22', // 指定ECMAScript目标版本 - sourcemap: false, // 生成sourcemap - treeshake: true, // 启用树摇优化 - platform: 'node', // 指定为Node.js环境 - splitting: false, // 代码分割, 是否拆分文件 - outDir: 'dist', // 指定输出目录 - external: Object.keys(pkg.dependencies), // 外部依赖, 不打包进输出文件中 - outExtension: ({ format }) => ({ - js: format === 'esm' ? '.mjs' : '.cjs' - }), - onSuccess: async () => { - await new Promise((resolve) => setTimeout(resolve, 5000)) - copyFiles() - } -}) - -export default defineConfig(options) - -const copyFiles = () => { - const file_name_path = fileURLToPath(import.meta.url) - const file_path = dirname(file_name_path) - - const distDir = path.join(file_path, 'dist') - - // 删除 .d.cts 文件 - fs.readdirSync(distDir).forEach((file) => { - if (file.endsWith('.d.cts')) { - fs.rmSync(path.join(distDir, file)) - } - }) - - console.log('构建目录成功!') -} \ No newline at end of file diff --git a/tsup.modules.ts b/tsup.modules.ts deleted file mode 100644 index 0f3eecd..0000000 --- a/tsup.modules.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { defineConfig, type Options } from 'tsup' -import fs from 'node:fs' -import { fileURLToPath, URL } from 'node:url' -import path, { dirname } from 'node:path' - -fs.rmSync('dist/exports', { recursive: true, force: true }) -const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8')) - -export const options: Options =({ - entry: ['src/exports/*.ts'], // 入口文件 - format: ['cjs', 'esm'], // ESM格式 - bundle: true, // 打包依赖 - dts: true, // 生成类型声明文件 - clean: true, // 清理dist目录 - minify: true, // 压缩生产环境代码 - target: 'node22', // 指定ECMAScript目标版本 - sourcemap: false, // 生成sourcemap - treeshake: true, // 启用树摇优化 - platform: 'node', // 指定为Node.js环境 - splitting: false, // 代码分割, 是否拆分文件 - outDir: 'dist/exports', // 指定输出目录 - external: Object.keys(pkg.dependencies), // 外部依赖, 不打包进输出文件中 - outExtension: ({ format }) => ({ - js: format === 'esm' ? '.mjs' : '.cjs' - }), - onSuccess: async () => { - await new Promise((resolve) => setTimeout(resolve, 5000)) - copyFiles() - } -}) -export default defineConfig(options) - -const copyFiles = () => { - const file_name_path = fileURLToPath(import.meta.url) - const file_path = dirname(file_name_path) - - const distDir = path.join(file_path, 'dist', 'exports') - - fs.readdirSync(distDir).forEach((file) => { - // 删除 .d.cts 文件 - if (file.endsWith('.d.cts')) { - fs.rmSync(path.join(distDir, file)) - } - }) - - console.log('构建导出依赖目录成功!') -} \ No newline at end of file