motia icon indicating copy to clipboard operation
motia copied to clipboard

feat: migrate build system to ESM with tsdown

Open andersonleal opened this issue 1 month ago • 4 comments

Summary

This PR introduces a comprehensive migration of the Motia monorepo build system from CommonJS to native ES Modules (ESM), replacing the previous build tooling (tsc/Vite) with tsdown across all packages. This modernization improves build performance, simplifies configuration, and ensures better compatibility with the modern JavaScript ecosystem.

Key Changes

  • ESM-first architecture: All packages now use "type": "module" and output .mjs files
  • tsdown adoption: Replaced tsc/Vite build configurations with tsdown for consistent, fast builds
  • Updated TypeScript configuration: Changed module resolution to bundler and module format to ESNext
  • Dependency updates: Updated TypeScript to 5.9.3, ts-jest to 29.4.5, and other dependencies
  • Biome schema update: Updated to version 2.3.5

Related Issues

Type of Change

  • [ ] Bug fix
  • [x] New feature
  • [ ] Breaking change
  • [x] Refactor
  • [ ] Other (please describe):

Packages Affected

Core Packages

  • @motiadev/core - Migrated to ESM with tsdown
  • @motiadev/snap - Migrated to ESM with tsdown, updated CLI entry point

Adapter Packages

  • @motiadev/adapter-rabbitmq-events - Added tsdown config
  • @motiadev/adapter-redis-cron - Added tsdown config
  • @motiadev/adapter-redis-state - Added tsdown config
  • @motiadev/adapter-redis-streams - Added tsdown config

Stream Client Packages

  • @motiadev/stream-client - Migrated to ESM with tsdown
  • @motiadev/stream-client-browser - Added tsdown config
  • @motiadev/stream-client-node - Migrated to ESM, removed custom build script
  • @motiadev/stream-client-react - Added tsdown config

UI Packages

  • @motiadev/ui - Replaced Vite with tsdown
  • @motiadev/workbench - Migrated to tsdown, updated post-build script

Plugins

  • plugin-endpoint - Replaced Vite with tsdown
  • plugin-example - Replaced Vite with tsdown
  • plugin-logs - Replaced Vite with tsdown
  • plugin-observability - Replaced Vite with tsdown
  • plugin-states - Replaced Vite with tsdown

Changes Overview

Build System Changes

Before After
tsc for TypeScript compilation tsdown for bundling
Vite for plugin builds tsdown for all builds
CommonJS (require) ESM (import)
.js output files .mjs output files
dist/cjs/ and dist/esm/ dist/ (ESM only)

Package.json Export Changes

// Before
{
  "main": "dist/cjs/index.js",
  "module": "dist/esm/index.js",
  "types": "dist/types/index.d.ts"
}

// After
{
  "type": "module",
  "main": "dist/index.mjs",
  "module": "dist/index.mjs",
  "types": "dist/index.d.mts"
}

Test Configuration

  • Jest now runs with NODE_OPTIONS='--experimental-vm-modules' for ESM support
  • Migrated jest.config.js to jest.config.cjs where needed

Checklist

  • [x] I have read the CONTRIBUTING.md
  • [x] My code follows the code style of this project
  • [x] I have added tests where applicable
  • [x] I have tested my changes locally
  • [ ] I have linked relevant issues
  • [ ] I have added screenshots for UI changes (if applicable)

Testing Performed

  • [ ] All packages build successfully with pnpm build
  • [ ] Unit tests pass with ESM configuration
  • [ ] Playground runs correctly with updated packages
  • [ ] Workbench starts and functions properly
  • [ ] CLI commands work as expected

Migration Notes

For Contributors

  • Use import syntax instead of require
  • File extensions may be needed in imports for certain edge cases
  • Jest tests now require --experimental-vm-modules flag

For Users

  • No breaking changes in public API
  • Import paths remain the same
  • TypeScript users get improved module resolution

Additional Context

This migration prepares Motia for better tree-shaking, faster builds, and improved compatibility with modern tooling. The tsdown bundler was chosen for its simplicity, speed, and excellent TypeScript support.

Files Added

  • tsdown.config.ts in each package (17 new configs)
  • jest.config.cjs for packages needing CommonJS Jest config

Files Removed

  • vite.config.ts from plugins and UI packages
  • scripts/build.sh from several packages
  • tsconfig.build.json and tsconfig.node.json where redundant
  • Various .d.ts declaration files that are now auto-generated

andersonleal avatar Nov 26 '25 13:11 andersonleal

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
motia-docs Ready Ready Preview Comment Dec 2, 2025 6:52pm
motia-ui Ready Ready Preview Comment Dec 2, 2025 6:52pm

vercel[bot] avatar Nov 26 '25 13:11 vercel[bot]

⚠️ This PR is quite large (>1000 lines). Consider splitting it into smaller PRs for easier review.

github-actions[bot] avatar Nov 26 '25 13:11 github-actions[bot]

Dependency Review

The following issues were found:

  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 18 package(s) with unknown licenses.
  • ⚠️ 8 packages with OpenSSF Scorecard issues.

View full job summary

github-actions[bot] avatar Nov 26 '25 13:11 github-actions[bot]

E2E Test Results ✅

All tests have completed. Tests passed.

Matrix: 2 OS (Ubuntu, macOS) × 2 Templates (TypeScript, Python) = 4 jobs

View detailed test results


This comment is automatically posted by the PR E2E Results workflow.

github-actions[bot] avatar Nov 26 '25 13:11 github-actions[bot]