File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import fs from 'fs' ;
2- import path from 'path' ;
32import type { RawOptions } from './types.js' ;
3+ import { findConfigFile } from '../core/helpers/findConfigFile.js' ;
44import {
55 printConfigLoaded ,
66 printConfigLoadError ,
@@ -17,17 +17,7 @@ import {
1717export function loadConfig ( cliOptions : Partial < RawOptions > ) : RawOptions {
1818 const cwd = process . cwd ( ) ;
1919
20- // Recursive search upwards for dotenv-diff.config.json
21- function findConfigFile ( dir : string ) : string | null {
22- const configPath = path . resolve ( dir , 'dotenv-diff.config.json' ) ;
23- if ( fs . existsSync ( configPath ) ) return configPath ;
24-
25- const parent = path . dirname ( dir ) ;
26- if ( parent !== dir ) return findConfigFile ( parent ) ;
27- return null ;
28- }
29-
30- const foundPath = findConfigFile ( cwd ) ;
20+ const foundPath = findConfigFile ( cwd , 'dotenv-diff.config.json' ) ;
3121
3222 let fileConfig : Partial < RawOptions > = { } ;
3323
Original file line number Diff line number Diff line change 1+ import fs from 'fs' ;
2+ import path from 'path' ;
3+ /**
4+ * Recursive search upwards for a config file with the given name, starting from the specified directory.
5+ * fx: dotenv-diff.config.json or dotenv-diff.baseline.json
6+ * @param dir - Directory to start searching from
7+ * @param file - The name of the config file to search for
8+ * @returns The path to the config file if found, otherwise null
9+ */
10+ export function findConfigFile ( dir : string , file : string ) : string | null {
11+ const configPath = path . resolve ( dir , file ) ;
12+ if ( fs . existsSync ( configPath ) ) return configPath ;
13+
14+ const parent = path . dirname ( dir ) ;
15+ if ( parent !== dir ) return findConfigFile ( parent , file ) ;
16+ return null ;
17+ }
You can’t perform that action at this time.
0 commit comments