MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / findUp

Function findUp

packages/language/src/utils.ts:778–799  ·  view source on GitHub ↗
(
    names: string[],
    cwd: string = process.cwd(),
    multiple: Multiple = false as Multiple,
    result: string[] = [],
)

Source from the content-addressed store, hash-verified

776type FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;
777
778function 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.

Callers 1

getPluginDocumentsFunction · 0.70

Calls 3

findMethod · 0.80
pushMethod · 0.80
resolveMethod · 0.80

Tested by

no test coverage detected