@@ -91,58 +91,8 @@ async function loadFile(
9191) : Promise < Record < string , any > > {
9292 const filePath : string = path . join ( cwd , file )
9393 const extension = path . extname ( filePath )
94- << < < < << HEAD
95- let definitions
96- switch ( extension ) {
97- case '.json' :
98- definitions = JSON . parse (
99- await promisify ( fs . readFile ) ( filePath , { encoding : 'utf-8' } )
100- )
101- break
102- case '.yaml' :
103- case '.yml' :
104- definitions = YAML . parse (
105- await promisify ( fs . readFile ) ( filePath , { encoding : 'utf-8' } )
106- )
107- break
108- case '.cjs' :
109- logger . debug (
110- `Loading configuration file "${ file } " as CommonJS based on extension`
111- )
112- // eslint-disable-next-line @typescript-eslint/no-require-imports
113- definitions = require ( filePath )
114- break
115- case '.mjs' :
116- logger . debug (
117- `Loading configuration file "${ file } " as ESM based on extension`
118- )
119- definitions = await import ( pathToFileURL ( filePath ) . toString ( ) )
120- break
121- case '.js' :
122- {
123- logger . debug (
124- `Loading configuration file "${ file } " as JavaScript based on extension`
125- )
126- const ambiguous = await import ( pathToFileURL ( filePath ) . toString ( ) )
127- if ( 'module.exports' in ambiguous ) {
128- logger . debug (
129- `Treating configuration file "${ file } " as CommonJS based on heuristics`
130- )
131- definitions = ambiguous [ 'module.exports' ]
132- } else {
133- logger . debug (
134- `Treating configuration file "${ file } " as ESM based on heuristics`
135- )
136- definitions = ambiguous
137- }
138- }
139- break
140- default :
141- throw new Error ( `Unsupported configuration file extension "${ extension } "` )
142- === = ===
14394 if ( ! SUPPORTED_EXTENSIONS . includes ( extension ) ) {
14495 throw new Error ( `Unsupported configuration file extension "${ extension } "` )
145- >>> > >>> main
14696 }
14797 let definitions
14898 try {
@@ -186,27 +136,23 @@ async function loadFile(
186136 definitions = await import ( pathToFileURL ( filePath ) . toString ( ) )
187137 break
188138 case '.js' :
189- {
190- const parentPackage = await readPackageJson ( filePath )
191- if ( ! parentPackage ) {
192- logger . debug (
193- `Loading configuration file "${ file } " as CommonJS based on absence of a parent package`
194- )
195- // eslint-disable-next-line @typescript-eslint/no-require-imports
196- definitions = require ( filePath )
197- } else if ( parentPackage . type === 'module' ) {
198- logger . debug (
199- `Loading configuration file "${ file } " as ESM based on "${ parentPackage . name } " package type`
200- )
201- definitions = await import ( pathToFileURL ( filePath ) . toString ( ) )
202- } else {
203- logger . debug (
204- `Loading configuration file "${ file } " as CommonJS based on "${ parentPackage . name } " package type`
205- )
206- // eslint-disable-next-line @typescript-eslint/no-require-imports
207- definitions = require ( filePath )
208- }
139+ {
140+ logger . debug (
141+ `Loading configuration file "${ file } " as JavaScript based on extension`
142+ )
143+ const ambiguous = await import ( pathToFileURL ( filePath ) . toString ( ) )
144+ if ( 'module.exports' in ambiguous ) {
145+ logger . debug (
146+ `Treating configuration file "${ file } " as CommonJS based on heuristics`
147+ )
148+ definitions = ambiguous [ 'module.exports' ]
149+ } else {
150+ logger . debug (
151+ `Treating configuration file "${ file } " as ESM based on heuristics`
152+ )
153+ definitions = ambiguous
209154 }
155+ }
210156 break
211157 }
212158 } catch ( error ) {
0 commit comments