( config: ResolvedConfig, )
| 1420 | |
| 1421 | const MAX_TEMP_DIR_AGE_MS = 24 * 60 * 60 * 1000 |
| 1422 | export async function cleanupDepsCacheStaleDirs( |
| 1423 | config: ResolvedConfig, |
| 1424 | ): Promise<void> { |
| 1425 | try { |
| 1426 | const cacheDir = path.resolve(config.cacheDir) |
| 1427 | if (fs.existsSync(cacheDir)) { |
| 1428 | const dirents = await fsp.readdir(cacheDir, { withFileTypes: true }) |
| 1429 | for (const dirent of dirents) { |
| 1430 | if (dirent.isDirectory() && dirent.name.includes('_temp_')) { |
| 1431 | const tempDirPath = path.resolve(config.cacheDir, dirent.name) |
| 1432 | const stats = await fsp.stat(tempDirPath).catch(() => null) |
| 1433 | if ( |
| 1434 | stats?.mtime && |
| 1435 | Date.now() - stats.mtime.getTime() > MAX_TEMP_DIR_AGE_MS |
| 1436 | ) { |
| 1437 | debug?.(`removing stale cache temp dir ${tempDirPath}`) |
| 1438 | await fsp.rm(tempDirPath, { recursive: true, force: true }) |
| 1439 | } |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | } catch (err) { |
| 1444 | config.logger.error(err) |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | // We found issues with renaming folders in some systems. This is a custom |
| 1449 | // implementation for the optimizer. It isn't intended to be a general utility |
no test coverage detected