Replace build tooling with tsdown for dual CJS/ESM output - #82
Open
ikrbasak wants to merge 1 commit into
Open
Conversation
Adds tsdown bundler config with proper CJS/ESM dual packaging, TypeScript declarations, inline sourcemaps, and minification. Updates package.json exports map and test imports accordingly.
ikrbasak
marked this pull request as ready for review
March 27, 2026 03:47
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The current build pipeline uses
tscdirectly, which has several issues:1. No ESM output
tscemits only CommonJS. Modern bundlers (webpack, rollup, esbuild, vite) and Node.jswith
"type": "module"can't tree-shake or properly consume the package without an ESMbuild. There is no
exportsfield ormodulefield, so bundlers fall back to the CJSbundle and lose the ability to do dead-code elimination.
2. Broken type declarations
package.jsonhad"typings": "index.d.ts"pointing to a root-level file that doesn'texist in the published package — the actual declarations were emitted to
dist/.TypeScript consumers would get no types unless they happened to find them via other means.
3. Tests import internal build artifacts
test/index.jsimportedvalidateUUIDdirectly from../dist/validate, coupling teststo the internal module structure of the build output. This breaks whenever the bundler
changes how it splits or names output chunks.
4. No
filesfieldWithout it,
npm publishincludes source files, TypeScript sources, config files, andother noise in the published tarball.
Fix
Replaces
tscwith tsdown (built on rolldown) as thebundler:
dist/index.js) and ESM (dist/index.mjs) builds from thesame TypeScript source
dist/index.d.ts/dist/index.d.mts)exportsmap so Node.js and bundlers resolve the right formatautomatically
"module"field for bundlers that use it (webpack 4, rollup, etc.)"typings"→"types"pointing to the correct generated file indist/tsc --noEmitasprebuild) from bundling, so the build stepstays fast while type errors are still caught
filesfield to keep the published package cleanvalidateUUIDinto the test file with a regex, removing the dependency oninternal build artifact paths
Why tsdown
tsdown is a TypeScript-first bundler built on rolldown (Rust-based), designed specifically
for library publishing. It handles the CJS/ESM dual-build, declaration generation, and
exportsfield wiring with minimal config compared to alternatives like tsup or ahand-rolled rollup setup.
Changes at a glance
package.jsontsc→tsdown; addedexports,module,types,files; fixedtypingstsdown.config.mjstest/index.js../dist/validateimport; inlined UUID regex; guardedconstants.defaultpackage-lock.json