@@ -29,17 +29,13 @@ const loadConfigFile = async ({projectDir, configFile}) => {
29
29
return null ;
30
30
}
31
31
32
- throw Object . assign ( new Error ( `Error loading ${ fileForErrorMessage } : ${ error . message } ` ) , { parent : error } ) ;
32
+ throw Object . assign ( new Error ( `Error loading ${ fileForErrorMessage } : ${ error . message } ` ) , { cause : error } ) ;
33
33
}
34
34
} ;
35
35
36
36
function resolveConfigFile ( configFile ) {
37
37
if ( configFile ) {
38
38
configFile = path . resolve ( configFile ) ; // Relative to CWD
39
-
40
- if ( ! configFile . endsWith ( '.js' ) && ! configFile . endsWith ( '.cjs' ) && ! configFile . endsWith ( '.mjs' ) ) {
41
- throw new Error ( 'Config files must have .js, .cjs or .mjs extensions' ) ;
42
- }
43
39
}
44
40
45
41
return configFile ;
@@ -78,7 +74,7 @@ async function checkJsonFile(searchDir) {
78
74
}
79
75
}
80
76
81
- export async function loadConfig ( { configFile, resolveFrom = process . cwd ( ) , defaults = { } } = { } ) {
77
+ export async function loadConfig ( { configFile, resolveFrom = process . cwd ( ) , defaults = { } } = { } ) { // eslint-disable-line complexity
82
78
let packageConf = await packageConfig ( 'ava' , { cwd : resolveFrom } ) ;
83
79
const filepath = packageJsonPath ( packageConf ) ;
84
80
const projectDir = filepath === undefined ? resolveFrom : path . dirname ( filepath ) ;
@@ -94,7 +90,17 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
94
90
let fileForErrorMessage ;
95
91
let conflicting = [ ] ;
96
92
if ( configFile ) {
97
- const loaded = await loadConfigFile ( { projectDir, configFile} ) ;
93
+ let loaded ;
94
+ try {
95
+ loaded = await loadConfigFile ( { projectDir, configFile} ) ;
96
+ } catch ( error ) {
97
+ if ( ! configFile . endsWith ( '.js' ) && ! configFile . endsWith ( '.cjs' ) && ! configFile . endsWith ( '.mjs' ) ) {
98
+ throw Object . assign ( new Error ( 'Could not load config file; it should have .js, .cjs or .mjs extension' ) , { cause : error } ) ;
99
+ }
100
+
101
+ throw error ;
102
+ }
103
+
98
104
if ( loaded !== null ) {
99
105
( { config : fileConf , fileForErrorMessage} = loaded ) ;
100
106
}
0 commit comments