This repository was archived by the owner on Nov 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')) { | ||
| 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('构建导出依赖目录成功!') | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 模式来处理所有情况。
建议的实现方式:
glob包已安装在您的项目中 (npm install 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:
globpackage is installed in your project (npm install glob).import glob from 'glob'at the top of the file, or useconst glob = require('glob')if using CommonJS..jsfiles to.mjsin subdirectories, you should apply a similar glob pattern for.jsfiles.