(
names: string[],
cwd: string = process.cwd(),
multiple: Multiple = false as Multiple,
result: string[] = [],
)
| 776 | type FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined; |
| 777 | |
| 778 | function findUp<Multiple extends boolean = false>( |
| 779 | names: string[], |
| 780 | cwd: string = process.cwd(), |
| 781 | multiple: Multiple = false as Multiple, |
| 782 | result: string[] = [], |
| 783 | ): FindUpResult<Multiple> { |
| 784 | if (!names.some((name) => !!name)) { |
| 785 | return undefined; |
| 786 | } |
| 787 | const target = names.find((name) => fs.existsSync(path.join(cwd, name))); |
| 788 | if (multiple === false && target) { |
| 789 | return path.join(cwd, target) as FindUpResult<Multiple>; |
| 790 | } |
| 791 | if (target) { |
| 792 | result.push(path.join(cwd, target)); |
| 793 | } |
| 794 | const up = path.resolve(cwd, '..'); |
| 795 | if (up === cwd) { |
| 796 | return (multiple && result.length > 0 ? result : undefined) as FindUpResult<Multiple>; |
| 797 | } |
| 798 | return findUp(names, up, multiple, result); |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * Returns the root node of the given AST node by following the `$container` references. |
no test coverage detected