Open jorenbroekema opened 2 months ago
This was planned but never got around to adding it. If someone can take it up, it should be a relatively simple change.
I've been desperately trying to get on this but I can't for the life of me find the time for it, summer's been a little crazy for me. Just FYI for transparency, it might be best if someone else pick this up😅 sorry
Hi, I'm looking to perhaps migrate from glob to fdir and one big blocker for me is that glob allows you to inject a custom "fs" implementation like so:
It would be cool if the node builtin modules could be optionally substituted, e.g.
path-unified
is an NPM package which is just anode:path
clone that works in the browser out of the box, andmemfs
would be a goodnode:fs
replacement.The path replacement is basically always a good idea because that module has no reason not to work in a browser env, the fs module is slightly harder because browser doesn't have filesystem access by default, you either need to use an in-memory replacement or an adapter which makes it interact with the browser's filesystem access API (bit more complicated). memfs allows doing both, fortunately.
You can use package entrypoints for example to internally do this in your package:
using:
so when not in a Node env, this lib would require the user to pass "fs" as an option to any fdir calls, similar to how you do it in glob, since there isn't a default fallback. You could also set a default fallback ->
memfs
instead of "empty variable", up to you.If you're at all interested in this approach to make this lib work in browser out of the box without any bundler shenanigans, I'd be happy to investigate this and open a PR