@@ -547,20 +547,17 @@ export function runOptimizeDeps(
547547 // is safer than a delete-rename operation.
548548 const temporaryPath = depsCacheDir + getTempSuffix ( )
549549 const depsCacheDirPresent = fs . existsSync ( depsCacheDir )
550+ if ( depsCacheDirPresent ) {
551+ debug ?.( colors . green ( `renaming ${ depsCacheDir } to ${ temporaryPath } ` ) )
552+ await safeRename ( depsCacheDir , temporaryPath )
553+ }
554+
550555 if ( isWindows ) {
551- if ( depsCacheDirPresent ) {
552- debug ?.( colors . green ( `renaming ${ depsCacheDir } to ${ temporaryPath } ` ) )
553- await safeRename ( depsCacheDir , temporaryPath )
554- }
555556 debug ?.(
556557 colors . green ( `renaming ${ processingCacheDir } to ${ depsCacheDir } ` ) ,
557558 )
558559 await safeRename ( processingCacheDir , depsCacheDir )
559560 } else {
560- if ( depsCacheDirPresent ) {
561- debug ?.( colors . green ( `renaming ${ depsCacheDir } to ${ temporaryPath } ` ) )
562- fs . renameSync ( depsCacheDir , temporaryPath )
563- }
564561 debug ?.(
565562 colors . green ( `renaming ${ processingCacheDir } to ${ depsCacheDir } ` ) ,
566563 )
@@ -1291,19 +1288,23 @@ export async function cleanupDepsCacheStaleDirs(
12911288 const cacheDir = path . resolve ( config . cacheDir )
12921289 if ( fs . existsSync ( cacheDir ) ) {
12931290 const dirents = await fsp . readdir ( cacheDir , { withFileTypes : true } )
1291+ const promises = [ ]
12941292 for ( const dirent of dirents ) {
12951293 if ( dirent . isDirectory ( ) && dirent . name . includes ( '_temp_' ) ) {
1296- const tempDirPath = path . resolve ( config . cacheDir , dirent . name )
1297- const stats = await fsp . stat ( tempDirPath ) . catch ( ( _ ) => null )
1298- if (
1299- stats ?. mtime &&
1300- Date . now ( ) - stats . mtime . getTime ( ) > MAX_TEMP_DIR_AGE_MS
1301- ) {
1302- debug ?.( `removing stale cache temp dir ${ tempDirPath } ` )
1303- await fsp . rm ( tempDirPath , { recursive : true , force : true } )
1304- }
1294+ promises . push ( async ( ) => {
1295+ const tempDirPath = path . resolve ( config . cacheDir , dirent . name )
1296+ const stats = await fsp . stat ( tempDirPath ) . catch ( ( _ ) => null )
1297+ if (
1298+ stats ?. mtime &&
1299+ Date . now ( ) - stats . mtime . getTime ( ) > MAX_TEMP_DIR_AGE_MS
1300+ ) {
1301+ debug ?.( `removing stale cache temp dir ${ tempDirPath } ` )
1302+ await fsp . rm ( tempDirPath , { recursive : true , force : true } )
1303+ }
1304+ } )
13051305 }
13061306 }
1307+ if ( promises . length ) await Promise . all ( promises )
13071308 }
13081309 } catch ( err ) {
13091310 config . logger . error ( err )
0 commit comments