Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "map" and "paths" config #6

Open
millermedeiros opened this issue Nov 21, 2012 · 8 comments
Open

support "map" and "paths" config #6

millermedeiros opened this issue Nov 21, 2012 · 8 comments
Labels

Comments

@millermedeiros
Copy link
Owner

would need to translate the dependency names

nodefy.config({
  paths : {
    "utils" : "amd-utils"
  },
  map : {
    "*" : {
      "lib/foo" : "foo"
    },
    "dolor/amet" : {
       "dolor/sit" : "sit-amet"
    }
  }
});


// INPUT: dolor/amet.js ===
define(['lib/foo', './sit', 'utils/math/clamp'], function(foo, sit, clamp){
    return foo.bar(sit, clamp);
});

// OUTPUT: dolor/amet.js ===
var foo = require('foo');
var sit = require('sit-amet');
var clamp = require('amd-utils/math/clamp');
module.exports = foo.bar(sit, clamp);

Reference:

@millermedeiros
Copy link
Owner Author

try to reuse amd-resolve if possible.

@jaridmargolin
Copy link

Any plans to implement this feature? or am I better off looking at a tool like uRequire?

@millermedeiros
Copy link
Owner Author

I have no plans for now (it is working for my own needs, and I don't have that much free time), but contributions are highly appreciated!!

@jaridmargolin
Copy link

No promises but I will look into it.

@jaridmargolin
Copy link

I believe paths would be very simple to implement.

I'm trying to wrap my head around map and how amd-resolve would/could be used to assist. If you have any thoughts/ideas I would be happy to do the grunt work required to implement.

If I am unable to fully form my thoughts on implementing map, would you still be open to a PR for a simple implementation to resolve paths?

@millermedeiros
Copy link
Owner Author

sure! we can do as incremental commits/PRs!

amd-resolve does the map/paths magic, you pass the ID + configs and it should return the absolute path. I did not try it out tho..

@jaridmargolin
Copy link

I guess that is the issue I am having difficulty wrapping my head around.

Currently as I understand it, we will be moving in the opposite direction. We will have the absolute paths and we will need to create the ID.

I'll start with paths, maybe my brain just needs some time to digest :)

@jaridmargolin
Copy link

CLI

Couple of questions before I implement. How/will this be integrated with the CLI? Only two options I can think of are:

  1. nodefy.json configuration file.
  2. or to just not offer support via CL..

Standalone Lib

Curious of the benefits or adding a config method rather than passing and options object to the parse, convert, & batchConvert methods..

var nodefy = require('nodefy');

// nodefy.parse(string)
// returns node.js style module
var cjsModule = nodefy.parse(jsString, {
  paths : { "utils" : "amd-utils" }
});

// nodefy.convert(inputPath [, outputPath], callback)
// if outputPath is omitted it won't write the result
nodefy.convert('foo.js', {
  paths : { "utils" : "amd-utils" }
}, function(err, result){
    console.log(result);
});

// nodefy.batchConvert(glob [, outputFolder], callback)
// if outputFolder is omitted it won't write the result
nodefy.batchConvert('src/**.js', {
  outputDir: ''cjs",
  paths : { "utils" : "amd-utils" }
}, function(err, results){
    // results is an array of {sourcePath, outputPath, result}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants