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

perf: preserve symlinks while scanning user code #12818

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
...resolveOptions,
scan: resolveOpts?.scan ?? resolveOptions.scan,
}
if (!options.preserveSymlinks && resolveOpts?.custom?.depScan) {
// For user code, we can force preserving symlinks so we don't need to do a
// expensive realPathSync call.
if (!isInNodeModules(id) && !bareImportRE.test(id)) {
options.preserveSymlinks = true
}
}

const resolvedImports = resolveSubpathImports(
id,
Expand Down Expand Up @@ -551,7 +558,7 @@ function tryCleanFsResolve(
const fileStat = tryStatSync(file)

// Try direct match first
if (fileStat?.isFile()) return getRealPath(file, options.preserveSymlinks)
if (fileStat?.isFile()) return getRealPath(file, preserveSymlinks)

let res: string | undefined

Expand Down Expand Up @@ -614,7 +621,7 @@ function tryCleanFsResolve(
let pkgPath = `${dirPath}/package.json`
try {
if (fs.existsSync(pkgPath)) {
if (!options.preserveSymlinks) {
if (!preserveSymlinks) {
pkgPath = safeRealpathSync(pkgPath)
}
// path points to a node package
Expand Down