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(vite-node): remove suffix slash on file protocol for window #6109

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

syi0808
Copy link
Contributor

@syi0808 syi0808 commented Jul 12, 2024

Description

In window platform, dynamic import with file protocol are convert to request id and request id normalized by normalizeRequestId function.
normalizeRequestId function's return value with file protocol is like '/C:Users/user/workspace/file.js' in window, so fs can't resolve this absolute path because of suffix forward slash.

For that reason, when isWindow is true, i decided to remove the suffix slash.

before this pr

IMG_9441-min

after this pr

IMG_9440-min

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Fix: #6087

@sheremet-va
Copy link
Member

I don't think this is the root of the problem, this code wasn't touched for a long time. We need to know why the issue happens when it happens. It worked in 1.6.0. We also need a new test case of course.

@syi0808
Copy link
Contributor Author

syi0808 commented Jul 12, 2024

I don't think this is the root of the problem, this code wasn't touched for a long time. We need to know why the issue happens when it happens. It worked in 1.6.0. We also need a new test case of course.

I have trouble to add test. b6a34fa
I dynamic import vite-node/utils, but isWindow not changed. process.platform fixed by first test task.

And let's look for the reason why it worked in 1.6.0. The information I checked while debugging was generated from 2.0.0-beta.1, but the changes in 2.0.0-beta.1 did not seem to have much effect. I checked variously, such as node version and vite, but the only thing I found was the corresponding PR.

@sheremet-va
Copy link
Member

sheremet-va commented Jul 12, 2024

I dynamic import vite-node/utils, but isWindow not changed. It fixed by first process.platform.

  1. You don't need to mock the platform, we are running tests on all platforms
  2. You shouldn't test the function because that's not what this PR fixes - you need to test the dynamic import with an absolute path (vite-node is just an implementation detail)

@syi0808
Copy link
Contributor Author

syi0808 commented Jul 12, 2024

I dynamic import vite-node/utils, but isWindow not changed. It fixed by first process.platform.

  1. You don't need to mock the platform, we are running tests on all platforms
  2. You shouldn't test the function because that's not what this PR fixes - you need to test the dynamic import with an absolute path (vite-node is just an implementation detail)

Thanks for guide. I remove unit test and add integration test about write file and dynamic import.
And I've been debugging, but I can't find a good reason. What's certain is that fs.readFile('/C:/Users/user/workspace/file.js') throws an error.

@syi0808
Copy link
Contributor Author

syi0808 commented Jul 12, 2024

I think failed test is not depend on this pr changes. So new added test is works as well and I'll keep looking for reasons.

@syi0808
Copy link
Contributor Author

syi0808 commented Jul 12, 2024

I found it @sheremet-va. this happen is because of #5177.
In version 1.6.0 server.watch.ignored is exist. So it not cache fs method results that vite implements.
Bug version 2 server.watch.ignored is not exist because remove watchExclude. So it cache fs method results that vite implements.
File path resolving logic in vite fsUtils implemenet so, I don't know the details of the implementation but, file path resolving logic is certainly changed by server.watch.ignored.

Screenshot 2024-07-13 at 6 45 56 AM
Screenshot 2024-07-13 at 6 40 52 AM
Screenshot 2024-07-13 at 7 11 15 AM

@syi0808
Copy link
Contributor Author

syi0808 commented Jul 12, 2024

So I think this change can be resolved separately from the cause, so why not reflect it? Basically, the path with the suffix slash in window is wrong.

@sheremet-va
Copy link
Member

LGTM!

@sheremet-va sheremet-va merged commit 93ebdef into vitest-dev:main Jul 15, 2024
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to load module created in test
2 participants