Skip to content

Commit 6e7b733

Browse files
committed
fix: drop cache for new majors
1 parent 5788b67 commit 6e7b733

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cli/lib/build.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ const main = async ({loglevel, releases: rawReleases, useCurrent, navPath, conte
113113
}
114114
})
115115

116+
/**
117+
* this voids the cache when a new version is added to release.json / not in the cli-cache.json
118+
* this is done so that the previous major versions nav can be reset to legacy and pages can be droped from its variant
119+
*/
120+
cache.voidOnNewKey(releases.map(v => v.id))
121+
116122
const updates = await Promise.all(
117123
releases.map(r => extractRelease(r, {cache, contentPath, baseNav: navData, prerelease})),
118124
).then(r => r.filter(Boolean))

cli/lib/cache.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const fs = require('fs/promises')
22

33
/** cache npm cli version shas to NOT pull down changes we already have */
44
class CacheVersionSha {
5+
shouldVoid = false
6+
57
constructor(cache, path) {
68
this.cache = cache
79
this.path = path
@@ -11,6 +13,16 @@ class CacheVersionSha {
1113
return new CacheVersionSha(JSON.parse(await fs.readFile(path, 'utf-8')), path)
1214
}
1315

16+
get keys() {
17+
return Object.keys(this.cache)
18+
}
19+
20+
voidOnNewKey(keys) {
21+
if (keys.length !== this.keys.length || !keys.every(key => this.keys.includes(key))) {
22+
this.shouldVoid = true
23+
}
24+
}
25+
1426
async save() {
1527
await fs.writeFile(this.path, JSON.stringify(this.cache, null, 2))
1628
return this
@@ -22,6 +34,7 @@ class CacheVersionSha {
2234
}
2335

2436
same(id, value) {
37+
if (this.shouldVoid) return false
2538
return this.cache[id] === value
2639
}
2740
}

0 commit comments

Comments
 (0)