@@ -159,7 +159,7 @@ export async function initialize({
159
159
// enable loading indicator
160
160
process . env . GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR = `true`
161
161
}
162
- detectLmdbStore ( )
162
+ const lmdbStoreIsUsed = detectLmdbStore ( )
163
163
164
164
if ( config && config . polyfill ) {
165
165
reporter . warn (
@@ -209,20 +209,29 @@ export async function initialize({
209
209
await apiRunnerNode ( `onPreInit` , { parentSpan : activity . span } )
210
210
activity . end ( )
211
211
212
+ const lmdbCacheDirectoryName = `caches-lmdb`
213
+
212
214
const cacheDirectory = `${ program . directory } /.cache`
213
215
const publicDirectory = `${ program . directory } /public`
214
216
const workerCacheDirectory = `${ program . directory } /.cache/worker`
217
+ const lmdbCacheDirectory = `${ program . directory } /.cache/${ lmdbCacheDirectoryName } `
215
218
216
219
const cacheJsonDirExists = fs . existsSync ( `${ cacheDirectory } /json` )
217
220
const publicDirExists = fs . existsSync ( publicDirectory )
218
221
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
219
228
220
229
// For builds in case public dir exists, but cache doesn't, we need to clean up potentially stale
221
230
// artifacts from previous builds (due to cache not being available, we can't rely on tracking of artifacts)
222
231
if (
223
232
process . env . NODE_ENV === `production` &&
224
233
publicDirExists &&
225
- ! cacheJsonDirExists
234
+ ! cacheDirExists
226
235
) {
227
236
activity = reporter . activityTimer (
228
237
`delete html and css files from previous builds` ,
@@ -297,9 +306,8 @@ export async function initialize({
297
306
}
298
307
299
308
// .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
303
311
if ( cacheIsCorrupt ) {
304
312
reporter . info ( reporter . stripIndent `
305
313
We've detected that the Gatsby cache is incomplete (the .cache directory exists
@@ -448,7 +456,11 @@ export async function initialize({
448
456
try {
449
457
await fs . copy ( srcDir , siteDir )
450
458
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
+ }
452
464
453
465
// Ensure .cache/fragments exists and is empty. We want fragments to be
454
466
// added on every run in response to data as fragments can only be added if
0 commit comments