Nucleus Powered Mitochondria

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

    Keywords

    none

    Install

    npm i amd-codemod

    DownloadsWeekly Downloads

    0

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar