From 21a62daea59b66cf095f5de1a230ccc0bea5932b Mon Sep 17 00:00:00 2001 From: sun0day Date: Tue, 19 Sep 2023 16:40:50 +0800 Subject: [PATCH] chore(optimizer): debug info on cache dir handle process (#12858) --- packages/vite/src/node/optimizer/index.ts | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 6ae227d5db156f..ba6e11f0e4d2ea 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -379,6 +379,7 @@ export async function loadCachedDepOptimizationMetadata( } // Start with a fresh cache + debug?.(colors.green(`removing old cache dir ${depsCacheDir}`)) await fsp.rm(depsCacheDir, { recursive: true, force: true }) } @@ -473,6 +474,7 @@ export function runOptimizeDeps( // a hint for Node.js // all files in the cache directory should be recognized as ES modules + debug?.(colors.green(`creating package.json in ${processingCacheDir}`)) fs.writeFileSync( path.resolve(processingCacheDir, 'package.json'), `{\n "type": "module"\n}\n`, @@ -499,6 +501,7 @@ export function runOptimizeDeps( cleaned = true // No need to wait, we can clean up in the background because temp folders // are unique per run + debug?.(colors.green(`removing cache dir ${processingCacheDir}`)) fsp.rm(processingCacheDir, { recursive: true, force: true }).catch(() => { // Ignore errors }) @@ -521,6 +524,7 @@ export function runOptimizeDeps( // Write metadata file, then commit the processing folder to the global deps cache // Rewire the file paths from the temporal processing dir to the final deps cache dir const dataPath = path.join(processingCacheDir, '_metadata.json') + debug?.(colors.green(`creating _metadata.json in ${processingCacheDir}`)) fs.writeFileSync( dataPath, stringifyDepsOptimizerMetadata(metadata, depsCacheDir), @@ -537,16 +541,30 @@ export function runOptimizeDeps( const temporalPath = depsCacheDir + getTempSuffix() const depsCacheDirPresent = fs.existsSync(depsCacheDir) if (isWindows) { - if (depsCacheDirPresent) await safeRename(depsCacheDir, temporalPath) + if (depsCacheDirPresent) { + debug?.(colors.green(`renaming ${depsCacheDir} to ${temporalPath}`)) + await safeRename(depsCacheDir, temporalPath) + } + debug?.( + colors.green(`renaming ${processingCacheDir} to ${depsCacheDir}`), + ) await safeRename(processingCacheDir, depsCacheDir) } else { - if (depsCacheDirPresent) fs.renameSync(depsCacheDir, temporalPath) + if (depsCacheDirPresent) { + debug?.(colors.green(`renaming ${depsCacheDir} to ${temporalPath}`)) + fs.renameSync(depsCacheDir, temporalPath) + } + debug?.( + colors.green(`renaming ${processingCacheDir} to ${depsCacheDir}`), + ) fs.renameSync(processingCacheDir, depsCacheDir) } // Delete temporal path in the background - if (depsCacheDirPresent) + if (depsCacheDirPresent) { + debug?.(colors.green(`removing cache temp dir ${temporalPath}`)) fsp.rm(temporalPath, { recursive: true, force: true }) + } }, } @@ -1309,6 +1327,7 @@ export async function cleanupDepsCacheStaleDirs( stats?.mtime && Date.now() - stats.mtime.getTime() > MAX_TEMP_DIR_AGE_MS ) { + debug?.(`removing stale cache temp dir ${tempDirPath}`) await fsp.rm(tempDirPath, { recursive: true, force: true }) } }