(
files: Record<string, string>,
matcher: FileMatcher,
options: FindFileOptions = {},
)
| 273 | * @throws {Error} When no matching file is found |
| 274 | */ |
| 275 | export const findFile = ( |
| 276 | files: Record<string, string>, |
| 277 | matcher: FileMatcher, |
| 278 | options: FindFileOptions = {}, |
| 279 | ): string => { |
| 280 | const { ignoreHash = true } = options; |
| 281 | const getComparable = (file: string) => (ignoreHash ? file.replace(HASH_PATTERN, '') : file); |
| 282 | const matcherFn = toMatcherFn(matcher); |
| 283 | |
| 284 | for (const file of Object.keys(files)) { |
| 285 | if (matcherFn(getComparable(file))) { |
| 286 | return file; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | throw new Error(`Unable to find file matching "${styleText('cyan', matcher.toString())}"`); |
| 291 | }; |
| 292 | |
| 293 | /** |
| 294 | * Get the content of the first matching file from a files map |
no test coverage detected
searching dependent graphs…