requireDir icon indicating copy to clipboard operation
requireDir copied to clipboard

Get only an array of paths

Open jlgrall opened this issue 9 years ago • 4 comments

Add a requireDir.resolve() which would return a map of the paths instead of a map of the required paths.

It would help plugins like browserify to follow your requires, without loosing time loading unnecessary modules.

I chose the name .resolve() to stay consistent with require.resolve().

jlgrall avatar Dec 12 '14 01:12 jlgrall

Sorry for the delay here, but nice idea! Love it.

Just to be clear, the return value would be the exact same structure of map that requireDir() returns (which can be recursive, etc.), but the values would be (absolute) string paths instead of the results of require()'ing those paths?

This should be pretty easy to do. I'll see if I can get to it, but pull requests welcome too. =)

aseemk avatar Jan 29 '15 01:01 aseemk

Is this a feature you're still interested in? I'd take a PR for it if it doesn't add too much surface and is done in a generic way.

yocontra avatar Feb 07 '18 22:02 yocontra

Thx for the follow up. Yep, I am still interested. It is to allow the listing and loading of plug-in modules on-demand.

Now, I had to put my project on hold, so if I go back to it and still need that feature, I can look into writing a PR for you.

As for @aseemk's first question, yes it would return string paths instead of the result of require()'ing those paths, and yes it would allow the use of the recurse option. But you shouldn't turn the paths to absolute paths: just keep the paths as they are given and append the filenames at the end, without transforming them into absolute paths.

jlgrall avatar Feb 08 '18 11:02 jlgrall

@jlgrall Great, looking forward to a PR from you (or somebody else reading this) - it shouldn't be too hard to replace the key = require(path) with key = path to achieve this behavior.

yocontra avatar Feb 08 '18 16:02 yocontra