Giter Club home page Giter Club logo

cjs2mjsexport's Introduction

cjs2mjsExport

A tool that can transform CommonJS to ESM

CLI

tsx [pathToLibrary]/cjs2mjsExport/src/index.ts --project-files='src/**/*.{tsx,ts,js}'

API

import { migrate } from './src/index.ts';

migrate({
  projectFiles: 'src/**/*.{tsx,ts,js}',
})

Related projects

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:

5to6/5to6-codemod: A collection of codemods that allow you to transform your js code from ES5 to ES6.

azu/commonjs-to-es-module-codemod: Codemod that convert CommonJS(require/exports) to ES Modules(import/export) for JavaScript/TypeScript

TODO

  • run as cli
  • progress bar
  • handle module.exports.sum with import { sum } from './sum'; will be transformed to export const sum
  • handle module.exports.sum with import tool from './sum'; will be transformed to export const sum and import * tool from './sum';
  • handle module.exports = sum with import sum from './sum'; will be transformed to export const sum and import { sum } from './sum';
  • module.exports = { name: 'name'} need to be transformed to export const [fileName] = {
  • module.exports = {name} need to be transformed to export const name = 'name'
  • handle module.exports = {name: 'name'} with import { name } from './module';
  • handle module.exports.sum = function sum(a, b) {
  • publish package

References

Issue on typescript which can help handle this: Support find-all-references for module.exports · Issue #22205 · microsoft/TypeScript

cjs2mjsexport's People

Contributors

andriyor avatar

Stargazers

Diana Maliukh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.