mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +00:00
fix(kit): make resolvePath
case-sensitive (#291)
This commit is contained in:
parent
35e2b474d0
commit
6cd5f8816f
@ -1,5 +1,5 @@
|
||||
import { existsSync, lstatSync } from 'fs'
|
||||
import { resolve, join } from 'upath'
|
||||
import { existsSync, lstatSync, readdirSync } from 'fs'
|
||||
import { basename, dirname, resolve, join } from 'upath'
|
||||
import globby from 'globby'
|
||||
|
||||
export interface ResolveOptions {
|
||||
@ -20,7 +20,7 @@ export interface ResolveOptions {
|
||||
|
||||
function resolvePath (path: string, opts: ResolveOptions = {}) {
|
||||
// Fast return if the path exists
|
||||
if (existsSync(path)) {
|
||||
if (existsSyncSensitive(path)) {
|
||||
return path
|
||||
}
|
||||
|
||||
@ -34,9 +34,11 @@ function resolvePath (path: string, opts: ResolveOptions = {}) {
|
||||
// Resolve relative to base or cwd
|
||||
resolvedPath = resolve(opts.base || '.', resolvedPath)
|
||||
|
||||
const resolvedPathFiles = readdirSync(dirname(resolvedPath))
|
||||
|
||||
// Check if resolvedPath is a file
|
||||
let isDirectory = false
|
||||
if (existsSync(resolvedPath)) {
|
||||
if (existsSyncSensitive(resolvedPath, resolvedPathFiles)) {
|
||||
isDirectory = lstatSync(resolvedPath).isDirectory()
|
||||
if (!isDirectory) {
|
||||
return resolvedPath
|
||||
@ -47,12 +49,12 @@ function resolvePath (path: string, opts: ResolveOptions = {}) {
|
||||
for (const ext of opts.extensions) {
|
||||
// resolvedPath.[ext]
|
||||
const resolvedPathwithExt = resolvedPath + ext
|
||||
if (!isDirectory && existsSync(resolvedPathwithExt)) {
|
||||
if (!isDirectory && existsSyncSensitive(resolvedPathwithExt, resolvedPathFiles)) {
|
||||
return resolvedPathwithExt
|
||||
}
|
||||
// resolvedPath/index.[ext]
|
||||
const resolvedPathwithIndex = join(resolvedPath, 'index' + ext)
|
||||
if (isDirectory && existsSync(resolvedPathwithIndex)) {
|
||||
if (isDirectory && existsSyncSensitive(resolvedPathwithIndex)) {
|
||||
return resolvedPathwithIndex
|
||||
}
|
||||
}
|
||||
@ -66,6 +68,12 @@ function resolvePath (path: string, opts: ResolveOptions = {}) {
|
||||
throw new Error(`Cannot resolve "${path}" from "${resolvedPath}"`)
|
||||
}
|
||||
|
||||
function existsSyncSensitive (path: string, files?: string[]) {
|
||||
if (!existsSync(path)) { return false }
|
||||
const _files = files || readdirSync(dirname(path))
|
||||
return _files.includes(basename(path))
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a path with any relevant aliases resolved.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user