Skip to content

Commit

Permalink
fix: Look for lockfiles in parent directories if workspaces are being…
Browse files Browse the repository at this point in the history
… used (prisma#29)
  • Loading branch information
Dobefu committed Aug 5, 2024
1 parent 472aee4 commit 6b5ac90
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/package-utils/detect-pm.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { existsSync } from "fs";
import { logWarning } from "./log-helpers";
import path, { dirname } from "path";

type PackageManager = "npm" | "yarn" | "pnpm" | "bun";

function detectPackageManager(): PackageManager {
let projectRoot = process.cwd();

// Find the project root, in case workspaces are being used.
do {
projectRoot = path.resolve(projectRoot, "..");
} while (projectRoot !== "/" && !existsSync(`${projectRoot}/package.json`));

// Check for package-lock.json
if (existsSync("package-lock.json")) {
if (
existsSync("package-lock.json") ||
existsSync(`${projectRoot}/package-lock.json`)
) {
return "npm";
}

// Check for yarn.lock
if (existsSync("yarn.lock")) {
if (existsSync("yarn.lock") || existsSync(`${projectRoot}/yarn.lock`)) {
return "yarn";
}

// Check for pnpm-lock.yaml
if (existsSync("pnpm-lock.yaml")) {
if (
existsSync("pnpm-lock.yaml") ||
existsSync(`${projectRoot}/pnpm-lock.yaml`)
) {
return "pnpm";
}

// bun.lockb
if (existsSync("bun.lockb")) {
if (existsSync("bun.lockb") || existsSync(`${projectRoot}/bun.lockb`)) {
return "bun";
}

Expand Down

0 comments on commit 6b5ac90

Please sign in to comment.