lukeed / premove

A tiny (201B to 247B) utility to remove items recursively
MIT License
66 stars 7 forks source link

Async function call does not always return a Promise #4

Closed rdmurphy closed 2 years ago

rdmurphy commented 2 years ago

I'm shocked I'm only now hitting this after using this library since it basically launched, but here we are. 😅

I have premove embedded in a pipeline where a directory gets purged on each run. (Out of my control but I'm back in Gulp land.) I pointed premove at that directory, added it as a step and moved on.

However I quickly hit an issue — as documented if premove does not find the file or directory it returns a bare false. But that's surprising when you're using the async function — I expected a Promise! This whole time I did actually think it returned Promise<false> but maybe my previous uses weren't so sensitive to that. Gulp however doesn't recognize that false as a valid "step complete" signal and locks up.

I can (and will) certainly just code around this, but it did make me wonder if the async function should always return a Promise so other code assuming it's truly an async function won't get tripped up. FWIW the native fsPromise.rmDir and fsPromise.rm do return Promises independent of directory/file existence.

lukeed commented 2 years ago

Thanks for raising this. Yeah, weird choice 😅 I'll cut a 4.0 that has both modes return a boolean, indicating whether or not the path existed. The async will be Promise<boolean> (truly).