tunnckoCore / opensource

Delivering delightful digital solutions. Monorepo of monorepos of Open Source packages with combined ~100M/month downloads, semantically versioned following @conventional-commits. Fully powered ES Modules, @Airbnb @ESLint + @Prettier, independent & fixed versioning. Quality with @Actions, CodeQL, & Dependabot.
https://tunnckocore.com/opensource
481 stars 18 forks source link

glob-cache: update cache file when `changed`, automatically #196

Open tunnckoCore opened 2 years ago

tunnckoCore commented 2 years ago

Seems like currently, it detects that the file has changed, but doesn't update the cache to the new state. Thus, it always hits the changed hook.

It's easy like

// Update the changed file's cache,
// Note: maybe we should handle that on glob-cache automatically?
await cacache.put(cacheLocation, file.path, file.contents);

on the if ctx.changed, and after the call of hooks.changed.

tunnckoCore commented 2 years ago

Use cacache.verify after the loop, and cacache.rm.content old content on changed.

Also add done/finish hook.

edit:

Seems like when you call verify it automatically cleans up the old content file and the index file. So, the only needed is to call it once at the end of all, such as in done hook.

The done hook is handy, if you don't want to include cacache as dep in the upper module. Or because version collisions. This way you use the same cacache version, as glob-cache one.

Make the default done hook do just that cacache.verify.

tunnckoCore commented 2 years ago

Do not read the files by default.