Skip to content

Commit 3d05d4a

Browse files
authored
Merge pull request #69 from 10play/fix/detect-pm-monorepo
fix(cli): detect package manager in monorepo setups
2 parents 7eb3e58 + 10c4193 commit 3d05d4a

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

cli/utils/common.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,27 @@ export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
440440
* Detect the package manager used in a project by checking lock files.
441441
*/
442442
export function detectPackageManager(projectRoot: string): PackageManager {
443-
if (
444-
fs.existsSync(path.join(projectRoot, "bun.lockb")) ||
445-
fs.existsSync(path.join(projectRoot, "bun.lock"))
446-
) {
447-
return "bun";
448-
}
449-
if (fs.existsSync(path.join(projectRoot, "pnpm-lock.yaml"))) {
450-
return "pnpm";
451-
}
452-
if (fs.existsSync(path.join(projectRoot, "yarn.lock"))) {
453-
return "yarn";
443+
let dir = projectRoot;
444+
while (true) {
445+
if (
446+
fs.existsSync(path.join(dir, "bun.lockb")) ||
447+
fs.existsSync(path.join(dir, "bun.lock"))
448+
) {
449+
return "bun";
450+
}
451+
if (fs.existsSync(path.join(dir, "pnpm-lock.yaml"))) {
452+
return "pnpm";
453+
}
454+
if (fs.existsSync(path.join(dir, "yarn.lock"))) {
455+
return "yarn";
456+
}
457+
if (fs.existsSync(path.join(dir, "package-lock.json"))) {
458+
return "npm";
459+
}
460+
461+
const parent = path.dirname(dir);
462+
if (parent === dir) break;
463+
dir = parent;
454464
}
455465
return "npm";
456466
}

0 commit comments

Comments
 (0)