Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): replace checks for .cache/json with checks for .cache/caches-lmdb #33431

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function initialize({
// enable loading indicator
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR = `true`
}
detectLmdbStore()
const lmdbStoreIsUsed = detectLmdbStore()

if (config && config.polyfill) {
reporter.warn(
Expand Down Expand Up @@ -209,20 +209,29 @@ export async function initialize({
await apiRunnerNode(`onPreInit`, { parentSpan: activity.span })
activity.end()

const lmdbCacheDirectoryName = `caches-lmdb`

const cacheDirectory = `${program.directory}/.cache`
const publicDirectory = `${program.directory}/public`
const workerCacheDirectory = `${program.directory}/.cache/worker`
const lmdbCacheDirectory = `${program.directory}/.cache/${lmdbCacheDirectoryName}`

const cacheJsonDirExists = fs.existsSync(`${cacheDirectory}/json`)
const publicDirExists = fs.existsSync(publicDirectory)
const workerCacheDirExists = fs.existsSync(workerCacheDirectory)
const lmdbCacheDirExists = fs.existsSync(lmdbCacheDirectory)

// check the cache file that is used by the current configuration
const cacheDirExists = lmdbStoreIsUsed
? lmdbCacheDirExists
: cacheJsonDirExists

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

// .cache directory exists in develop at this point
// so checking for .cache/json as a heuristic (could be any expected file)
const cacheIsCorrupt = cacheJsonDirExists && !publicDirExists

// so checking for .cache/json or .cache/caches-lmdb as a heuristic (could be any expected file)
const cacheIsCorrupt = cacheDirExists && !publicDirExists
if (cacheIsCorrupt) {
reporter.info(reporter.stripIndent`
We've detected that the Gatsby cache is incomplete (the .cache directory exists
Expand Down Expand Up @@ -448,7 +456,11 @@ export async function initialize({
try {
await fs.copy(srcDir, siteDir)
await fs.copy(tryRequire, `${siteDir}/test-require-error.js`)
await fs.ensureDirSync(`${cacheDirectory}/json`)
if (lmdbStoreIsUsed) {
await fs.ensureDirSync(`${cacheDirectory}/${lmdbCacheDirectoryName}`)
} else {
await fs.ensureDirSync(`${cacheDirectory}/json`)
}

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