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

omit parameters #111

Closed
dealloc opened this issue Jul 22, 2016 · 4 comments
Closed

omit parameters #111

dealloc opened this issue Jul 22, 2016 · 4 comments

Comments

@dealloc
Copy link

dealloc commented Jul 22, 2016

Sometimes you just want to delete a directory and don't care wether or not that happened,
currently I need to pass this:

rimraf(loc, {}, () => {});

As both the options and callback parameter are required. Wouldn't it be easier if you could just omit the parameters if you didn't need them?

It took me a couple minutes longer than it should've to figure this out, I eventually found out how to do this due to #96

@isaacs
Copy link
Owner

isaacs commented Jul 22, 2016

Options are not required, only the callback.

$ mkdir -p a/b/c/d/e

$ node -e 'require("rimraf")("a", () => {})'

$ ls a
ls: a: No such file or directory

@isaacs isaacs closed this as completed Jul 22, 2016
@dealloc
Copy link
Author

dealloc commented Jul 22, 2016

Why would the callback be required if I can just pass in an empty function?
This seems like a bit overhead

@isaacs
Copy link
Owner

isaacs commented Jul 22, 2016

Because race conditions should be opt-in.

If you have a rimraf (or file creation, stat, etc.) and don't provide a callback, then there is no way for your program to behave in a deterministic manner. It could take a long time to delete that file, or barely any time at all.

If you want a simpler program, then the right way to go is to use rimraf.sync(path), where no callback is required, and the removal happens before the next line of code.

If you really truly want to just fire it off into the ether, and never be alerted, that's fine, but this module (like most filesystem utilities in Node.js) requires that you explicitly state that intention by providing a function that does nothing. The purpose is to make it clear in your program that that's what you're doing, and that it's on purpose rather than an oversight.

The order of the assertions is misleading, though, because it does seem to indicate that options are required rather than that a callback is required. I will reorder the assertions in the rimraf function to make the reason for the failure clearer.

@isaacs isaacs reopened this Jul 22, 2016
@isaacs isaacs closed this as completed in 5ecd321 Jul 22, 2016
@dealloc
Copy link
Author

dealloc commented Jul 22, 2016

Ah, I should've looked at .sync more in depth, I agree with the decision that you must state your intention explicitly.

My bad

iarna added a commit to npm/npm that referenced this issue Aug 11, 2016
Clarify assertions: cb is required, options are not  …
Fix isaacs/rimraf#111

Credit: @isaacs
iarna added a commit to npm/npm that referenced this issue Aug 12, 2016
Clarify assertions: cb is required, options are not

Fixes: isaacs/rimraf#111
Credit: @isaacs
zkat added a commit to npm/npm that referenced this issue Sep 8, 2016
Clarify assertions: cb is required, options are not

Fixes: isaacs/rimraf#111
Credit: @isaacs
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