mts-migrator is a javascript-to-typescript migration engine that converts CommonJS modules to ESM, infers types from AST analysis, extracts JSDoc annotations, and refines types with the TypeScript compiler using ts-morph. Current stable version is 2.1.11, released under AGPL-3.0. It can be used via `pnpm dlx` or `npx` without installation. Key differentiators: it handles module system conversion (require→import, module.exports→export), deduplicates imports, strips .js/.jsx from relative imports, infers types from literals, constructors, known APIs, arrays, binary ops, and JSDoc, and optionally runs eslint --fix. It backs up original files, supports dry runs, error recovery, migration reports, and skips config files. Does not handle Flow types or fix logic bugs.
npm install mts-migratorNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of the migrateCode function to convert CommonJS to ESM with type inference.
Check result.errors for migration warnings or issues.
Install typescript as a devDependency: pnpm add -D typescript
Use 'pnpm mts' or 'npx mts-migrator' but note that the binary name is 'mts'.
To restore, copy files from .mts-backups or similar (check documentation for exact backup folder name).
Use import syntax or switch to ESM in your project (add 'type': 'module' to package.json).
Use dynamic import: const { migrateCode } = await import('mts-migrator'); or use ESM import syntax.Install it: pnpm add mts-migrator or npm install mts-migrator
Add explicit type annotations where inference fails.