-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: filePath with "#" is a directory #2432
Changes from 5 commits
57893b5
ffd4c0d
2060f21
0e38265
0fb5172
1a6e643
1121768
388dbef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,23 +222,12 @@ export function resolvePlugin(baseOptions: InternalResolveOptions): Plugin { | |
} | ||
} | ||
|
||
function tryFsResolve( | ||
fsPath: string, | ||
function tryResolve( | ||
file: string, | ||
postfix: string, | ||
options: InternalResolveOptions, | ||
tryIndex = true | ||
): string | undefined { | ||
let file = fsPath | ||
let postfix = '' | ||
|
||
let postfixIndex = fsPath.indexOf('?') | ||
if (postfixIndex < 0) { | ||
postfixIndex = fsPath.indexOf('#') | ||
} | ||
if (postfixIndex > 0) { | ||
file = fsPath.slice(0, postfixIndex) | ||
postfix = fsPath.slice(postfixIndex) | ||
} | ||
|
||
let res: string | undefined | ||
for (const ext of options.extensions || DEFAULT_EXTENSIONS) { | ||
if ( | ||
|
@@ -261,6 +250,35 @@ function tryFsResolve( | |
} | ||
} | ||
|
||
function tryFsResolve( | ||
fsPath: string, | ||
options: InternalResolveOptions, | ||
tryIndex = true | ||
): string | undefined { | ||
let file = fsPath | ||
let postfix = '' | ||
let res: string | undefined | ||
|
||
// 1、Try resolving without removing postfixes first | ||
if ((res = tryResolve(file, postfix, options, tryIndex))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are going to lose the optimization introduced in #2718 with this PR. When people use imports with extensions, we should first check for an exact match before trying the list of auto-resolved extensions. Also, I think that we should first with the extensions removed to avoid two checks per file for common cases. The order of the
I also think that if |
||
return res | ||
} | ||
|
||
// 2、If that didn't work, treat ? and # as postfixes, remove them and try resolving again. | ||
let postfixIndex = fsPath.indexOf('?') | ||
if (postfixIndex < 0) { | ||
postfixIndex = fsPath.indexOf('#') | ||
} | ||
if (postfixIndex > 0) { | ||
file = fsPath.slice(0, postfixIndex) | ||
postfix = fsPath.slice(postfixIndex) | ||
} | ||
|
||
if ((res = tryResolve(file, postfix, options, tryIndex))) { | ||
return res | ||
} | ||
} | ||
|
||
function tryResolveFile( | ||
file: string, | ||
postfix: string, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As #2346 (comment) said, can we just remove this line so that
#
are always treated as part of file path?