Migrating a Real TypeScript OSS Library from tsup to tsdown
Описание и применение
Перенос библиотеки is‑kit из tsup в tsdown потребовал сохранения публичного контракта пакета, включая имена файлов и экспорты. Добавление outExtensions в конфигурацию tsdown позволило вернуть прежние имена файлов, а проверка через packed‑package smoke test убедилась в совместимости. Размер артефакта вырос на ~23,6 %, но основная выгода — сохранение совместимости пользователей.
Задача
Preserve the published package contract (file names, exports, declarations) when switching build tools from tsup to tsdown.
Результат
The migration was small in code changes but required careful handling of output filenames via outExtensions to preserve the package contract. A packed‑package smoke test confirmed compatibility. Artifact size increased by ~23.6% and build time improved marginally, but the main benefit was maintaining consumer compatibility.
Рабочий процесс
- 1. Remove tsup dependency and install tsdown.
- 2. Replace tsup.config.ts with tsdown.config.mts and map options.
- 3. Run pnpm build – build succeeds but output filenames differ.
- 4. Add outExtensions to map cjs outputs to .js and dts to .d.ts.
- 5. Run pnpm build again – filenames match original contract.
- 6. Execute packed‑package smoke test to verify exports, runtime, and declarations.
- 7. Measure artifact size and build performance 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 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
- Дата записи: 2026-10-08T16:40:51.369Z