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: cleanUpStaleCacheDirs once per process #12847

Merged
merged 2 commits into from Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/vite/src/node/optimizer/index.ts
Expand Up @@ -13,7 +13,6 @@ import type { ResolvedConfig } from '../config'
import {
arraify,
createDebugger,
emptyDir,
flattenId,
getHash,
isOptimizable,
Expand Down Expand Up @@ -328,6 +327,8 @@ export function addOptimizedDepInfo(
return depInfo
}

let firstLoadCachedDepOptimizationMetadata = true

/**
* Creates the initial dep optimization metadata, loading it from the deps cache
* if it exists and pre-bundling isn't forced
Expand All @@ -340,16 +341,11 @@ export async function loadCachedDepOptimizationMetadata(
): Promise<DepOptimizationMetadata | undefined> {
const log = asCommand ? config.logger.info : debug

setTimeout(() => {
// Before Vite 2.9, dependencies were cached in the root of the cacheDir
// For compat, we remove the cache if we find the old structure
if (fs.existsSync(path.join(config.cacheDir, '_metadata.json'))) {
emptyDir(config.cacheDir)
}
// Fire a clean up of stale cache dirs, in case old processes didn't
// terminate correctly
cleanupDepsCacheStaleDirs(config)
}, 100)
if (firstLoadCachedDepOptimizationMetadata) {
firstLoadCachedDepOptimizationMetadata = false
// Fire up a clean up of stale processing deps dirs if older process exited early
setTimeout(() => cleanupDepsCacheStaleDirs(config), 0)
}

const depsCacheDir = getDepsCacheDir(config, ssr)

Expand Down