{"id":15640160,"url":"https://github.com/azu/commonjs-to-es-module-codemod","last_synced_at":"2025-05-07T00:07:59.226Z","repository":{"id":48878005,"uuid":"289488861","full_name":"azu/commonjs-to-es-module-codemod","owner":"azu","description":"Codemod that convert CommonJS(require/exports) to ES Modules(import/export) for JavaScript/TypeScript","archived":false,"fork":false,"pushed_at":"2023-05-10T21:33:54.000Z","size":266,"stargazers_count":87,"open_issues_count":2,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T00:07:52.638Z","etag":null,"topics":["codemod","commonjs","esm","esmodules","migration","tools"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azu.png","metadata":{"funding":{"github":"azu"},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-22T13:03:26.000Z","updated_at":"2025-03-07T14:59:16.000Z","dependencies_parsed_at":"2024-06-21T13:08:53.121Z","dependency_job_id":"a613b49f-4171-4215-943d-a57d28acd4fe","html_url":"https://github.com/azu/commonjs-to-es-module-codemod","commit_stats":{"total_commits":78,"total_committers":7,"mean_commits":"11.142857142857142","dds":"0.33333333333333337","last_synced_commit":"e1001a15faac8a78135ae50175b374fba4a65303"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fcommonjs-to-es-module-codemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fcommonjs-to-es-module-codemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fcommonjs-to-es-module-codemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fcommonjs-to-es-module-codemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azu","download_url":"https://codeload.github.com/azu/commonjs-to-es-module-codemod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788524,"owners_count":21804284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codemod","commonjs","esm","esmodules","migration","tools"],"created_at":"2024-10-03T11:31:47.784Z","updated_at":"2025-05-07T00:07:59.195Z","avatar_url":"https://github.com/azu.png","language":"JavaScript","funding_links":["https://github.com/sponsors/azu"],"categories":[],"sub_categories":[],"readme":"# commonjs-to-es-module-codemod [![Actions Status: test](https://github.com/azu/commonjs-to-es-module-codemod/workflows/test/badge.svg)](https://github.com/azu/commonjs-to-es-module-codemod/actions?query=workflow%3A\"test\")\n\njscodeshift codemod that convert CommonJS(require/exports) to ES Modules(import/export) for JavaScript/TypeScript\n\n## Support Patterns\n\n### Exports\n\n- [x] named export: `module.exports.foo = foo` \u0026 `exports.foo = foo` to `export { foo }`\n- [x] named export: `module.exports.bar = foo` \u0026 `exports.bar = foo` to `export { foo as bar }`\n- [x] default export: `module.exports = foo` to `export default foo`\n- [x] ignore multiple `module.exports = x`\n\n### Imports\n\n- [x] `require(\"mod\")` to `import \"mod\"`\n- [x] `const foo = require(\"mod\")` to `import foo from \"mod\"`\n- [x] `const { foo } = require(\"mod\")` to `import { foo } from \"mod\"`\n- [x] `const foo = require(\"mod\").foo` to `import { foo } from \"mod\"`\n- [x] `const bar = require(\"mod\").foo` to `import { foo as bar } from \"mod\"`\n- [ ] `const o = { foo: require(\"foo\") } ` to `import foo from \"mod\"; const o = { foo }`\n\n## Usage\n\n`commonjs-to-es-module-codemod` is published on [npm](https://www.npmjs.com/package/commonjs-to-es-module-codemod).\n\nYou can convert `index.js` and `index.ts` to ES Modules using [jscodeshift](https://github.com/facebook/jscodeshift) and [unpkg](https://unpkg.com/).\n\n    # Install jscodeshift\n    npm install --global jscodeshift\n    # Transform using latest version\n    LATEST_VERSION=$(npm view commonjs-to-es-module-codemod version)\n    jscodeshift -t \"https://unpkg.com/commonjs-to-es-module-codemod@${LATEST_VERSION}/dist/index.js\" \"index.js\"\n    # Transform TypeScript\n    jscodeshift -t \"https://unpkg.com/commonjs-to-es-module-codemod@${LATEST_VERSION}/dist/index.js\" --extensions ts \"index.ts\"\n\nConvert `src/*.js`:\n\n    LATEST_VERSION=$(npm view commonjs-to-es-module-codemod version)\n    find src -name \"*.js\" | xargs jscodeshift -t \"https://unpkg.com/commonjs-to-es-module-codemod@${LATEST_VERSION}/dist/index.js\"\n\n## Related\n\n- [azu/eslint-cjs-to-esm: ESLint wrapper for migration from CJS to ESM.](https://github.com/azu/eslint-cjs-to-esm)\n\n## Tests\n\n    yarn test\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## License\n\nMIT © azu\n\nIt includes [BuonOmo/CommonJS-to-ES6-codemod](https://github.com/BuonOmo/CommonJS-to-ES6-codemod).\n\nMIT © Ulysse Buonomo \u003cbuonomo.ulysse@gmail.com\u003e\n\n\n## Related\n\n- [lebab/lebab: Turn your ES5 code into readable ES6. Lebab does the opposite of what Babel does.](https://github.com/lebab/lebab)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fcommonjs-to-es-module-codemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazu%2Fcommonjs-to-es-module-codemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fcommonjs-to-es-module-codemod/lists"}