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

Function findLockfiles

packages/angular/cli/src/package-managers/discovery.ts:31–64  ·  view source on GitHub ↗

* Searches a directory for lockfiles and returns a set of package managers that correspond to them. * @param host A `Host` instance for interacting with the file system. * @param directory The directory to search. * @param logger An optional logger instance. * @returns A promise that resolves to

(
  host: Host,
  directory: string,
  logger?: Logger,
)

Source from the content-addressed store, hash-verified

29 * @returns A promise that resolves to a set of package manager names.
30 */
31async function findLockfiles(
32 host: Host,
33 directory: string,
34 logger?: Logger,
35): Promise<Set<PackageManagerName>> {
36 logger?.debug(`Searching for lockfiles in '${directory}'...`);
37
38 const foundPackageManagers = new Set<PackageManagerName>();
39 const checks: Promise<void>[] = [];
40
41 for (const [name, descriptor] of Object.entries(SUPPORTED_PACKAGE_MANAGERS)) {
42 const manager = name as PackageManagerName;
43 for (const lockfile of descriptor.lockfiles) {
44 checks.push(
45 (async () => {
46 try {
47 const path = join(directory, lockfile);
48 const stats = await host.stat(path);
49 if (stats.isFile()) {
50 logger?.debug(` Found '${lockfile}'.`);
51 foundPackageManagers.add(manager);
52 }
53 } catch {
54 // File does not exist or cannot be accessed.
55 }
56 })(),
57 );
58 }
59 }
60
61 await Promise.all(checks);
62
63 return foundPackageManagers;
64}
65
66/**
67 * Checks if a given path is a directory.

Callers 1

discoverFunction · 0.85

Calls 7

joinFunction · 0.85
debugMethod · 0.65
statMethod · 0.65
isFileMethod · 0.65
entriesMethod · 0.45
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected