amd-codemod

1.0.0 • Public • Published

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;
});

Readme

Keywords

none

Package Sidebar

Install

npm i amd-codemod

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • kbielaski
  • dwalker
  • atlassian-aui
  • jvdl
  • mdejongh
  • mszczepanski
  • cdarroch
  • macku
  • dboyd
  • dmorrow
  • mstaas
  • cwhittington
  • doklovic
  • 1999-atlassian
  • amcculloch
  • wyasvoin
  • jmoynihan
  • xqiu
  • gleal-atlassian
  • mszpyra
  • bcytrowski
  • plai1
  • sraj
  • tilwin_atlassian
  • mrzymski
  • media-build-bot
  • akishore
  • timse
  • mkem114
  • tsebastian
  • sfp-release-bot
  • sharwood