Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cache): simplify
clean
method (#358)
* refactor(cache): simplify `clean` method - `cache().clean()` is only called during instantiation in `options`, so we can instead just call it inside of the constructor - there is no need to call `this.init()` in `clean` as it's only used in the constructor anyway, which already calls `this.init()` - and if `noCache` is `true`, `init` is basically a no-op too - so technically we don't need to call `init` _at all_ if `noCache`, but that's a larger refactor that I'm splitting into a separate commit/PR - now that `clean` is just one conditional, we can invert it and return early instead - it's also not necessary and less efficient to call `emptyDir` before `remove`; `remove` will unlink all the contents anyway - docs here: https://github.com/jprichardson/node-fs-extra/blob/0220eac966d7d6b9a595d69b1242ab8a397fba7f/docs/remove-sync.md - though this also just normal FS behavior - IMO, it's also not necessary to check if it's a directory, we can `remove` it either way - and not necessary to log out if we _don't_ clean it - then also just simplify the logic to use a `filter` instead of a nested `if` - which we already do in several places, so this follows existing code style * undo dir and not clean log removal - as requested in code review, will go with a safety-first operating assumption - as such, with safety as modus operandus, make the logging more detailed in these scenarios, since they're not supposed to happen - and don't check code coverage on these as they're not supposed to happen in normal usage
- Loading branch information