Skip to content

Commit

Permalink
flattened out resolver loading function
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jun 1, 2016
1 parent 322fbbd commit 9b9d905
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/core/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,32 @@ function resolverReducer(resolvers, map) {
}

function requireResolver(name, modulePath) {
try {
// Try to resolve package with absolute path (/Volumes/....)
if (isAbsolute(name)) {
// Try to resolve package with absolute path (/Volumes/....)
if (isAbsolute(name)) {
try {
return require(name)
}
} catch (err) { /* continue */ }
}

try {
// Try to resolve package with path, relative to closest package.json
const packageDir = pkgDir.sync(resolve(modulePath))
// Try to resolve package with path, relative to closest package.json
try {
const packageDir = pkgDir.sync((modulePath))

return require(join(packageDir, name))
} catch (err) {
try {
// Try to resolve package with custom name (@myorg/resolver-name)
return require(name)
} catch (err) { // eslint-disable-line no-shadow
return require(join(packageDir, name))
} catch (err) { /* continue */ }

// Try to resolve package with conventional name
return require(`eslint-import-resolver-${name}`)
}
}
} catch (err) {
throw new Error(`unable to load resolver "${name}".`)
}
// Try to resolve package with custom name (@myorg/resolver-name)
try {
return require(name)
} catch (err) { /* continue */ }

// Try to resolve package with conventional name
try {
return require(`eslint-import-resolver-${name}`)
} catch (err) { /* continue */ }

// all else failed
throw new Error(`unable to load resolver "${name}".`)
}

const erroredContexts = new Set()
Expand Down

0 comments on commit 9b9d905

Please sign in to comment.