-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
Vite: Fix react-vite and projects with absolute path preview entries on Windows #21545
Merged
valentinpalkovic
merged 1 commit into
next
from
valentin/fix-vite-sandbox-development-on-windows
Mar 15, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
...lder-vite/src/utils/transform-abs-path.ts → .../src/utils/strip-abs-node-modules-path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import path from 'path'; | ||
import { normalizePath } from 'vite'; | ||
import slash from 'slash'; | ||
|
||
function normalizePath(id: string) { | ||
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. This is copied largely from the |
||
return path.posix.normalize(slash(id)); | ||
} | ||
|
||
// We need to convert from an absolute path, to a traditional node module import path, | ||
// so that vite can correctly pre-bundle/optimize | ||
export function transformAbsPath(absPath: string) { | ||
export function stripAbsNodeModulesPath(absPath: string) { | ||
// TODO: Evaluate if searching for node_modules in a yarn pnp environment is correct | ||
const splits = absPath.split(`node_modules${path.sep}`); | ||
// Return everything after the final "node_modules/" | ||
const module = normalizePath(splits[splits.length - 1]); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's unfortunate that this is necessary, but it is caused by #21197 (comment) in all projects but also could happen if the user specifies addons in their main.js using absolute paths (for yarn pnp, for instance).
I would love to find a way to avoid so many absolute paths, but it seems like for now at least it's what we are stuck with.
Note that windows will likely still break if the user specifies absolute paths to non-node_modules files, but I don't think that should not be supported anyway (I can't think of a reason it would be needed, at least).
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.
In a pnp situation, the path won't include
node_modules
.