Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 17, 2022
1 parent fcc50ca commit 9c952b5
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,12 @@ export function tryNodeResolve(
const lastArrowIndex = id.lastIndexOf('>')
const nestedRoot = id.substring(0, lastArrowIndex).trim()
const nestedPath = id.substring(lastArrowIndex + 1).trim()
const possibleIds = getPossibleModuleIds(nestedPath)
possibleIds.reverse()
const nestedPkgId = nestedPath
.split('/', nestedPath[0] === '@' ? 2 : 1)
.join('/')

let basedir: string
if (dedupe?.some((id) => possibleIds.includes(id))) {
if (dedupe?.includes(nestedPkgId)) {
basedir = root
} else if (
importer &&
Expand Down Expand Up @@ -802,25 +803,6 @@ export function tryNodeResolve(
}
}

function getPossibleModuleIds(id: string) {
const moduleIds: string[] = []
let moduleId = ''
for (const part of id.split('/')) {
if (!moduleId) {
moduleId = part
if (part[0] === '@') {
// For efficiency, let's assume that package scope folders
// are guaranteed to never be a module ID.
continue
}
} else {
moduleId += '/' + part
}
moduleIds.push(moduleId)
}
return moduleIds
}

export async function tryOptimizedResolve(
depsOptimizer: DepsOptimizer,
id: string,
Expand Down

0 comments on commit 9c952b5

Please sign in to comment.