| 184 | options?: { rootFirst?: boolean }, |
| 185 | ): Promise<string[]> |
| 186 | export async function findUp( |
| 187 | target: string | string[], |
| 188 | start: string, |
| 189 | stop?: string, |
| 190 | options?: { rootFirst?: boolean }, |
| 191 | ) { |
| 192 | const dirs = [start] |
| 193 | let current = start |
| 194 | while (true) { |
| 195 | if (stop === current) break |
| 196 | const parent = dirname(current) |
| 197 | if (parent === current) break |
| 198 | dirs.push(parent) |
| 199 | current = parent |
| 200 | } |
| 201 | |
| 202 | const targets = Array.isArray(target) ? target : [target] |
| 203 | const result = [] |
| 204 | for (const dir of options?.rootFirst ? dirs.toReversed() : dirs) { |
| 205 | for (const item of targets) { |
| 206 | const search = join(dir, item) |
| 207 | if (await exists(search)) result.push(search) |
| 208 | } |
| 209 | } |
| 210 | return result |
| 211 | } |
| 212 | |
| 213 | export async function* up(options: { targets: string[]; start: string; stop?: string }) { |
| 214 | const { targets, start, stop } = options |