refactor(update): share package.json readers

This commit is contained in:
Peter Steinberger
2026-02-16 00:41:28 +00:00
parent 32221e194a
commit dece9e8b07
3 changed files with 26 additions and 41 deletions

View File

@@ -5,6 +5,7 @@ import path from "node:path";
import type { UpdateStepProgress, UpdateStepResult } from "../../infra/update-runner.js";
import { resolveStateDir } from "../../config/paths.js";
import { resolveOpenClawPackageRoot } from "../../infra/openclaw-root.js";
import { readPackageName, readPackageVersion } from "../../infra/package-json.js";
import { trimLogTail } from "../../infra/restart-sentinel.js";
import { parseSemver } from "../../infra/runtime-guard.js";
import { fetchNpmTagVersion } from "../../infra/update-check.js";
@@ -68,15 +69,7 @@ export function normalizeVersionTag(tag: string): string | null {
return parseSemver(cleaned) ? cleaned : null;
}
export async function readPackageVersion(root: string): Promise<string | null> {
try {
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
const parsed = JSON.parse(raw) as { version?: string };
return typeof parsed.version === "string" ? parsed.version : null;
} catch {
return null;
}
}
export { readPackageName, readPackageVersion };
export async function resolveTargetVersion(
tag: string,
@@ -99,17 +92,6 @@ export async function isGitCheckout(root: string): Promise<boolean> {
}
}
export async function readPackageName(root: string): Promise<string | null> {
try {
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
const parsed = JSON.parse(raw) as { name?: string };
const name = parsed?.name?.trim();
return name ? name : null;
} catch {
return null;
}
}
export async function isCorePackage(root: string): Promise<boolean> {
const name = await readPackageName(root);
return Boolean(name && CORE_PACKAGE_NAMES.has(name));