A tool that can transform CommonJS to ESM
tsx [pathToLibrary]/cjs2mjsExport/src/index.ts --project-files='src/**/*.{tsx,ts,js}'
import { migrate } from './src/index.ts';
migrate({
projectFiles: 'src/**/*.{tsx,ts,js}',
})
Other projects makes changes file by file instead of fix usage of export from this file and doesn't change ESM import of CJS module
wessberg/cjstoesm: A tool that can transform CommonJS to ESM - produce a lot of changes and slow
have several issues:
- Doesn't work with newer TypeScript versions · Issue #34 · wessberg/cjstoesm because typescript have a lot of braking changes in compiler api and this package it relies on typescript package used by project
- Usage documentation is unclear · Issue #27 · wessberg/cjstoesm
- run as cli
- progress bar
- handle
module.exports.sum
withimport { sum } from './sum';
will be transformed toexport const sum
- handle
module.exports.sum
withimport tool from './sum';
will be transformed toexport const sum
andimport * tool from './sum';
- handle
module.exports = sum
withimport sum from './sum';
will be transformed toexport const sum
andimport { sum } from './sum';
-
module.exports = { name: 'name'}
need to be transformed toexport const [fileName] = {
-
module.exports = {name}
need to be transformed toexport const name = 'name'
- handle
module.exports = {name: 'name'}
withimport { name } from './module';
- handle
module.exports.sum = function sum(a, b) {
- publish package
Issue on typescript which can help handle this: Support find-all-references for module.exports · Issue #22205 · microsoft/TypeScript