Skip to content

Add tsdown for cjs and esm builds - #421

Merged
abhithesys merged 16 commits into
mainfrom
abhishek/cjs-builds
Apr 8, 2026
Merged

Add tsdown for cjs and esm builds#421
abhithesys merged 16 commits into
mainfrom
abhishek/cjs-builds

Conversation

@abhithesys

@abhithesys abhithesys commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

What

Migrate all publishable packages to dual ESM/CJS builds using tsdown, eliminating the need for transpilePackages in Next.js and build.transpile in Nuxt. This fixes the friction reported in #360 where consumers had to manually configure their bundlers to use OpenUI packages.

fixes point 3 in #360.
fixes: #436

Changes

Build system

  • Migrated lang-core, react-lang, react-headless, and react-email builds from tsc to tsdown with dual ESM (.mjs) + CJS (.cjs) output and bundled type declarations (.d.mts, .d.cts)
  • Added CJS and ESM bundles for react-ui (via tsdown) for the . and ./genui-lib entry points, alongside the existing tsc-based ESM build for per-component sub-paths
  • tsdown generates bundled .d.mts/.d.cts declarations (no bare relative imports), making types resolve correctly in all TypeScript moduleResolution modes

Package exports

  • Updated exports maps across all packages with proper import/require conditional exports, each pointing to the correct .mjs/.cjs JS and .d.mts/.d.cts type files
  • Added exports field and "type": "module" to react-headless (previously had no exports map)
  • Updated top-level main, module, and types fields to reference the correct tsdown-generated artifacts
  • Removed ./tailwind export from react-ui (unused)
  • Moved zod from dependencies to peerDependencies across all packages that use it

Publish guards

  • Added check:publint and check:attw scripts to all packages
  • Added prepublishOnly to all packages running check:publint && check:attw before every publish, preventing accidental publishing of a broken build
  • Added lang-core to the GitHub Actions publish workflow (was missing)

Quality fixes

  • Fixed Theme re-export in react-ui/src/index.ts to use type modifier, resolving a rolldown MISSING_EXPORT build warning
  • Removed redundant shareThread.scss import from ShareThreadModal.tsx (already forwarded via openUIChat.scss)
  • Removed transpilePackages from all Next.js example and docs configs

Versions

All packages receive a minor version bump:

Package Old New
@openuidev/react-ui 0.10.2 0.11.0
@openuidev/lang-core 0.1.2 0.2.0
@openuidev/react-lang 0.1.5 0.2.0
@openuidev/react-headless 0.7.11 0.8.0
@openuidev/react-email 0.1.3 0.2.0

Test Plan

  • Built all packages with pnpm build and confirmed dual-format output files exist (.mjs, .cjs, .d.mts, .d.cts)
  • Ran pnpm check:publint — no errors on all packages (cosmetic repository URL suggestion only on react-ui)
  • Ran pnpm check:attw — all green (node10, node16 CJS, node16 ESM, bundler) on all packages
  • TypeScript consumer type-check: imported Button, Theme, and openuiLibrary from the built .d.mts declarations with strict mode — no errors
  • CJS runtime: require() on lang-core, react-headless, and react-ui/Button — exports load correctly
  • Visual integration test: created a Vite React app inside the monorepo referencing all packages via workspace:^, confirmed Button, Callout, ThemeProvider, and openuiLibrary render correctly in the browser and pnpm build succeeds
  • Verified Next.js examples (openui-chat, shadcn-chat, vercel-ai-chat) build successfully without transpilePackages

  - Fix module/types root fields and export paths to reference tsdown's
    .mjs/.d.mts outputs instead of tsc's .js/.d.ts (which were bare
    re-exports, not the bundled artifacts)
  - Remove manual build:dcts copy step; tsdown now generates .d.cts for
    main and genui-lib directly via per-format outDir configs
  - Add ESM build configs for main index and genui-lib so tsdown produces
    .mjs + .d.mts alongside the existing CJS outputs
  - Add check:attw and prepublishOnly to react-ui; add prepublishOnly to
    lang-core, react-lang, react-email, react-headless so publint/attw
    run before every publish
  - Fix Theme re-export in src/index.ts to use inline `type` modifier,
    resolving rolldown MISSING_EXPORT warning
@abhithesys
abhithesys marked this pull request as ready for review April 8, 2026 21:30
@abhithesys
abhithesys merged commit 98836ec into main Apr 8, 2026
1 check passed
@abhithesys
abhithesys deleted the abhishek/cjs-builds branch April 8, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move zod to peerDependencies

2 participants