Skip to content

Commit 0a99875

Browse files
committed
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.
1 parent 246018e commit 0a99875

3 files changed

Lines changed: 48 additions & 42 deletions

File tree

lib/entry-points.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/output-cache.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import path from "path";
33

44
import { getTemporaryDirectory } from "../actions-util";
55
import { Env, getEnv } from "../environment";
6-
import { isPersistedVersionInfo } from "../util";
76

87
import type { VersionInfo } from "./types";
98

9+
/** The persisted version together with the CLI path it was obtained from. */
10+
interface PersistedVersionInfo {
11+
cmd: string;
12+
version: VersionInfo;
13+
}
14+
1015
/**
1116
* The name of the temporary file that backs the on-disk cache of
1217
* CLI responses between workflow steps.
@@ -99,3 +104,35 @@ export function getCachedCodeQlVersion(
99104
cachedCodeQlVersion = persisted.version;
100105
return cachedCodeQlVersion;
101106
}
107+
108+
/**
109+
* Determines whether a value is a `VersionInfo` object.
110+
* @param x The value to test
111+
*/
112+
function isVersionInfo(x: unknown): x is VersionInfo {
113+
const candidate = x as Partial<VersionInfo> | null;
114+
return (
115+
typeof candidate === "object" &&
116+
candidate !== null &&
117+
typeof candidate.version === "string" &&
118+
(candidate.features === undefined ||
119+
(typeof candidate.features === "object" &&
120+
candidate.features !== null)) &&
121+
(candidate.overlayVersion === undefined ||
122+
typeof candidate.overlayVersion === "number")
123+
);
124+
}
125+
126+
/**
127+
* Determines whether a value is a `PersistedVersionInfo` object.
128+
* @param x The value to test
129+
*/
130+
function isPersistedVersionInfo(x: unknown): x is PersistedVersionInfo {
131+
const candidate = x as Partial<PersistedVersionInfo> | null;
132+
return (
133+
typeof candidate === "object" &&
134+
candidate !== null &&
135+
typeof candidate.cmd === "string" &&
136+
isVersionInfo(candidate.version)
137+
);
138+
}

src/util.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as yaml from "js-yaml";
1010
import * as semver from "semver";
1111

1212
import * as apiCompatibility from "./api-compatibility.json";
13-
import type { VersionInfo } from "./cli/types";
1413
import type { CodeQL } from "./codeql";
1514
import type { Pack } from "./config/db-config";
1615
import type { Config } from "./config-utils";
@@ -599,36 +598,6 @@ export function asHTTPError(arg: any): HTTPError | undefined {
599598
return undefined;
600599
}
601600

602-
/** The persisted version together with the CLI path it was obtained from. */
603-
interface PersistedVersionInfo {
604-
cmd: string;
605-
version: VersionInfo;
606-
}
607-
608-
function isVersionInfo(x: unknown): x is VersionInfo {
609-
const candidate = x as Partial<VersionInfo> | null;
610-
return (
611-
typeof candidate === "object" &&
612-
candidate !== null &&
613-
typeof candidate.version === "string" &&
614-
(candidate.features === undefined ||
615-
(typeof candidate.features === "object" &&
616-
candidate.features !== null)) &&
617-
(candidate.overlayVersion === undefined ||
618-
typeof candidate.overlayVersion === "number")
619-
);
620-
}
621-
622-
export function isPersistedVersionInfo(x: unknown): x is PersistedVersionInfo {
623-
const candidate = x as Partial<PersistedVersionInfo> | null;
624-
return (
625-
typeof candidate === "object" &&
626-
candidate !== null &&
627-
typeof candidate.cmd === "string" &&
628-
isVersionInfo(candidate.version)
629-
);
630-
}
631-
632601
export async function codeQlVersionAtLeast(
633602
codeql: CodeQL,
634603
requiredVersion: string,

0 commit comments

Comments
 (0)