Skip to content

Virtual file system option? #429

@mmkal

Description

@mmkal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions