Skip to content

Commit 751cc43

Browse files
authored
fix(gatsby): replace checks for .cache/json with checks for .cache/caches-lmdb (#33431)
1 parent 20eb2e0 commit 751cc43

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

packages/gatsby/src/services/initialize.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export async function initialize({
159159
// enable loading indicator
160160
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR = `true`
161161
}
162-
detectLmdbStore()
162+
const lmdbStoreIsUsed = detectLmdbStore()
163163

164164
if (config && config.polyfill) {
165165
reporter.warn(
@@ -209,20 +209,29 @@ export async function initialize({
209209
await apiRunnerNode(`onPreInit`, { parentSpan: activity.span })
210210
activity.end()
211211

212+
const lmdbCacheDirectoryName = `caches-lmdb`
213+
212214
const cacheDirectory = `${program.directory}/.cache`
213215
const publicDirectory = `${program.directory}/public`
214216
const workerCacheDirectory = `${program.directory}/.cache/worker`
217+
const lmdbCacheDirectory = `${program.directory}/.cache/${lmdbCacheDirectoryName}`
215218

216219
const cacheJsonDirExists = fs.existsSync(`${cacheDirectory}/json`)
217220
const publicDirExists = fs.existsSync(publicDirectory)
218221
const workerCacheDirExists = fs.existsSync(workerCacheDirectory)
222+
const lmdbCacheDirExists = fs.existsSync(lmdbCacheDirectory)
223+
224+
// check the cache file that is used by the current configuration
225+
const cacheDirExists = lmdbStoreIsUsed
226+
? lmdbCacheDirExists
227+
: cacheJsonDirExists
219228

220229
// For builds in case public dir exists, but cache doesn't, we need to clean up potentially stale
221230
// artifacts from previous builds (due to cache not being available, we can't rely on tracking of artifacts)
222231
if (
223232
process.env.NODE_ENV === `production` &&
224233
publicDirExists &&
225-
!cacheJsonDirExists
234+
!cacheDirExists
226235
) {
227236
activity = reporter.activityTimer(
228237
`delete html and css files from previous builds`,
@@ -297,9 +306,8 @@ export async function initialize({
297306
}
298307

299308
// .cache directory exists in develop at this point
300-
// so checking for .cache/json as a heuristic (could be any expected file)
301-
const cacheIsCorrupt = cacheJsonDirExists && !publicDirExists
302-
309+
// so checking for .cache/json or .cache/caches-lmdb as a heuristic (could be any expected file)
310+
const cacheIsCorrupt = cacheDirExists && !publicDirExists
303311
if (cacheIsCorrupt) {
304312
reporter.info(reporter.stripIndent`
305313
We've detected that the Gatsby cache is incomplete (the .cache directory exists
@@ -448,7 +456,11 @@ export async function initialize({
448456
try {
449457
await fs.copy(srcDir, siteDir)
450458
await fs.copy(tryRequire, `${siteDir}/test-require-error.js`)
451-
await fs.ensureDirSync(`${cacheDirectory}/json`)
459+
if (lmdbStoreIsUsed) {
460+
await fs.ensureDirSync(`${cacheDirectory}/${lmdbCacheDirectoryName}`)
461+
} else {
462+
await fs.ensureDirSync(`${cacheDirectory}/json`)
463+
}
452464

453465
// Ensure .cache/fragments exists and is empty. We want fragments to be
454466
// added on every run in response to data as fragments can only be added if

0 commit comments

Comments
 (0)