blob: 1df0accd73827e159f7a13b945c1bd05cd79f38a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import findUp from "find-up";
import path from "path";
export type PackageManager = "yarn" | "pnpm" | "npm";
const cache: { [cwd: string]: PackageManager } = {};
export default function getPackageManager({
directory,
}: { directory?: string } = {}): PackageManager | undefined {
const cwd = directory || process.cwd();
if (cache[cwd]) {
return cache[cwd];
}
const lockFile = findUp.sync(
["yarn.lock", "pnpm-lock.yaml", "package-lock.json"],
{
cwd,
}
);
if (!lockFile) {
return;
}
switch (path.basename(lockFile)) {
case "yarn.lock":
cache[cwd] = "yarn";
break;
case "pnpm-lock.yaml":
cache[cwd] = "pnpm";
break;
case "package-lock.json":
cache[cwd] = "npm";
break;
}
return cache[cwd];
}
|