Refactor CLI executions into helper functions

This provides a separation of concerns between the memoization and the execution.
This commit is contained in:
Mario Campos
2026-06-17 16:11:40 -05:00
parent 587fcb33c7
commit 889ae42672
+6 -3
View File
@@ -731,8 +731,7 @@ async function getCodeQLForCmd(
filterToLanguagesWithQueries: boolean;
} = { filterToLanguagesWithQueries: false },
) {
let result = util.getCachedCodeQlResolveLanguages(cmd);
if (result === undefined) {
async function runCliResolveLanguages() {
const codeqlArgs = [
"resolve",
"languages",
@@ -747,12 +746,16 @@ async function getCodeQLForCmd(
const output = await runCli(cmd, codeqlArgs);
try {
result = JSON.parse(output) as ResolveLanguagesOutput;
return JSON.parse(output) as ResolveLanguagesOutput;
} catch (e) {
throw new Error(
`Unexpected output from codeql resolve languages with --format=betterjson: ${e}`,
);
}
}
let result = util.getCachedCodeQlResolveLanguages(cmd);
if (result === undefined) {
result = await runCliResolveLanguages();
util.cacheCodeQlResolveLanguages(cmd, result);
}
return result;