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

Feature request: isEmptyDir() #1037

Open
btea opened this issue Mar 19, 2024 · 6 comments
Open

Feature request: isEmptyDir() #1037

btea opened this issue Mar 19, 2024 · 6 comments

Comments

@btea
Copy link

btea commented Mar 19, 2024

Sometimes we encounter situations where we need to determine whether a directory is empty before deleting or performing other operations. Therefore, I think it might be convenient if an API can be provided.

fs.isEmptyDir(dir[,callback])
@RyanZim
Copy link
Collaborator

RyanZim commented Mar 19, 2024

This is basically a duplicate of #420; though I'm open to reconsidering the decision there.

Can you elaborate more on the use-case here?

@btea
Copy link
Author

btea commented Mar 19, 2024

This is basically a duplicate of #420; though I'm open to reconsidering the decision there.

Oh, sorry, I didn't notice this.

Can you elaborate more on the use-case here?

For example, in pnpm, there is a pnpm patch-remove command. After removing a certain patch file, you need to determine whether the directory where the patch file is stored is empty to decide whether to remove the corresponding folder.

There is also scaffolding that when initializing a project, it will also judge whether it is empty to decide whether to overwrite the content and continue or cancel. And I think this method can also be reused internally in emptyDir.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 20, 2024

I'm especially hesitant to add it as it's trivial to implement wherever it's needed; the code is literally:

!(await fs.readdir(dir)).length

Is it worth creating a method just for this?

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 20, 2024

Also, in the case of something like emptyDir, you wouldn't actually want to use this, as you want the full output from fs.readdir anyhow.

@btea
Copy link
Author

btea commented Mar 21, 2024

I'm especially hesitant to add it as it's trivial to implement wherever it's needed; the code is literally:

!(await fs.readdir(dir)).length

Yes, the code implementation seems relatively simple.

Is it worth creating a method just for this?

It is hoped that providing this wrapper function is just a suggestion. It is difficult for me to give a strong support for whether it is worth adding. The scenario I am currently encountering is the example I provided above.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 21, 2024

cc @JPeer264 @manidlou @jprichardson for thoughts

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

2 participants