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

refactor(cache): simplify clean method #358

Merged
merged 2 commits into from Jun 20, 2022

Commits on Jun 12, 2022

  1. 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
    agilgur5 committed Jun 12, 2022
    Configuration menu
    Copy the full SHA
    9a90337 View commit details
    Browse the repository at this point in the history

Commits on Jun 17, 2022

  1. 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
    agilgur5 committed Jun 17, 2022
    Configuration menu
    Copy the full SHA
    7e87e32 View commit details
    Browse the repository at this point in the history