sindresorhus / globby

User-friendly glob matching
MIT License
2.49k stars 126 forks source link

respect `options.fs` in `checkCwdOption` #236

Open unicornware opened 1 year ago

unicornware commented 1 year ago

fast-glob allows the use of custom file system functions via the fs option.

checkCwdOption should respect options.fs:

diff --git a/index.js b/index.js
index ce5a65639d49b3fc665b35d4b0d162e092c9d612..445bbadf62a85b4aab4728c3aafa34fd30c3caf9 100644
--- a/index.js
+++ b/index.js
@@ -29,7 +29,7 @@ const checkCwdOption = options => {

    let stat;
    try {
-       stat = fs.statSync(options.cwd);
+       stat = (options?.fs ?? fs).statSync(options.cwd);
    } catch {
        return;
    }

otherwise, it may yield a false positive.

let's say a user is mocking the file system with memfs. if options.cwd resolves to a directory on their machine, but isn't found in their mock file system, checkCwdOption will not catch the error. it checks the wrong file system.