Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly handle postfix for getRealPath #5149

Merged
merged 1 commit into from Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -382,7 +382,7 @@ function tryResolveFile(
} catch (e) {}
if (isReadable) {
if (!fs.statSync(file).isDirectory()) {
return normalizePath(ensureVolumeInPath(file)) + postfix
return getRealPath(file, preserveSymlinks) + postfix
} else if (tryIndex) {
if (!skipPackageJson) {
const pkgPath = file + '/package.json'
Expand All @@ -396,7 +396,7 @@ function tryResolveFile(
targetWeb,
preserveSymlinks
)
return resolved ? getRealPath(resolved, preserveSymlinks) : resolved
return resolved
}
}
const index = tryFsResolve(file + '/index', options, preserveSymlinks)
Expand Down Expand Up @@ -479,8 +479,6 @@ export function tryNodeResolve(
return
}

resolved = getRealPath(resolved, preserveSymlinks)

// link id to pkg for browser field mapping check
idToPkgMap.set(resolved, pkg)
if (isBuild) {
Expand Down Expand Up @@ -919,8 +917,9 @@ function equalWithoutSuffix(path: string, key: string, suffix: string) {
}

function getRealPath(resolved: string, preserveSymlinks?: boolean): string {
resolved = ensureVolumeInPath(resolved)
if (!preserveSymlinks && browserExternalId !== resolved) {
return normalizePath(fs.realpathSync(resolved))
resolved = fs.realpathSync(resolved)
}
return resolved
return normalizePath(resolved)
}