| 26 | } |
| 27 | |
| 28 | export function loadCliConfiguration( |
| 29 | configPath: string | undefined, |
| 30 | workingDirectory: string |
| 31 | ): LoadedCliConfiguration { |
| 32 | const configExplorer = cosmiconfigSync(cosmiconfigModuleName); |
| 33 | let configExplorerResult: CosmiconfigResult | null; |
| 34 | |
| 35 | if (configPath) { |
| 36 | let normalizedConfigPath = configPath; |
| 37 | const matchesWorkingDirectory = normalizedConfigPath.match(workingDirectory); |
| 38 | |
| 39 | if (matchesWorkingDirectory && matchesWorkingDirectory.length > 0) { |
| 40 | normalizedConfigPath = normalizedConfigPath.replace(workingDirectory + path.sep, ''); |
| 41 | } |
| 42 | |
| 43 | configExplorerResult = configExplorer.load(path.resolve(normalizedConfigPath)); |
| 44 | } else { |
| 45 | configExplorerResult = configExplorer.search(); |
| 46 | } |
| 47 | |
| 48 | return { |
| 49 | configFile: configExplorerResult?.config ?? {}, |
| 50 | configExplorerResult |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | export function normalizePatternList(patterns: unknown): string[] { |
| 55 | if (!patterns) { |