fix(resolver): resolvedPath/index.[ext] resolution (#4548)

This commit is contained in:
Mark 2018-12-13 18:39:42 +00:00 committed by Pooya Parsa
parent 6315bd71f3
commit b413bc14fb

View File

@ -69,16 +69,20 @@ export default class Resolver {
resolvedPath = path resolvedPath = path
} }
// Check if resolvedPath exits // Check if resolvedPath exits and is not a directory
if (fs.existsSync(resolvedPath)) { if (fs.existsSync(resolvedPath) && !fs.lstatSync(resolvedPath).isDirectory()) {
return resolvedPath return resolvedPath
} }
// Check if any resolvedPath.[ext] exists // Check if any resolvedPath.[ext] or resolvedPath/index.[ext] exists
for (const ext of this.options.extensions) { for (const ext of this.options.extensions) {
if (fs.existsSync(resolvedPath + '.' + ext)) { if (fs.existsSync(resolvedPath + '.' + ext)) {
return resolvedPath + '.' + ext return resolvedPath + '.' + ext
} }
if (fs.existsSync(resolvedPath + '/index.' + ext)) {
return resolvedPath + '/index.' + ext
}
} }
// Give up // Give up