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

fix: drop cache for new majors #1419

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ const main = async ({loglevel, releases: rawReleases, useCurrent, navPath, conte
}
})

/**
* this voids the cache when a new version is added to release.json / not in the cli-cache.json
* this is done so that the previous major versions nav can be reset to legacy and pages can be droped from its variant
*/
cache?.voidOnNewKey(releases.map(v => v.id))

const updates = await Promise.all(
releases.map(r => extractRelease(r, {cache, contentPath, baseNav: navData, prerelease})),
).then(r => r.filter(Boolean))
Expand Down
13 changes: 13 additions & 0 deletions cli/lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs/promises')

/** cache npm cli version shas to NOT pull down changes we already have */
class CacheVersionSha {
shouldVoid = false

constructor(cache, path) {
this.cache = cache
this.path = path
Expand All @@ -11,6 +13,16 @@ class CacheVersionSha {
return new CacheVersionSha(JSON.parse(await fs.readFile(path, 'utf-8')), path)
}

get keys() {
return Object.keys(this.cache)
}

voidOnNewKey(keys) {
if (keys.length !== this.keys.length || !keys.every(key => this.keys.includes(key))) {
this.shouldVoid = true
}
}

async save() {
await fs.writeFile(this.path, JSON.stringify(this.cache, null, 2))
return this
Expand All @@ -22,6 +34,7 @@ class CacheVersionSha {
}

same(id, value) {
if (this.shouldVoid) return false
return this.cache[id] === value
}
}
Expand Down
Loading