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 cannot load configuration files in the link directory (#4180) #4181

Merged
merged 5 commits into from May 13, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Expand Up @@ -889,7 +889,7 @@ async function loadConfigFromBundledFile(
const extension = path.extname(fileName)
const defaultLoader = require.extensions[extension]!
require.extensions[extension] = (module: NodeModule, filename: string) => {
if (filename === fileName) {
if (filename === fs.realpathSync(fileName)) {
Copy link
Member

Choose a reason for hiding this comment

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

@patak-js Wasn't there something about realpathSync that it is bad? Cause it is slow or something?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know, we are not using it in the codebase. But we are using its async version realPath here:

sourceRoot = await fs.realpath(
, so I don't think performance is an issue here. It is only while reading the config file. But I let others more used to linked files to check this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I think fs.realpathSync(fileName) will be called many times, if it is here and require exists inside the config.
How about caching it like this?

const realFileName = fs.realpathSync(fileName)
require.extensions[extension] = (module: NodeModule, filename: string) => {
  if (filename === realFileName) {

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense @sapphi-red, would you like to send a commit with that change to this PR directly?

Copy link
Member

Choose a reason for hiding this comment

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

I updated 👍

;(module as NodeModuleWithCompile)._compile(bundledCode, filename)
} else {
defaultLoader(module, filename)
Expand Down