@@ -20,14 +20,15 @@ const importConfig = async ({configFile, fileForErrorMessage}) => {
20
20
} ;
21
21
22
22
const loadConfigFile = async ( { projectDir, configFile} ) => {
23
- if ( ! fs . existsSync ( configFile ) ) {
24
- return null ;
25
- }
26
-
27
23
const fileForErrorMessage = path . relative ( projectDir , configFile ) ;
28
24
try {
25
+ await fs . promises . access ( configFile ) ;
29
26
return { config : await importConfig ( { configFile, fileForErrorMessage} ) , configFile, fileForErrorMessage} ;
30
27
} catch ( error ) {
28
+ if ( error . code === 'ENOENT' ) {
29
+ return null ;
30
+ }
31
+
31
32
throw Object . assign ( new Error ( `Error loading ${ fileForErrorMessage } : ${ error . message } ` ) , { parent : error } ) ;
32
33
}
33
34
} ;
@@ -63,6 +64,20 @@ async function findRepoRoot(fromDir) {
63
64
return root ;
64
65
}
65
66
67
+ async function checkJsonFile ( searchDir ) {
68
+ const file = path . join ( searchDir , 'ava.config.json' ) ;
69
+ try {
70
+ await fs . promises . access ( file ) ;
71
+ return file ;
72
+ } catch ( error ) {
73
+ if ( error . code === 'ENOENT' ) {
74
+ return null ;
75
+ }
76
+
77
+ throw error ;
78
+ }
79
+ }
80
+
66
81
export async function loadConfig ( { configFile, resolveFrom = process . cwd ( ) , defaults = { } } = { } ) {
67
82
let packageConf = await packageConfig ( 'ava' , { cwd : resolveFrom } ) ;
68
83
const filepath = packageJsonPath ( packageConf ) ;
@@ -74,6 +89,7 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
74
89
const allowConflictWithPackageJson = Boolean ( configFile ) ;
75
90
configFile = resolveConfigFile ( configFile ) ;
76
91
92
+ const unsupportedFiles = [ ] ;
77
93
let fileConf = NO_SUCH_FILE ;
78
94
let fileForErrorMessage ;
79
95
let conflicting = [ ] ;
@@ -86,12 +102,17 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
86
102
let searchDir = projectDir ;
87
103
const stopAt = path . dirname ( repoRoot ) ;
88
104
do {
89
- const results = await Promise . all ( [ // eslint-disable-line no-await-in-loop
105
+ const [ jsonFile , ...results ] = await Promise . all ( [ // eslint-disable-line no-await-in-loop
106
+ checkJsonFile ( searchDir ) ,
90
107
loadConfigFile ( { projectDir, configFile : path . join ( searchDir , 'ava.config.js' ) } ) ,
91
108
loadConfigFile ( { projectDir, configFile : path . join ( searchDir , 'ava.config.cjs' ) } ) ,
92
109
loadConfigFile ( { projectDir, configFile : path . join ( searchDir , 'ava.config.mjs' ) } ) ,
93
110
] ) ;
94
111
112
+ if ( jsonFile !== null ) {
113
+ unsupportedFiles . push ( jsonFile ) ;
114
+ }
115
+
95
116
[ { config : fileConf , fileForErrorMessage, configFile} = { config : NO_SUCH_FILE , fileForErrorMessage : undefined } , ...conflicting ] = results . filter ( result => result !== null ) ;
96
117
97
118
searchDir = path . dirname ( searchDir ) ;
@@ -139,5 +160,5 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
139
160
}
140
161
}
141
162
142
- return config ;
163
+ return { config, unsupportedFiles } ;
143
164
}
0 commit comments