Files
openclaw/src/version.ts
2026-02-03 17:31:51 -08:00

44 lines
1.2 KiB
TypeScript

import { createRequire } from "node:module";
declare const __OPENCLAW_VERSION__: string | undefined;
function readVersionFromPackageJson(): string | null {
try {
const require = createRequire(import.meta.url);
const pkg = require("../package.json") as { version?: string };
return pkg.version ?? null;
} catch {
return null;
}
}
function readVersionFromBuildInfo(): string | null {
try {
const require = createRequire(import.meta.url);
const candidates = ["../build-info.json", "./build-info.json"];
for (const candidate of candidates) {
try {
const info = require(candidate) as { version?: string };
if (info.version) {
return info.version;
}
} catch {
// ignore missing candidate
}
}
return null;
} catch {
return null;
}
}
// Single source of truth for the current OpenClaw version.
// - Embedded/bundled builds: injected define or env var.
// - Dev/npm builds: package.json.
export const VERSION =
(typeof __OPENCLAW_VERSION__ === "string" && __OPENCLAW_VERSION__) ||
process.env.OPENCLAW_BUNDLED_VERSION ||
readVersionFromPackageJson() ||
readVersionFromBuildInfo() ||
"0.0.0";