Refactor resolveLanguages() to cache output according to CLI feature support

The output of `resolveLanguages()` can vary based on whether the flag `--filter-to-languages-with-queries` is included, but not all versions of the CLI support that. This makes caching a single execution problematic, so I opted to cache it based on whether it's supported. If it's supported, it's used; otherwise, it's not.
This commit is contained in:
Mario Campos
2026-06-18 14:42:03 -05:00
parent 553eef0d3f
commit c8e32e423d
4 changed files with 41 additions and 41 deletions

View File

@@ -126,9 +126,7 @@ export interface CodeQL {
/**
* Run 'codeql resolve languages' with '--format=betterjson'.
*/
resolveLanguages(options?: {
filterToLanguagesWithQueries: boolean;
}): Promise<ResolveLanguagesOutput>;
resolveLanguages(): Promise<ResolveLanguagesOutput>;
/**
* Run 'codeql resolve build-environment'
*/
@@ -784,28 +782,30 @@ async function getCodeQLForCmd(
];
await runCli(cmd, args);
},
async resolveLanguages(
{
filterToLanguagesWithQueries,
}: {
filterToLanguagesWithQueries: boolean;
} = { filterToLanguagesWithQueries: false },
) {
async resolveLanguages() {
return getCachedOrRun(
CommandCacheKey.ResolveLanguages,
cmd,
() =>
runCliJson<ResolveLanguagesOutput>(cmd, [
async () => {
const isFilterToLanguagesWithQueriesSupported =
await this.supportsFeature(
ToolsFeature.BuiltinExtractorsSpecifyDefaultQueries,
);
return runCliJson<ResolveLanguagesOutput>(cmd, [
"resolve",
"languages",
"--format=betterjson",
"--extractor-options-verbosity=4",
"--extractor-include-aliases",
...(filterToLanguagesWithQueries
// TODO: Unconditionally include `--filter-to-languages-with-queries`
// once CODEQL_MINIMUM_VERSION is at least v2.23.0
// — the first version to support this flag.
...(isFilterToLanguagesWithQueriesSupported
? ["--filter-to-languages-with-queries"]
: []),
...getExtraOptionsFromEnv(["resolve", "languages"]),
]),
]);
},
isResolveLanguagesOutput,
);
},