diff --git a/cli/lib/build.js b/cli/lib/build.js index 4f7b6be5298..dbb0eeaff13 100644 --- a/cli/lib/build.js +++ b/cli/lib/build.js @@ -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)) diff --git a/cli/lib/cache.js b/cli/lib/cache.js index 3e0dabc8c4b..ca3c89e6d87 100644 --- a/cli/lib/cache.js +++ b/cli/lib/cache.js @@ -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 @@ -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 @@ -22,6 +34,7 @@ class CacheVersionSha { } same(id, value) { + if (this.shouldVoid) return false return this.cache[id] === value } }