mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:48:26 +00:00
refactor(update): dedupe package manager detection
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
resolveControlUiDistIndexHealth,
|
||||
resolveControlUiDistIndexPathForRoot,
|
||||
} from "./control-ui-assets.js";
|
||||
import { detectPackageManager as detectPackageManagerImpl } from "./detect-package-manager.js";
|
||||
import { trimLogTail } from "./restart-sentinel.js";
|
||||
import {
|
||||
channelToNpmTag,
|
||||
@@ -254,28 +255,7 @@ async function findPackageRoot(candidates: string[]) {
|
||||
}
|
||||
|
||||
async function detectPackageManager(root: string) {
|
||||
try {
|
||||
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
|
||||
const parsed = JSON.parse(raw) as { packageManager?: string };
|
||||
const pm = parsed?.packageManager?.split("@")[0]?.trim();
|
||||
if (pm === "pnpm" || pm === "bun" || pm === "npm") {
|
||||
return pm;
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
const files = await fs.readdir(root).catch((): string[] => []);
|
||||
if (files.includes("pnpm-lock.yaml")) {
|
||||
return "pnpm";
|
||||
}
|
||||
if (files.includes("bun.lockb")) {
|
||||
return "bun";
|
||||
}
|
||||
if (files.includes("package-lock.json")) {
|
||||
return "npm";
|
||||
}
|
||||
return "npm";
|
||||
return (await detectPackageManagerImpl(root)) ?? "npm";
|
||||
}
|
||||
|
||||
type RunStepOptions = {
|
||||
|
||||
Reference in New Issue
Block a user