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: resolver.ts fixes + code cleanup + matching practices #947

Merged
merged 7 commits into from
Oct 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/node/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ const resolveFilePathPostfix = (filePath: string): string | undefined => {
postfix = ext
break
}
if (isFile(path.join(cleanPath, '/index' + ext))) {
postfix = '/index' + ext
const defaultFilePath = `/index${ext}`
if (isFile(path.join(cleanPath, defaultFilePath))) {
postfix = defaultFilePath
break
}
}
Expand Down Expand Up @@ -155,9 +156,9 @@ export function createResolver(
}
}

resolvers.forEach((r) => {
if (r.alias && typeof r.alias === 'object') {
resolveAlias(r.alias)
resolvers.forEach(({ alias }) => {
yyx990803 marked this conversation as resolved.
Show resolved Hide resolved
if (alias && typeof alias === 'object') {
resolveAlias(alias)
}
})
resolveAlias(userAlias)
Expand Down Expand Up @@ -281,9 +282,8 @@ export function createResolver(
if (aliased) {
return aliased
}
for (const r of resolvers) {
aliased =
r.alias && typeof r.alias === 'function' ? r.alias(id) : undefined
for (const { alias } of resolvers) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refer to comment #1

aliased = alias && typeof alias === 'function' ? alias(id) : undefined
if (aliased) {
return aliased
}
Expand Down Expand Up @@ -365,8 +365,7 @@ export function resolveBareModuleRequest(
if (!pkgInfo.entry) {
console.error(
chalk.yellow(
`[vite] dependency ${id} does not have default entry defined in ` +
`package.json.`
`[vite] dependency ${id} does not have default entry defined in package.json.`
)
)
} else {
Expand Down Expand Up @@ -510,7 +509,7 @@ export function resolveNodeModule(

// resolve object browser field in package.json
// https://github.com/defunctzombie/package-browser-field-spec
const browserField = pkg.browser
const { browser: browserField } = pkg
if (entryPoint && browserField && typeof browserField === 'object') {
entryPoint = mapWithBrowserField(entryPoint, browserField)
}
Expand Down Expand Up @@ -583,9 +582,9 @@ function mapWithBrowserField(
map: Record<string, string>
) {
const normalized = normalize(relativePathInPkgDir)
const foundEntry = Object.entries(map).find(([from]) => {
return normalize(from) === normalized
})
const foundEntry = Object.entries(map).find(
([from]) => normalize(from) === normalized
)
if (!foundEntry) {
return normalized
}
Expand Down