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(runner): resolve and normalize absolute path in fetchModule #18361

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Oct 16, 2024

Description

Not so confident that this is a proper fix nor the issue needs fix, but I'm thinking about what would require to support #18223 and hopefully it helps deciding the fate of the issue (bug or wontfix).

One thing I noticed that it looks possible to dedupe/normalize /abs-path-to/src/etc -> /src/etc on server side (fetchModule) and module identity is still kept intact on runner side. For FetchModuleResult.cache detection, I replaced getModuleByUrl with ensureEntryFromUrl and I'm wondering what's the downside of this.

todo

  • decide on file:// support
    • check if build works?

Copy link

stackblitz bot commented Oct 16, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@hi-ogawa hi-ogawa force-pushed the fix-normalize-url-in-fetchModule branch from bb8c402 to 5e8e7ec Compare October 16, 2024 04:24
@hi-ogawa hi-ogawa changed the title fix(runner): normalize absolute path in fetchModule fix(runner): resolve and normalize absolute path in fetchModule Oct 16, 2024
@hi-ogawa
Copy link
Collaborator Author

normalizeAbsoluteUrl also noramlizes file:///... to support this test case, but I'm not sure if we needs to keep this if we go with externalizing file:// entirely #17369. Also v5's ssrLoadModule('file://') doesn't seem to work either.

// loads the same module if id is a file url
const fileUrl = new _URL('./fixtures/simple.js', import.meta.url)
const mod2 = await runner.import(fileUrl.toString())
expect(mod).toBe(mod2)

Comment on lines 13 to 16
dynamicAbsoluteFull: await import(path.join(
...process.platform === 'win32' ? ['/@fs'] : [],
import.meta.dirname, "simple.js"
)),
Copy link
Collaborator Author

@hi-ogawa hi-ogawa Oct 16, 2024

Choose a reason for hiding this comment

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

After the change, for Windows, import("C:/...") doesn't work but probably this behavior hasn't changed from v5? (Also node doesn't support it either as they require import("file://...") for windows path)

I think I added this test case in #17422 saying it's broken in v6, but maybe it was already broken on v5 if I tested it on Windows 😅

@hi-ogawa hi-ogawa marked this pull request as ready for review October 16, 2024 07:06
@@ -16,7 +16,7 @@ export function normalizeAbsoluteUrl(url: string, root: string): string {
// /root/id.js -> /id.js
Copy link
Member

Choose a reason for hiding this comment

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

I guess the addition of resolveId in fetchModule makes this irrelevant. The only downside is the additional call to the server if the entry point is not normalized, but it was already imported.

If we move this to the environment, then maybe this whole function can be removed, which also makes it so the root is not required anymore

Copy link
Collaborator Author

@hi-ogawa hi-ogawa Oct 16, 2024

Choose a reason for hiding this comment

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

Okay, I moved everything to fetchModule including file:// handling. It looks like this works, but the behavior of file:// might be actually different from browser and v5 since Astro is relying on userland plugin #17369 (comment)

(though In my opinion, supporting file:// out of the box seems nice to have anyways)

@hi-ogawa
Copy link
Collaborator Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

@hi-ogawa hi-ogawa marked this pull request as draft October 16, 2024 23:12
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.

virtual file system is broken in v6
2 participants