From 19d19803c190b48284526903aab00b3b69311ac8 Mon Sep 17 00:00:00 2001 From: patak Date: Sun, 26 Mar 2023 15:20:25 +0200 Subject: [PATCH] perf: avoid fsp.unlink if we don't use the promise (#12589) --- packages/vite/src/node/config.ts | 6 +----- packages/vite/src/node/optimizer/index.ts | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index d42af1a6a74a3b..19f856a040ef2b 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1093,11 +1093,7 @@ async function loadConfigFromBundledFile( try { return (await dynamicImport(fileUrl)).default } finally { - try { - await fsp.unlink(fileNameTmp) - } catch { - // already removed if this function is called twice simultaneously - } + fs.unlink(fileNameTmp, () => {}) // Ignore errors } } // for cjs, we can register a custom loader via `_require.extensions` diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index e55651537623c2..7782667699b3b3 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -626,7 +626,7 @@ export function runOptimizeDeps( // Clean up old files in the background for (const filePath of oldFilesPaths) - if (!newFilesPaths.has(filePath)) fsp.unlink(filePath) + if (!newFilesPaths.has(filePath)) fs.unlink(filePath, () => {}) // ignore errors await Promise.all(files) },