diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index e62d78fdf1b956..71e2b138f753ea 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -547,20 +547,17 @@ export function runOptimizeDeps( // is safer than a delete-rename operation. const temporaryPath = depsCacheDir + getTempSuffix() const depsCacheDirPresent = fs.existsSync(depsCacheDir) + if (depsCacheDirPresent) { + debug?.(colors.green(`renaming ${depsCacheDir} to ${temporaryPath}`)) + await safeRename(depsCacheDir, temporaryPath) + } + if (isWindows) { - if (depsCacheDirPresent) { - debug?.(colors.green(`renaming ${depsCacheDir} to ${temporaryPath}`)) - await safeRename(depsCacheDir, temporaryPath) - } debug?.( colors.green(`renaming ${processingCacheDir} to ${depsCacheDir}`), ) await safeRename(processingCacheDir, depsCacheDir) } else { - if (depsCacheDirPresent) { - debug?.(colors.green(`renaming ${depsCacheDir} to ${temporaryPath}`)) - fs.renameSync(depsCacheDir, temporaryPath) - } debug?.( colors.green(`renaming ${processingCacheDir} to ${depsCacheDir}`), ) @@ -1291,19 +1288,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