Skip to content

Commit fc5310f

Browse files
authored
fix: esbuildOutputFromId for symlinked root (#10154)
1 parent aebfd9c commit fc5310f

File tree

1 file changed

+15
-5
lines changed
  • packages/vite/src/node/optimizer

1 file changed

+15
-5
lines changed

packages/vite/src/node/optimizer/index.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -911,12 +911,22 @@ function esbuildOutputFromId(
911911
id: string,
912912
cacheDirOutputPath: string
913913
): any {
914+
const cwd = process.cwd()
914915
const flatId = flattenId(id) + '.js'
915-
return outputs[
916-
normalizePath(
917-
path.relative(process.cwd(), path.join(cacheDirOutputPath, flatId))
918-
)
919-
]
916+
const normalizedOutputPath = normalizePath(
917+
path.relative(cwd, path.join(cacheDirOutputPath, flatId))
918+
)
919+
const output = outputs[normalizedOutputPath]
920+
if (output) {
921+
return output
922+
}
923+
// If the root dir was symlinked, esbuild could return output keys as `../cwd/`
924+
// Normalize keys to support this case too
925+
for (const [key, value] of Object.entries(outputs)) {
926+
if (normalizePath(path.relative(cwd, key)) === normalizedOutputPath) {
927+
return value
928+
}
929+
}
920930
}
921931

922932
export async function extractExportsData(

0 commit comments

Comments
 (0)