Bring your own file system for globbing by proxying the cache
This library uses some implementation detail of the
glob package by adding Proxies to specific cache options.
Since the cache is always checked before executing a certain file system operation, this package completely bypasses the underlying
By its very nature a cache is synchronous. Therefore all proxied file system operations need to return synchronously.
That's why this package only makes sense for
glob.sync. It also works for the async counterpart, but since file system access is sync behind the scenes, this is rather useless.
Creating an interceptor
You can create an interceptor by calling
createGlobInterceptor(fs) and providing an object that implements the following interface for file system access:
/** A minimal abstraction of FileSystem operations needed to provide a cache proxy for 'glob'. None of the methods are expected to throw. */
For convenience there is a utility function
fromNodeLikeFileSystem, that returns an instance of
GlobFileSystem for a given file system compatible with Node's
Using the interceptor
With the previously created
interceptor you can now invoke
glob.sync to intercept all file system interaction:
;// or if you are targeting a runtime without object spread, you can use `Object.assign` insteadresult = glob.sync'**' /* any pattern you want */, Object.assign, interceptor;
You can reuse an interceptor as often as you want or need.
interceptor contains the following properties:
If you add one of these properties to your options object, they will be overridden by the ones from
If you explicitly override any of these properties with your own, the interceptor will not work as expected.
Unless your implementation of
GlobFileSystem does some caching, it will always
execute the underlying binding. There's a utility function
memoizeFileSystem to add caching to your
MIT © Klaus Meinhardt