It'd be great if we could pass in a virtual filesystem as an option. There are several compatible with the fs API so it shouldn't require many changes:
How it'd work:
let glob = require('glob')
let memfs = require('memfs')
let volume = memfs.Volume.fromJSON({
'/foo/bar/abc.txt': 'abc',
'/foo/bar/def.log': 'def',
'/foo/bar/xyz.txt': 'xyz',
})
glob.sync('/foo/bar/*.txt', { fs: volume }) // returns ['/foo/bar/abc.txt', '/foo/bar/xyz.txt']
This would allow usage of glob in lots more places without adding any real maintenance burden or requiring users to monkey-patch. All of the hard work would be done by one of the above libraries, and glob could be used in the browser, with dropbox, S3, and many others.
It'd also be useful for speeding up the testing of libraries that rely on glob - instead of creating fixtures that touch the real filesystem, the same operations could be done with in-memory objects using memfs (although monkey-patching is less risky in test code).
Of course, to make sure it doesn't add overhead to maintenance of this library, it should come with the disclaimer that glob doesn't take responsibility for incomplete/imperfect fs-emulation. If users have issues with symlinks/missing functionality, they should raise an issue with the library being used to get a virtual fs rather than glob.
It'd be great if we could pass in a virtual filesystem as an option. There are several compatible with the
fsAPI so it shouldn't require many changes:How it'd work:
This would allow usage of
globin lots more places without adding any real maintenance burden or requiring users to monkey-patch. All of the hard work would be done by one of the above libraries, and glob could be used in the browser, with dropbox, S3, and many others.It'd also be useful for speeding up the testing of libraries that rely on
glob- instead of creating fixtures that touch the real filesystem, the same operations could be done with in-memory objects usingmemfs(although monkey-patching is less risky in test code).Of course, to make sure it doesn't add overhead to maintenance of this library, it should come with the disclaimer that
globdoesn't take responsibility for incomplete/imperfectfs-emulation. If users have issues with symlinks/missing functionality, they should raise an issue with the library being used to get a virtual fs rather than glob.