Skip to content

Commit 6fcf10c

Browse files
authored
fix: drop cache for new majors (#1419)
currently when new majors are introduced we need to shift around branches / older versions need to be rebuild, so we invalidate the cache here when a new major is introduced
1 parent df8e6e5 commit 6fcf10c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cli/lib/build.js

+6
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

+13
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
const sortedCache = {}
1628
Object.keys(this.cache)
@@ -33,6 +45,7 @@ class CacheVersionSha {
3345
}
3446

3547
same(id, value) {
48+
if (this.shouldVoid) return false
3649
return this.cache[id] === value
3750
}
3851
}

0 commit comments

Comments
 (0)