amd-codemod

v1.0.0
Converts amd modules to es6 modules

A codemod for jscodeshift that will convert amd modules to es6 ones.

Usage

  1. npm install -g jscodeshift
  2. npm install amd-codemod
  3. jscodeshift -t node_modules/amd-codemod [files]

Example Input -> Output

Module Imports

 // input
define([
    "some/module",
    "some/other/module"
], (
    SomeModule,
    SomeOtherModule
) => {
    
});

// output
import SomeModule from "some/module";
import SomeOtherModule from "some/other/module";

Default Return

// input
define([], () => {
    return 'some-value';
});

// output
export default 'some-value';

exports

// Input
define(['exports'], (
    exports
) => {
    exports.someProp = "some-value";
    exports.anotherProp = "another-value";
});

// Output
export const someProp = "some-value";
export const anotherProp = "some-value";
export default {someProp, anotherProp};

Inline requires

// Input 
const myModule = require("some/module");

// Output
import myModule from "some/module";

Async requires

In the case of webpack you can use require.ensure to load code on demand, with webpack 2 you can do this via System.import.

// Input
require.ensure([], () => {
     const myModule = require("some/module");
});

// Output
System.import("some/module").then((someModule) => {
   const myModule = someModule;
});
npm i amd-codemod

Metadata

  • ISC
  • Whatever
  • Scott Harwood
  • released 4/21/2017

Downloads

Maintainers