esperantojs / esperanto

DEPRECATED: An easier way to convert ES6 modules to AMD and CommonJS
http://esperantojs.org
234 stars 21 forks source link

Convert relative paths to absolute with one-to-one conversions #58

Closed Rich-Harris closed 9 years ago

Rich-Harris commented 9 years ago

e.g.

// foo/a.js
import b from './b';

// foo/b.js
import c from '../bar/c';

// var/c.js
export var c = 'copacetic';

Right now this transpiles to AMD like this:

// foo/a.js
define(['./b'], function (b) {...});

// foo/b.js
define(['../bar/c'], function (c) {...});

// bar/c.js
define(function () {...});

Where named modules are used, it would be helpful to do this instead:

// foo/a.js
define('foo/a', ['foo/b'], function (b) {...});

// foo/b.js
define('foo/b', ['bar/c'], function (c) {...});

// bar/c.js
define('bar/c', ['exports'], function (exports) {...});

Ref https://github.com/ef4/broccoli-es6modules/pull/4#issuecomment-69924193

Rich-Harris commented 9 years ago

@stefanpenner any feedback on #69 before I merge it? It converts relative paths to absolute for both AMD and UMD (CJS require statements are left alone):

esperanto.toAmd( source, {
  amdName: 'my/module/id',
  absolutePaths: true
});

Passing absolutePaths: true without an amdName is an error.

See e.g. https://github.com/esperantojs/esperanto/blob/absolute-paths/test/strictMode/output/umd/absolutePaths.js for example output

Rich-Harris commented 9 years ago

Released 0.6.5 with this feature