@@ -379,6 +379,7 @@ export async function loadCachedDepOptimizationMetadata(
379379 }
380380
381381 // Start with a fresh cache
382+ debug ?.( colors . green ( `removing old cache dir ${ depsCacheDir } ` ) )
382383 await fsp . rm ( depsCacheDir , { recursive : true , force : true } )
383384}
384385
@@ -473,6 +474,7 @@ export function runOptimizeDeps(
473474
474475 // a hint for Node.js
475476 // all files in the cache directory should be recognized as ES modules
477+ debug ?.( colors . green ( `creating package.json in ${ processingCacheDir } ` ) )
476478 fs . writeFileSync (
477479 path . resolve ( processingCacheDir , 'package.json' ) ,
478480 `{\n "type": "module"\n}\n` ,
@@ -499,6 +501,7 @@ export function runOptimizeDeps(
499501 cleaned = true
500502 // No need to wait, we can clean up in the background because temp folders
501503 // are unique per run
504+ debug ?.( colors . green ( `removing cache dir ${ processingCacheDir } ` ) )
502505 fsp . rm ( processingCacheDir , { recursive : true , force : true } ) . catch ( ( ) => {
503506 // Ignore errors
504507 } )
@@ -521,6 +524,7 @@ export function runOptimizeDeps(
521524 // Write metadata file, then commit the processing folder to the global deps cache
522525 // Rewire the file paths from the temporal processing dir to the final deps cache dir
523526 const dataPath = path . join ( processingCacheDir , '_metadata.json' )
527+ debug ?.( colors . green ( `creating _metadata.json in ${ processingCacheDir } ` ) )
524528 fs . writeFileSync (
525529 dataPath ,
526530 stringifyDepsOptimizerMetadata ( metadata , depsCacheDir ) ,
@@ -537,16 +541,30 @@ export function runOptimizeDeps(
537541 const temporalPath = depsCacheDir + getTempSuffix ( )
538542 const depsCacheDirPresent = fs . existsSync ( depsCacheDir )
539543 if ( isWindows ) {
540- if ( depsCacheDirPresent ) await safeRename ( depsCacheDir , temporalPath )
544+ if ( depsCacheDirPresent ) {
545+ debug ?.( colors . green ( `renaming ${ depsCacheDir } to ${ temporalPath } ` ) )
546+ await safeRename ( depsCacheDir , temporalPath )
547+ }
548+ debug ?.(
549+ colors . green ( `renaming ${ processingCacheDir } to ${ depsCacheDir } ` ) ,
550+ )
541551 await safeRename ( processingCacheDir , depsCacheDir )
542552 } else {
543- if ( depsCacheDirPresent ) fs . renameSync ( depsCacheDir , temporalPath )
553+ if ( depsCacheDirPresent ) {
554+ debug ?.( colors . green ( `renaming ${ depsCacheDir } to ${ temporalPath } ` ) )
555+ fs . renameSync ( depsCacheDir , temporalPath )
556+ }
557+ debug ?.(
558+ colors . green ( `renaming ${ processingCacheDir } to ${ depsCacheDir } ` ) ,
559+ )
544560 fs . renameSync ( processingCacheDir , depsCacheDir )
545561 }
546562
547563 // Delete temporal path in the background
548- if ( depsCacheDirPresent )
564+ if ( depsCacheDirPresent ) {
565+ debug ?.( colors . green ( `removing cache temp dir ${ temporalPath } ` ) )
549566 fsp . rm ( temporalPath , { recursive : true , force : true } )
567+ }
550568 } ,
551569 }
552570
@@ -1309,6 +1327,7 @@ export async function cleanupDepsCacheStaleDirs(
13091327 stats ?. mtime &&
13101328 Date . now ( ) - stats . mtime . getTime ( ) > MAX_TEMP_DIR_AGE_MS
13111329 ) {
1330+ debug ?.( `removing stale cache temp dir ${ tempDirPath } ` )
13121331 await fsp . rm ( tempDirPath , { recursive : true , force : true } )
13131332 }
13141333 }
0 commit comments