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 configuration but required explicit filename mapping to preserve the package contract. The smoke test confirmed that consumers would receive the same API and declarations. Artifact size increased by ~23.6% and build time improved marginally, but the primary benefit was maintaining compatibility.
Рабочий процесс
- 1. Replace tsup dependency with tsdown.
- 2. Rename tsup.config.ts to tsdown.config.mts and adjust options (entry, format, dts, clean, outDir, target, banner).
- 3. Run pnpm build – observe that output filenames differ from package.json exports.
- 4. Add outExtensions to map cjs outputs to .js and dts outputs to .d.ts, preserving original filenames.
- 5. Run the existing packed‑package smoke test to verify exports, runtime, and declarations.
- 6. Measure artifact size and build time for comparison.
Доказательства
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 added outExtensions to preserve the existing filenames
After the migration, I expanded the test to verify more of the package contract
- Дата записи: 2026-11-02T16:29:04.711Z