From 48fa7a013c6d779a6d4f95353480146b829238d5 Mon Sep 17 00:00:00 2001 From: merceyz Date: Sun, 11 Feb 2024 15:20:03 +0100 Subject: [PATCH] perf: skip `existsSync` check --- sources/corepackUtils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sources/corepackUtils.ts b/sources/corepackUtils.ts index e3bba8d29..f0be61f10 100644 --- a/sources/corepackUtils.ts +++ b/sources/corepackUtils.ts @@ -110,7 +110,7 @@ export async function installVersion(installTarget: string, locator: Locator, {s const installFolder = path.join(installTarget, locator.name, version); - if (fs.existsSync(installFolder)) { + try { const corepackFile = path.join(installFolder, `.corepack`); const corepackContent = await fs.promises.readFile(corepackFile, `utf8`); const corepackData = JSON.parse(corepackContent); @@ -121,6 +121,10 @@ export async function installVersion(installTarget: string, locator: Locator, {s hash: corepackData.hash as string, location: installFolder, }; + } catch (err) { + if ((err as nodeUtils.NodeError).code !== `ENOENT`) { + throw err; + } } const defaultNpmRegistryURL = spec.url.replace(`{}`, version);