1
1
import crossImport from 'cross-import'
2
2
import { existsSync } from 'fs'
3
- import { resolve } from 'path'
3
+ import { parse , resolve } from 'path'
4
4
5
5
export interface ExploreConfigOptions {
6
6
extensions ?: ( 'js' | 'ts' | 'cjs' | 'cts' | 'mjs' | 'mts' ) [ ]
@@ -18,13 +18,23 @@ export default function exploreConfig(name: string, options: ExploreConfigOption
18
18
// try to find the config file with the given name and options.extensions
19
19
let foundConfigPath : string | undefined
20
20
let foundBasename : string | undefined
21
- for ( const eachExtension of options . extensions ) {
22
- const eachBasename = name + '.' + eachExtension
23
- const eachPath = resolve ( options . cwd || '' , eachBasename )
24
- if ( existsSync ( eachPath ) ) {
25
- foundConfigPath = eachPath
26
- foundBasename = eachBasename
27
- break
21
+ if ( options . extensions . find ( ext => name . endsWith ( '.' + ext ) ) ) {
22
+ const resolvedPath = resolve ( options . cwd || '' , name )
23
+ if ( existsSync ( resolvedPath ) ) {
24
+ foundConfigPath = resolvedPath
25
+ foundBasename = parse ( name ) . base
26
+ }
27
+ } else {
28
+ for ( const eachExtension of options . extensions ) {
29
+ const eachBasename = name . endsWith ( '.' + eachExtension )
30
+ ? name
31
+ : name + '.' + eachExtension
32
+ const eachPath = resolve ( options . cwd || '' , eachBasename )
33
+ if ( existsSync ( eachPath ) ) {
34
+ foundConfigPath = eachPath
35
+ foundBasename = eachBasename
36
+ break
37
+ }
28
38
}
29
39
}
30
40
if ( foundConfigPath ) {
0 commit comments