defunctzombie / node-required

identifies which modules your script is using
67 stars 15 forks source link

require('./bar') and require('./bar.js') generate separate dependencies #3

Closed ghost closed 11 years ago

ghost commented 11 years ago

Given this source, x.js:

var bar1 = require('./bar');
var bar2 = require('./bar.js');

and this program, req.js:

var required = require('required');
required('x.js', function (err, deps) {
    console.dir(deps);
});
$ node req.js
[ { id: './bar',
    filename: '/home/substack/projects/node-browserify/example/test/bar.js',
    deps: [] },
  { id: './bar.js',
    filename: '/home/substack/projects/node-browserify/example/test/bar.js',
    deps: [] } ]

This output is not ideal since ./bar and ./bar.js are the same file.

ghost commented 11 years ago

Update: it seems like id is just the raw string that appears in the require() statement. This might not be worth fixing since I can always just re-normalize the filename parameter.

defunctzombie commented 11 years ago

It has to appear twice so that anything that consumes the output is aware that both of those ids exist. An alternative would be to have an 'aliases' field alongside the filename. But I think that is worse since the existence of require('bar') and require('bar.js') is if in different source files will not be put under the alias (since they will be under their respective parent files).

Basically, the output of required is meant to be a direct mapping of ids required to the filenames those lead to.