Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(kit): try extensions with resolvePath with absolute input (#6233)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 29, 2022
1 parent 63cbb77 commit 5dc864d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/kit/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function resolvePath (path: string, opts: ResolvePathOptions = {}):
path = normalize(path)

// Fast return if the path exists
if (isAbsolute(path) && existsSync(path)) {
if (isAbsolute(path) && existsSync(path) && !(await isDirectory(path))) {
return path
}

Expand All @@ -47,10 +47,10 @@ export async function resolvePath (path: string, opts: ResolvePathOptions = {}):
}

// Check if resolvedPath is a file
let isDirectory = false
let _isDir = false
if (existsSync(path)) {
isDirectory = (await fsp.lstat(path)).isDirectory()
if (!isDirectory) {
_isDir = await isDirectory(path)
if (!_isDir) {
return path
}
}
Expand All @@ -64,7 +64,7 @@ export async function resolvePath (path: string, opts: ResolvePathOptions = {}):
}
// path/index.[ext]
const pathWithIndex = join(path, 'index' + ext)
if (isDirectory && existsSync(pathWithIndex)) {
if (_isDir && existsSync(pathWithIndex)) {
return pathWithIndex
}
}
Expand All @@ -89,8 +89,8 @@ export async function findPath (paths: string|string[], opts?: ResolvePathOption
for (const path of paths) {
const rPath = await resolvePath(path, opts)
if (await existsSensitive(rPath)) {
const isDirectory = (await fsp.lstat(rPath)).isDirectory()
if (!pathType || (pathType === 'file' && !isDirectory) || (pathType === 'dir' && isDirectory)) {
const _isDir = await isDirectory(rPath)
if (!pathType || (pathType === 'file' && !_isDir) || (pathType === 'dir' && _isDir)) {
return rPath
}
}
Expand Down Expand Up @@ -146,6 +146,11 @@ async function existsSensitive (path: string) {
return dirFiles.includes(basename(path))
}

// Usage note: We assume path existance is already ensured
async function isDirectory (path: string) {
return (await fsp.lstat(path)).isDirectory()
}

export async function resolveFiles (path: string, pattern: string | string[]) {
const files = await globby(pattern, { cwd: path, followSymbolicLinks: true })
return files.map(p => resolve(path, p)).filter(p => !isIgnored(p)).sort()
Expand Down

0 comments on commit 5dc864d

Please sign in to comment.