MCPcopy Index your code
hub / github.com/angular/angular-cli / findUp

Function findUp

packages/angular/cli/src/utilities/find-up.ts:19–44  ·  view source on GitHub ↗
(names: string | string[], from: string)

Source from the content-addressed store, hash-verified

17 * @returns The path to the first match found, or `null` if no match was found.
18 */
19export async function findUp(names: string | string[], from: string): Promise<string | null> {
20 const filenames = Array.isArray(names) ? names : [names];
21
22 let currentDir = resolve(from);
23 while (true) {
24 for (const name of filenames) {
25 const p = join(currentDir, name);
26 try {
27 await stat(p);
28
29 return p;
30 } catch {
31 // Ignore errors (e.g. file not found).
32 }
33 }
34
35 const parentDir = dirname(currentDir);
36 if (parentDir === currentDir) {
37 break;
38 }
39
40 currentDir = parentDir;
41 }
42
43 return null;
44}
45
46/**
47 * Synchronously find a file or directory by walking up the directory tree.

Callers 1

projectFilePathFunction · 0.90

Calls 4

joinFunction · 0.85
resolveFunction · 0.50
statFunction · 0.50
dirnameFunction · 0.50

Tested by

no test coverage detected