Change OutputCache to use object for entries

This will ensure it works nicely with `JSON.stringify`. And, then we can validate the type before marshaling.
This commit is contained in:
Mario Campos
2026-08-12 12:01:20 -05:00
parent bf96b0df93
commit 6c0d9018d4
2 changed files with 13 additions and 3 deletions

6
lib/entry-points.js generated
View File

@@ -146256,9 +146256,13 @@ function cacheCodeQlVersion(cmd, version, env) {
throw new Error("cacheCodeQlVersion() should be called only once");
}
cachedCodeQlVersion = version;
const outputCache = {
cmd,
entries: { ["version" /* Version */]: version }
};
fs3.writeFileSync(
getCommandCacheFilePath(env),
JSON.stringify({ cmd, entries: { ["version" /* Version */]: version } }),
JSON.stringify(outputCache),
"utf8"
);
}

View File

@@ -25,7 +25,9 @@ export type CommandCacheKeyOutputMap = {
*/
export interface OutputCache<K extends CommandCacheKey> {
cmd: string;
entries: Map<K, CommandCacheKeyOutputMap[K]>;
entries: {
[P in K]: CommandCacheKeyOutputMap[K];
};
}
/**
@@ -70,13 +72,17 @@ export function cacheCodeQlVersion(
throw new Error("cacheCodeQlVersion() should be called only once");
}
cachedCodeQlVersion = version;
const outputCache = {
cmd,
entries: { [CommandCacheKey.Version]: version },
} satisfies OutputCache<CommandCacheKey.Version>;
// Persist the version so that subsequent Actions steps, which run in separate
// processes, can reuse it rather than invoking `codeql version` again. We
// record the CLI path so that a different step using a different CodeQL bundle
// doesn't pick up a stale version.
fs.writeFileSync(
getCommandCacheFilePath(env),
JSON.stringify({ cmd, entries: { [CommandCacheKey.Version]: version } }),
JSON.stringify(outputCache),
"utf8",
);
}