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

fix: incorrectly resolving knownJsSrcRE files from root (fixes #4161) #8808

Merged
merged 3 commits into from
Jun 28, 2022

Conversation

sapphi-red
Copy link
Member

Description

path.isAbsolute return true for /something also on windows.
https://nodejs.org/api/path.html#pathisabsolutepath

If the working directory is C:\Users\green, /something means C:\something.

fixes #4161
refs #8122

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added bug p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Jun 27, 2022
@netlify
Copy link

netlify bot commented Jun 27, 2022

Deploy Preview for vite-docs-main ready!

Name Link
🔨 Latest commit 56a77de
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62ba78d8a10d47000846b0de
😎 Deploy Preview https://deploy-preview-8808--vite-docs-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Comment on lines -175 to +176
(preferRelative && /^\w/.test(id)) ||
importer?.endsWith('.html')
((preferRelative || importer?.endsWith('.html')) && /^\w/.test(id))
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 think this was incorrect. If importer is html it was always handled as relative path.

So /foo.svelte will be resolved to

const basedir = importer ? path.dirname(importer) : process.cwd() // C:\Users\green\workspace
const fsPath = path.resolve(basedir, id) // C:\foo.svelte
const normalizedFsPath = normalizePath(fsPath) // C:/foo.svelte

Comment on lines +242 to +245
if (
isNonDriveRelativeAbsolutePath(id) &&
(res = tryFsResolve(id, options))
) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Even if the condition above is fixed, this is still needed.
/foo.svelte will be handled as C:/foo.svelte inside tryFsResolve by fs.statSync and others.

@patak-dev patak-dev merged commit e1e426e into vitejs:main Jun 28, 2022
@sapphi-red sapphi-red deleted the fix/incorrect-root-resolve branch June 28, 2022 11:55
@sapphi-red sapphi-red mentioned this pull request Jul 14, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vite:resolve plugin incorrectly resolves knownJsSrcRE files from root
2 participants