diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index e62d78fdf1b956..b9d7001c9b3e27 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1291,19 +1291,23 @@ export async function cleanupDepsCacheStaleDirs( const cacheDir = path.resolve(config.cacheDir) if (fs.existsSync(cacheDir)) { const dirents = await fsp.readdir(cacheDir, { withFileTypes: true }) + const promises = [] for (const dirent of dirents) { if (dirent.isDirectory() && dirent.name.includes('_temp_')) { - const tempDirPath = path.resolve(config.cacheDir, dirent.name) - const stats = await fsp.stat(tempDirPath).catch((_) => null) - if ( - 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 }) - } + promises.push(async () => { + const tempDirPath = path.resolve(config.cacheDir, dirent.name) + const stats = await fsp.stat(tempDirPath).catch((_) => null) + if ( + 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 }) + } + }) } } + if (promises.length) await Promise.all(promises) } } catch (err) { config.logger.error(err) diff --git a/packages/vite/src/node/optimizer/optimizer.ts b/packages/vite/src/node/optimizer/optimizer.ts index 096d0bef2cdd54..c411ec309b8eb6 100644 --- a/packages/vite/src/node/optimizer/optimizer.ts +++ b/packages/vite/src/node/optimizer/optimizer.ts @@ -790,17 +790,15 @@ function findInteropMismatches( const needsInteropMismatch = [] for (const dep in discovered) { const discoveredDepInfo = discovered[dep] + if (discoveredDepInfo.needsInterop === undefined) continue + const depInfo = optimized[dep] - if (depInfo) { - if ( - discoveredDepInfo.needsInterop !== undefined && - depInfo.needsInterop !== discoveredDepInfo.needsInterop - ) { - // This only happens when a discovered dependency has mixed ESM and CJS syntax - // and it hasn't been manually added to optimizeDeps.needsInterop - needsInteropMismatch.push(dep) - debug?.(colors.cyan(`✨ needsInterop mismatch detected for ${dep}`)) - } + + if (depInfo.needsInterop !== discoveredDepInfo.needsInterop) { + // This only happens when a discovered dependency has mixed ESM and CJS syntax + // and it hasn't been manually added to optimizeDeps.needsInterop + needsInteropMismatch.push(dep) + debug?.(colors.cyan(`✨ needsInterop mismatch detected for ${dep}`)) } } return needsInteropMismatch