| 54 | } |
| 55 | |
| 56 | const StrictNearestRoot = (includePatterns: string[], excludePatterns?: string[]): RootFunction => { |
| 57 | return async (file, ctx) => { |
| 58 | if (excludePatterns) { |
| 59 | const excludedFiles = Filesystem.up({ |
| 60 | targets: excludePatterns, |
| 61 | start: path.dirname(file), |
| 62 | stop: ctx.directory, |
| 63 | }) |
| 64 | const excluded = await excludedFiles.next() |
| 65 | await excludedFiles.return() |
| 66 | if (excluded.value) return undefined |
| 67 | } |
| 68 | const files = Filesystem.up({ |
| 69 | targets: includePatterns, |
| 70 | start: path.dirname(file), |
| 71 | stop: ctx.directory, |
| 72 | }) |
| 73 | const first = await files.next() |
| 74 | await files.return() |
| 75 | if (!first.value) return undefined |
| 76 | return path.dirname(first.value) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | export interface Info { |
| 81 | id: string |