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

Function discover

packages/angular/cli/src/package-managers/discovery.ts:92–131  ·  view source on GitHub ↗
(
  host: Host,
  startDir: string,
  logger?: Logger,
)

Source from the content-addressed store, hash-verified

90 * @returns A promise that resolves to the name of the discovered package manager, or null if none is found.
91 */
92export async function discover(
93 host: Host,
94 startDir: string,
95 logger?: Logger,
96): Promise<PackageManagerName | null> {
97 logger?.debug(`Starting package manager discovery in '${startDir}'...`);
98 let currentDir = startDir;
99
100 while (true) {
101 const found = await findLockfiles(host, currentDir, logger);
102
103 if (found.size > 0) {
104 logger?.debug(`Found lockfile(s): [${[...found].join(', ')}]. Applying precedence...`);
105 for (const packageManager of PACKAGE_MANAGER_PRECEDENCE) {
106 if (found.has(packageManager)) {
107 logger?.debug(`Selected '${packageManager}' based on precedence.`);
108
109 return packageManager;
110 }
111 }
112 }
113
114 // Stop searching if we reach the git repository root.
115 if (await isDirectory(host, join(currentDir, '.git'))) {
116 logger?.debug(`Reached repository root at '${currentDir}'. Stopping search.`);
117
118 return null;
119 }
120
121 const parentDir = dirname(currentDir);
122 if (parentDir === currentDir) {
123 // We have reached the filesystem root.
124 logger?.debug('Reached filesystem root. No lockfile found.');
125
126 return null;
127 }
128
129 currentDir = parentDir;
130 }
131}

Callers 2

discovery_spec.tsFile · 0.90
determinePackageManagerFunction · 0.90

Calls 6

findLockfilesFunction · 0.85
joinFunction · 0.85
isDirectoryFunction · 0.70
debugMethod · 0.65
hasMethod · 0.65
dirnameFunction · 0.50

Tested by

no test coverage detected