Move VersionInfo-related types to cli/output-cache.ts

This brings them out of the crowded all-purpose `util.ts` and into `cli/output-cache.ts` where they are exclusively used.
This commit is contained in:
Mario Campos
2026-08-11 15:35:03 -05:00
parent 246018e041
commit 0a99875ae5
3 changed files with 48 additions and 42 deletions

View File

@@ -3,10 +3,15 @@ import path from "path";
import { getTemporaryDirectory } from "../actions-util";
import { Env, getEnv } from "../environment";
import { isPersistedVersionInfo } from "../util";
import type { VersionInfo } from "./types";
/** The persisted version together with the CLI path it was obtained from. */
interface PersistedVersionInfo {
cmd: string;
version: VersionInfo;
}
/**
* The name of the temporary file that backs the on-disk cache of
* CLI responses between workflow steps.
@@ -99,3 +104,35 @@ export function getCachedCodeQlVersion(
cachedCodeQlVersion = persisted.version;
return cachedCodeQlVersion;
}
/**
* Determines whether a value is a `VersionInfo` object.
* @param x The value to test
*/
function isVersionInfo(x: unknown): x is VersionInfo {
const candidate = x as Partial<VersionInfo> | null;
return (
typeof candidate === "object" &&
candidate !== null &&
typeof candidate.version === "string" &&
(candidate.features === undefined ||
(typeof candidate.features === "object" &&
candidate.features !== null)) &&
(candidate.overlayVersion === undefined ||
typeof candidate.overlayVersion === "number")
);
}
/**
* Determines whether a value is a `PersistedVersionInfo` object.
* @param x The value to test
*/
function isPersistedVersionInfo(x: unknown): x is PersistedVersionInfo {
const candidate = x as Partial<PersistedVersionInfo> | null;
return (
typeof candidate === "object" &&
candidate !== null &&
typeof candidate.cmd === "string" &&
isVersionInfo(candidate.version)
);
}