Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
]
}
}
7 changes: 0 additions & 7 deletions tsconfig.module.json

This file was deleted.

89 changes: 89 additions & 0 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -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')) {
Comment on lines +61 to +62
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): 直接删除 dist 目录中的文件可能会导致问题,如果目录结构发生变化。

此逻辑仅删除 dist 顶层的文件,并且会遗漏子目录中的 .d.cts 文件。使用递归方法或 glob 模式来处理所有情况。

建议的实现方式:

  const distDir = path.join(file_path, 'dist')

  // 递归删除所有 .d.cts 文件
  import glob from 'glob'

  glob.sync('**/*.d.cts', { cwd: distDir, absolute: true }).forEach((file) => {
    fs.rmSync(file)
  })

  // 仅重命名顶层 .js 文件为 .mjs
  fs.readdirSync(distDir).forEach((file) => {
    if (file.endsWith('.js')) {
      const oldPath = path.join(distDir, file)
      const newPath = path.join(distDir, file.replace('.js', '.mjs'))
      fs.renameSync(oldPath, newPath)
    }
  })
  • 确保 glob 包已安装在您的项目中 (npm install glob)。
  • 如果您的项目使用 ES 模块,您可能需要将 glob 导入为 import glob from 'glob' 在文件顶部,或者如果使用 CommonJS,则使用 const glob = require('glob')
  • 如果您还想递归地将子目录中的 .js 文件重命名为 .mjs,您应该为 .js 文件应用类似的 glob 模式。
Original comment in English

suggestion (bug_risk): Directly deleting files in the dist directory may cause issues if the directory structure changes.

This logic only deletes files in the top level of dist and will miss .d.cts files in subdirectories. Use a recursive method or glob pattern to handle all cases.

Suggested implementation:

  const distDir = path.join(file_path, 'dist')

  // 递归删除所有 .d.cts 文件
  import glob from 'glob'

  glob.sync('**/*.d.cts', { cwd: distDir, absolute: true }).forEach((file) => {
    fs.rmSync(file)
  })

  // 仅重命名顶层 .js 文件为 .mjs
  fs.readdirSync(distDir).forEach((file) => {
    if (file.endsWith('.js')) {
      const oldPath = path.join(distDir, file)
      const newPath = path.join(distDir, file.replace('.js', '.mjs'))
      fs.renameSync(oldPath, newPath)
    }
  })
  • Make sure the glob package is installed in your project (npm install glob).
  • If your project uses ES modules, you may need to import glob as import glob from 'glob' at the top of the file, or use const glob = require('glob') if using CommonJS.
  • If you want to also recursively rename .js files to .mjs in subdirectories, you should apply a similar glob pattern for .js files.

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('构建导出依赖目录成功!')
}
47 changes: 0 additions & 47 deletions tsup.config.ts

This file was deleted.

47 changes: 0 additions & 47 deletions tsup.modules.ts

This file was deleted.

Loading