@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
64 lines (62 loc) • 1.73 kB
JavaScript
// @bun
// src/utils/package-manager.ts
import { execSync } from "child_process";
import { existsSync } from "fs";
import { join } from "path";
var PACKAGE_MANAGER_LOCK_FILES = [
{ fileName: "bun.lock", command: "bun" },
{ fileName: "bun.lockb", command: "bun" },
{ fileName: "pnpm-lock.yaml", command: "pnpm" },
{ fileName: "yarn.lock", command: "yarn" },
{ fileName: "package-lock.json", command: "npm" }
];
function detectPackageManagers() {
const managers = [
{
name: "Bun",
command: "bun",
installCommand: "bun install"
},
{
name: "pnpm",
command: "pnpm",
installCommand: "pnpm install"
},
{
name: "Yarn",
command: "yarn",
installCommand: "yarn install"
},
{
name: "npm",
command: "npm",
installCommand: "npm install"
}
];
return managers.map((manager) => ({
...manager,
available: isCommandAvailable(manager.command)
}));
}
function isCommandAvailable(command) {
try {
const checkCommand = process.platform === "win32" ? "where" : "which";
execSync(`${checkCommand} ${command}`, { stdio: "ignore" });
return true;
} catch {
return false;
}
}
function getPreferredPackageManager(projectPath, availableManagers) {
for (const lockFile of PACKAGE_MANAGER_LOCK_FILES) {
const lockPath = join(projectPath, lockFile.fileName);
if (existsSync(lockPath)) {
const manager = availableManagers.find((m) => m.command === lockFile.command);
if (manager?.available) {
return manager;
}
}
}
return availableManagers.find((m) => m.available) || null;
}
export { PACKAGE_MANAGER_LOCK_FILES, detectPackageManagers, getPreferredPackageManager };