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(resolve): support # in path only for dependencies #12469

Merged
merged 2 commits into from Mar 21, 2023
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: 7 additions & 4 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -474,11 +474,14 @@ function tryFsResolve(
): string | undefined {
const { file, postfix } = splitFileAndPostfix(fsPath)

// Dependencies like es5-ext use `#` in their paths. We don't support `#` in user
// source code so we only need to perform the check for dependencies.
const tryUnsplitted = fsPath.includes('#') && fsPath.includes('node_modules')

let res: string | undefined

// if there is a postfix, try resolving it as a complete path first (#4703)
if (
Copy link
Member

@sun0day sun0day Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add some comments before each if branch. The comments tell what fsPath will hit these if conditions. It's helpful for understanding these codes quickly and refactoring them later. And I guess there are still rooms to dedupe resolve logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the variable instead of adding a new comment because I think the main comment for tryUnsplitted is enough now.

postfix &&
tryUnsplitted &&
(res = tryResolveFile(
fsPath,
'',
Expand Down Expand Up @@ -508,7 +511,7 @@ function tryFsResolve(

for (const ext of options.extensions) {
if (
postfix &&
tryUnsplitted &&
(res = tryResolveFile(
fsPath + ext,
'',
Expand Down Expand Up @@ -543,7 +546,7 @@ function tryFsResolve(
if (!tryIndex) return

if (
postfix &&
tryUnsplitted &&
(res = tryResolveFile(
fsPath,
'',
Expand Down