-
-
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
Conversation
@@ -234,7 +234,7 @@ function tryFsResolve( | |||
if (postfixIndex < 0) { | |||
postfixIndex = fsPath.indexOf('#') | |||
} | |||
if (postfixIndex > 0) { | |||
if (postfixIndex > 0 && !fs.existsSync(fsPath.slice(0, postfixIndex + 1))) { |
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.
Should use accessSync
with try-catch (reason see the comment in tryResolveFile). And maybe we can extract it to a util function.
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.
This would only work for cases where full extensions are being used. I think the more complete fix here is:
- Try resolving without removing postfixes first
- If that didn't work, treat
?
and#
as postfixes, remove them and try resolving again.
@@ -234,7 +234,7 @@ function tryFsResolve( | |||
if (postfixIndex < 0) { | |||
postfixIndex = fsPath.indexOf('#') | |||
} | |||
if (postfixIndex > 0) { | |||
if (postfixIndex > 0 && !fs.existsSync(fsPath.slice(0, postfixIndex + 1))) { |
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.
This would only work for cases where full extensions are being used. I think the more complete fix here is:
- Try resolving without removing postfixes first
- If that didn't work, treat
?
and#
as postfixes, remove them and try resolving again.
I have modified the code as yyx suggested |
@YufJi There is a failing test, could you run rebuild everything locally and test it? rm -Rf node_modules
yarn install
yarn build-vite
yarn build-plugin-vue
yarn test |
@YufJi could you please update your branch git switch main
git remote add upstream git://github.com/vitejs/vite.git
git fetch upstream
git pull upstream main
git push
git switch fix--filePath-with-'#'-is-a-direction
git merge main
# resolve conflicts if occur
git commit -m "chore: merge main into pr"
git push or how to update a fork: https://gist.github.com/CristinaSolana/1885435 cause we are seeing something odd here. there is an optimization in another PR https://github.com/vitejs/vite/pull/2718/files#diff-9b81bb364c02eab9494a7d27a5effc400cacbffd3b8f349c192f890c37bfc83fR243-R247 that was brought in, but it isn't in your PR because we think its quite out of date |
okay, let me try it~ |
@YufJi I just updated the comment above to help sync the fork |
…b.com/YufJi/vite into fix--filePath-with-'#'-is-a-direction
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 comment
The 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 tryResolveFile
calls should be:
file ( tryIndex: false )
file ( tryIndex: false, removing postfixes )
for each ext
file+ext
file+ext ( removing postfixes )
file ( tryIndex: true )
file ( tryIndex: true, removing postfixes )
I also think that if ?
and #
are inside the folder path and are not part of the file, we can safely remove the postfixes so we avoid the double checks. So we should check for the presence of ?
and #
only after the last /
. This change alone should fix most issues (the other changes in this PR are still important though).
@hannoeru reported that Vite + pnpm v6 has package resolution issues due to the use of |
Great, at the end, they are going to replace |
Is there a test that can be added to prevent regressions? |
@knightly-bot build this |
🌒 Knightly build enabled, release every night at 00:00 UTC (skip if no change) |
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.
Any updates on this?) |
I wonder if it isn't enough to start scanning for '#' after the last slash as @patak-js suggested, see timvlaer@8d94d5d Do I oversee any other scenario's that are covered by this PR? I can open a new PR from my branch or @YufJi you can take it along in this branch. Same to me. Changing the |
|
||
let postfixIndex = fsPath.indexOf('?') | ||
if (postfixIndex < 0) { | ||
postfixIndex = fsPath.indexOf('#') |
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?
Same error while use vite, Any updates of this mr ? |
🚫 Currently blocking migration from CRA to vite :'( |
Any news? |
@bowencool Yes! See #4703 @iheyunfei is working on it |
Is there any update? Currently blocking migration from Webpack to vite |
For anyone who encountered the Add to Vite config {
find: /^es5-ext\/(.*)?\/#\/(.*)$/,
replacement: path.resolve(require.resolve('es5-ext'), '../$1/../#/$2'),
},
{
find: /^.\/#$/,
replacement: '../#/index.js',
}, |
Thanks for the work in this PR, which was used in part by #4703, closing as it is now merged |
before, vite did not check filePah that includes '#' is adirectory; when code includes
throw error