Skip to content

Commit

Permalink
perf(resolve): reduce ts check regex run
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 20, 2022
1 parent 28b6200 commit 80f405e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -529,6 +529,7 @@ function tryResolveFile(
targetWeb: boolean,
tryPrefix?: string,
skipPackageJson?: boolean,
skipTsExtension?: boolean,
): string | undefined {
const stat = fs.statSync(file, { throwIfNoEntry: false })
if (stat) {
Expand All @@ -553,8 +554,12 @@ function tryResolveFile(
}
}

const tryTsExtension = options.isFromTsImporter && isPossibleTsOutput(file)
if (tryTsExtension) {
// try resolve .js import to typescript file
if (
!skipTsExtension &&
options.isFromTsImporter &&
isPossibleTsOutput(file)
) {
const tsSrcPaths = getPotentialTsSrcPaths(file)
for (const srcPath of tsSrcPaths) {
const res = tryResolveFile(
Expand All @@ -565,6 +570,7 @@ function tryResolveFile(
targetWeb,
tryPrefix,
skipPackageJson,
true,
)
if (res) return res
}
Expand Down

0 comments on commit 80f405e

Please sign in to comment.