fix(core): cache CLI version to ensure consistency during sessions (#18793)

This commit is contained in:
Sehoon Shon
2026-02-11 12:01:50 -05:00
committed by GitHub
parent f5dd1068f6
commit 34a47a51f4
3 changed files with 37 additions and 4 deletions

View File

@@ -11,7 +11,20 @@ import path from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export async function getVersion(): Promise<string> {
const pkgJson = await getPackageJson(__dirname);
return process.env['CLI_VERSION'] || pkgJson?.version || 'unknown';
let versionPromise: Promise<string> | undefined;
export function getVersion(): Promise<string> {
if (versionPromise) {
return versionPromise;
}
versionPromise = (async () => {
const pkgJson = await getPackageJson(__dirname);
return process.env['CLI_VERSION'] || pkgJson?.version || 'unknown';
})();
return versionPromise;
}
/** For testing purposes only */
export function resetVersionCache(): void {
versionPromise = undefined;
}