mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 04:53:40 +00:00
24 lines
703 B
TypeScript
24 lines
703 B
TypeScript
import fs from "node:fs/promises";
|
|
import { readPackageManagerSpec } from "./package-json.js";
|
|
|
|
type DetectedPackageManager = "pnpm" | "bun" | "npm";
|
|
|
|
export async function detectPackageManager(root: string): Promise<DetectedPackageManager | null> {
|
|
const pm = (await readPackageManagerSpec(root))?.split("@")[0]?.trim();
|
|
if (pm === "pnpm" || pm === "bun" || pm === "npm") {
|
|
return pm;
|
|
}
|
|
|
|
const files = await fs.readdir(root).catch((): string[] => []);
|
|
if (files.includes("pnpm-lock.yaml")) {
|
|
return "pnpm";
|
|
}
|
|
if (files.includes("bun.lock") || files.includes("bun.lockb")) {
|
|
return "bun";
|
|
}
|
|
if (files.includes("package-lock.json")) {
|
|
return "npm";
|
|
}
|
|
return null;
|
|
}
|