Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

expose a module.resolve method, or require.resolve(path, startPath) #3285

Closed
lfdoherty opened this issue May 18, 2012 · 2 comments
Closed

expose a module.resolve method, or require.resolve(path, startPath) #3285

lfdoherty opened this issue May 18, 2012 · 2 comments

Comments

@lfdoherty
Copy link

It's almost possible to build lookup of other resources (like browser-side javascript resources) on top of the node.js require system. The only thing missing is the ability to resolve lookups relative to a module.

Adding the following to module.js exposes that functionality cleanly:

Module.prototype.resolve = function(path) {
return Module._resolveFilename(path, this);
};

Alternatively, changing require.resolve to take a path from which to start would be an even more flexible solution.

@moll
Copy link

moll commented Apr 21, 2013

This is something I just needed myself as well, so I'm definitely for adding the resolve method to Module.prototype.require. The current work-around of using Module._resolveFilename directly with, for example, the given module.parent is obviously risky.

@isaacs
Copy link

isaacs commented Apr 21, 2013

We won't be adding any API or functionality to the module system any time soon. The algorithm is pretty simple, and easy to implement in userland modules (as browserify does).

@isaacs isaacs closed this as completed Apr 21, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants