@@ -29,17 +29,13 @@ const loadConfigFile = async ({projectDir, configFile}) => {
2929 return null ;
3030 }
3131
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 } ) ;
3333 }
3434} ;
3535
3636function resolveConfigFile ( configFile ) {
3737 if ( configFile ) {
3838 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- }
4339 }
4440
4541 return configFile ;
@@ -78,7 +74,7 @@ async function checkJsonFile(searchDir) {
7874 }
7975}
8076
81- export async function loadConfig ( { configFile, resolveFrom = process . cwd ( ) , defaults = { } } = { } ) {
77+ export async function loadConfig ( { configFile, resolveFrom = process . cwd ( ) , defaults = { } } = { } ) { // eslint-disable-line complexity
8278 let packageConf = await packageConfig ( 'ava' , { cwd : resolveFrom } ) ;
8379 const filepath = packageJsonPath ( packageConf ) ;
8480 const projectDir = filepath === undefined ? resolveFrom : path . dirname ( filepath ) ;
@@ -94,7 +90,17 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
9490 let fileForErrorMessage ;
9591 let conflicting = [ ] ;
9692 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+
98104 if ( loaded !== null ) {
99105 ( { config : fileConf , fileForErrorMessage} = loaded ) ;
100106 }
0 commit comments