From 4c111af56c04e2c68e17db849899828d66795aec Mon Sep 17 00:00:00 2001 From: patak Date: Fri, 17 Mar 2023 17:40:06 +0100 Subject: [PATCH 1/2] perf: support # in path only for dependencies --- packages/vite/src/node/plugins/resolve.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 4cdd2043cc41b7..c632aa3b484912 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -474,11 +474,14 @@ function tryFsResolve( ): string | undefined { const { file, postfix } = splitFileAndPostfix(fsPath) + // Dependencies like es5-ext use `#` in their paths. We don't support `#` in user + // source code so we only need to perform the check for dependencies. + const trySharp = fsPath.includes('#') && fsPath.includes('node_modules') + let res: string | undefined - // if there is a postfix, try resolving it as a complete path first (#4703) if ( - postfix && + trySharp && (res = tryResolveFile( fsPath, '', @@ -508,7 +511,7 @@ function tryFsResolve( for (const ext of options.extensions) { if ( - postfix && + trySharp && (res = tryResolveFile( fsPath + ext, '', @@ -543,7 +546,7 @@ function tryFsResolve( if (!tryIndex) return if ( - postfix && + trySharp && (res = tryResolveFile( fsPath, '', From f5c29fa6ee0115ee1aeaa1c284e5a0d2cd8badcc Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 21 Mar 2023 08:52:12 +0100 Subject: [PATCH 2/2] chore: rename trySharp to tryUnsplitted --- packages/vite/src/node/plugins/resolve.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index c632aa3b484912..4c9ac2702bb128 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -476,12 +476,12 @@ function tryFsResolve( // Dependencies like es5-ext use `#` in their paths. We don't support `#` in user // source code so we only need to perform the check for dependencies. - const trySharp = fsPath.includes('#') && fsPath.includes('node_modules') + const tryUnsplitted = fsPath.includes('#') && fsPath.includes('node_modules') let res: string | undefined if ( - trySharp && + tryUnsplitted && (res = tryResolveFile( fsPath, '', @@ -511,7 +511,7 @@ function tryFsResolve( for (const ext of options.extensions) { if ( - trySharp && + tryUnsplitted && (res = tryResolveFile( fsPath + ext, '', @@ -546,7 +546,7 @@ function tryFsResolve( if (!tryIndex) return if ( - trySharp && + tryUnsplitted && (res = tryResolveFile( fsPath, '',