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

perf(resolve): reduce vite client path checks #12471

Merged
merged 3 commits into from Apr 6, 2023
Merged
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions packages/vite/src/node/config.ts
Expand Up @@ -47,6 +47,7 @@ import {
DEFAULT_EXTENSIONS,
DEFAULT_MAIN_FIELDS,
ENV_ENTRY,
FS_PREFIX,
} from './constants'
import type {
InternalResolveOptions,
Expand Down Expand Up @@ -472,8 +473,8 @@ export async function resolveConfig(
)

const clientAlias = [
{ find: /^\/?@vite\/env/, replacement: ENV_ENTRY },
{ find: /^\/?@vite\/client/, replacement: CLIENT_ENTRY },
{ find: /^\/?@vite\/env/, replacement: FS_PREFIX + ENV_ENTRY },
{ find: /^\/?@vite\/client/, replacement: FS_PREFIX + CLIENT_ENTRY },
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should also clean up and do path.posix.join instead. It's done at ,

rtn = path.posix.join(FS_PREFIX, id)

url = path.posix.join(FS_PREFIX, resolved.id)

but not at
const url = `${FS_PREFIX}${file}`

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to path.posix.join in vitejs/vite@656e5d2 (#12471)

Should we add isFsPathId and fsPathToId in another PR and use them everywhere?

export function isFsPathId(id: string): boolean {
  return id.startsWith(FS_PREFIX)
}

export function fsPathToId(fsPath: string): string {
  return path.posix.join(FS_PREFIX, normalizePath(fsPath))
}

export function fsPathFromId(fsPath: string): string {

Copy link
Member

Choose a reason for hiding this comment

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

Forgot to reply 😅 I don't really have a hard opinion if we want to abstract it, but usually I lean on not abstracting things until it becomes a problem.


Also maybe we can go ahead with this PR too now.

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 maybe we wait for this one a bit more. If #12450 is merged, then we will win a bit, but if not, I think we won't be winning much.

]

// resolve alias with internal client alias
Expand Down