resolve should also pass in filepath.
jamespedid opened this issue · 6 comments
It might be useful to also provide the filepath in the callback. In particular, my use case is to recursively loop through folders and build nested objects based on directory structure; passing in the path would help with this.
Makes sense 👍 Given the full path /foo/bar/baz.txt
, which part are you primarily looking for? (1) that entire thing, (2) just /foo/bar/
or (3) just baz.txt
?
I think our use-case needed the relative path to where we were using require-all; we were splitting the folder contents over path.sep, and then adding them to a return object based on their folder path. Example: foo/bar/baz.js would be set to modules.foo.bar.baz (e.g. modules.foo.bar.baz-> require('foo/bar/baz')). I think this would be most efficient because we can recover the absolute path based on our knowledge of the require-all path.
👍 Same as map
would make sense.
In map
I also need to know the whole content, name is in fact defined inside, but it's not really this important.
+1
This was a drawback when I wanted to use require-all to require a folder of helpers in hapi
s onPreResponse
hook, since the context passed to each helper should include the name of the helper.
I was also looking for this feature. Let me see what I can do.
HI @jamespedid your example of what you want to do is already what this module does out-of-the-box; you don't need any additional information in resolve
to achieve this; the returned object from requireAll()
is in the format you described already.