Skip to content

Commit

Permalink
fix: cleanUpStaleCacheDirs once per process (#12847)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Apr 17, 2023
1 parent 31f8b51 commit 2c58b6e
Showing 1 changed file with 7 additions and 11 deletions.
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

0 comments on commit 2c58b6e

Please sign in to comment.