From cafe43321127bc02c141287c3989090115447e84 Mon Sep 17 00:00:00 2001 From: patak Date: Sat, 2 Dec 2023 23:11:45 +0100 Subject: [PATCH] fix: back to realpathSync for windows --- packages/vite/src/node/utils.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 08e28871e8ea56..1bf08dded36116 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -631,15 +631,11 @@ export function copyDir(srcDir: string, destDir: string): void { // https://github.com/nodejs/node/issues/37737 export let safeRealpath = isWindows ? windowsSafeRealPath : fsp.realpath -async function realpathFallback(path: string) { - return fs.realpathSync(path) -} - // Based on https://github.com/larrybahr/windows-network-drive // MIT License, Copyright (c) 2017 Larry Bahr const windowsNetworkMap = new Map() -async function windowsMappedRealpath(path: string) { - const realPath = await fsp.realpath(path) +function windowsMappedRealpath(path: string) { + const realPath = fs.realpathSync.native(path) if (realPath.startsWith('\\\\')) { for (const [network, volume] of windowsNetworkMap) { if (realPath.startsWith(network)) return realPath.replace(network, volume) @@ -650,7 +646,7 @@ async function windowsMappedRealpath(path: string) { const parseNetUseRE = /^(\w+)? +(\w:) +([^ ]+)\s/ let firstSafeRealPathRun = false -async function windowsSafeRealPath(path: string): Promise { +function windowsSafeRealPath(path: string): string { if (!firstSafeRealPathRun) { optimizeSafeRealPath() firstSafeRealPathRun = true @@ -662,7 +658,7 @@ async function optimizeSafeRealPath() { // Skip if using Node <18.10 due to MAX_PATH issue: https://github.com/vitejs/vite/issues/12931 const nodeVersion = process.versions.node.split('.').map(Number) if (nodeVersion[0] < 18 || (nodeVersion[0] === 18 && nodeVersion[1] < 10)) { - safeRealpath = realpathFallback + safeRealpath = fs.realpathSync return } // Check the availability `fs.realpathSync.native` @@ -672,7 +668,7 @@ async function optimizeSafeRealPath() { await fsp.realpath(path.resolve('./')) } catch (error) { if (error.message.includes('EISDIR: illegal operation on a directory')) { - safeRealpath = realpathFallback + safeRealpath = fs.realpathSync return } } @@ -686,7 +682,7 @@ async function optimizeSafeRealPath() { if (m) windowsNetworkMap.set(m[3], m[2]) } if (windowsNetworkMap.size === 0) { - safeRealpath = fsp.realpath + safeRealpath = fs.realpathSync.native } else { safeRealpath = windowsMappedRealpath }