mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-28 10:22:32 +00:00
refactor(cli): extract hook pack update flow
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import fsSync from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { openBoundaryFileSync } from "../infra/boundary-file-read.js";
|
||||
import {
|
||||
expectedIntegrityForUpdate,
|
||||
readInstalledPackageVersion,
|
||||
} from "../infra/package-update-utils.js";
|
||||
import type { UpdateChannel } from "../infra/update-channels.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { resolveBundledPluginSources } from "./bundled-sources.js";
|
||||
@@ -103,49 +104,6 @@ type InstallIntegrityDrift = {
|
||||
};
|
||||
};
|
||||
|
||||
function expectedIntegrityForUpdate(
|
||||
spec: string | undefined,
|
||||
integrity: string | undefined,
|
||||
): string | undefined {
|
||||
if (!integrity || !spec) {
|
||||
return undefined;
|
||||
}
|
||||
const value = spec.trim();
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
const at = value.lastIndexOf("@");
|
||||
if (at <= 0 || at >= value.length - 1) {
|
||||
return undefined;
|
||||
}
|
||||
const version = value.slice(at + 1).trim();
|
||||
if (!/^v?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version)) {
|
||||
return undefined;
|
||||
}
|
||||
return integrity;
|
||||
}
|
||||
|
||||
async function readInstalledPackageVersion(dir: string): Promise<string | undefined> {
|
||||
const manifestPath = path.join(dir, "package.json");
|
||||
const opened = openBoundaryFileSync({
|
||||
absolutePath: manifestPath,
|
||||
rootPath: dir,
|
||||
boundaryLabel: "installed plugin directory",
|
||||
});
|
||||
if (!opened.ok) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const raw = fsSync.readFileSync(opened.fd, "utf-8");
|
||||
const parsed = JSON.parse(raw) as { version?: unknown };
|
||||
return typeof parsed.version === "string" ? parsed.version : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
} finally {
|
||||
fsSync.closeSync(opened.fd);
|
||||
}
|
||||
}
|
||||
|
||||
function pathsEqual(
|
||||
left: string | undefined,
|
||||
right: string | undefined,
|
||||
|
||||
Reference in New Issue
Block a user