From bf419d9caa006a14dacedffe7d365575af3c7212 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Sat, 17 Sep 2022 22:22:42 +0200 Subject: [PATCH] fix: esbuildOutputFromId for symlinked root --- packages/vite/src/node/optimizer/index.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 891d2dd709833c..eb80be2c3744a4 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -911,12 +911,22 @@ function esbuildOutputFromId( id: string, cacheDirOutputPath: string ): any { + const cwd = process.cwd() const flatId = flattenId(id) + '.js' - return outputs[ - normalizePath( - path.relative(process.cwd(), path.join(cacheDirOutputPath, flatId)) - ) - ] + const normalizedOutputPath = normalizePath( + path.relative(cwd, path.join(cacheDirOutputPath, flatId)) + ) + const output = outputs[normalizedOutputPath] + if (output) { + return output + } + // If the root dir was symlinked, esbuild could return output keys as `../cwd/` + // Normalize keys to support this case too + for (const [key, value] of Object.entries(outputs)) { + if (normalizePath(path.relative(cwd, key)) === normalizedOutputPath) { + return value + } + } } export async function extractExportsData(