Skip to content

Commit 2c58b6e

Browse files
authoredApr 17, 2023
fix: cleanUpStaleCacheDirs once per process (#12847)
1 parent 31f8b51 commit 2c58b6e

File tree

1 file changed

+7
-11
lines changed
  • packages/vite/src/node/optimizer

1 file changed

+7
-11
lines changed
 

‎packages/vite/src/node/optimizer/index.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type { ResolvedConfig } from '../config'
1313
import {
1414
arraify,
1515
createDebugger,
16-
emptyDir,
1716
flattenId,
1817
getHash,
1918
isOptimizable,
@@ -328,6 +327,8 @@ export function addOptimizedDepInfo(
328327
return depInfo
329328
}
330329

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

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

354350
const depsCacheDir = getDepsCacheDir(config, ssr)
355351

0 commit comments

Comments
 (0)
Please sign in to comment.