Migrating a Real TypeScript OSS Library from tsup to tsdown
说明与用途
将 is‑kit 从 tsup 迁移到 tsdown 时,需要保持输出文件名以维持包的合同。通过 outExtensions 和打包测试,合同保持不变,但产物大小略有增加。
问题
Preserve the published package contract while switching the build tool from tsup to tsdown.
结果
The migration was straightforward in terms of code changes but required careful handling of output filenames to keep the package contract intact. A smoke test that installs the packed tarball verified that consumers still received the same API and types.
工作流
- Replace tsup dependency with tsdown
- Rename tsup.config.ts to tsdown.config.mts
- Copy most config options (entry, format, dts, clean, outDir, target, banner)
- Run pnpm build
- Observe that output filenames changed
- Add outExtensions to map cjs to .js and dts to .d.ts
- Run pnpm build again
- Run packed‑package smoke test to verify exports, types, runtime, and declaration banner
证据
The first tsdown build succeeded while silently changing files that were already part of the package's public contract.
The config migration was small. Preserving the package contract was the interesting part.
I used outExtensions: ({ format }) => ({ dts: format === 'cjs' ? '.d.ts' : '.d.mts', js: format === 'cjs' ? '.js' : '.mjs', }),
After the migration, I expanded the test to verify more of the package contract
The tsdown output retained more comments and region markers than the previous tsup output.
- 记录日期: 2026-10-15T18:41:13.881Z