Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect options.fs in checkCwdOption #236

Open
unicornware opened this issue Sep 4, 2022 · 0 comments
Open

respect options.fs in checkCwdOption #236

unicornware opened this issue Sep 4, 2022 · 0 comments

Comments

@unicornware
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant