versionSolana.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { hasCommand, spawnCommand } from './commands';
  2. import { Language } from './localization';
  3. import {
  4. assertIsValidVersion,
  5. getVersionAndVersionWithoutPatch,
  6. getVersionFromStdout,
  7. ResolvedVersion,
  8. Version,
  9. } from './versionCore';
  10. export async function detectSolanaVersion(
  11. language: Language
  12. ): Promise<Version> {
  13. const hasSolanaCli = await hasCommand('solana');
  14. if (!hasSolanaCli) {
  15. throw new Error(
  16. language.errors.solanaCliNotFound.replace('$command', 'solana')
  17. );
  18. }
  19. return getVersionFromStdout(spawnCommand('solana', ['--version']));
  20. }
  21. export function resolveSolanaVersion(
  22. language: Language,
  23. inputVersion: string | undefined,
  24. detectedVersion: Version
  25. ): ResolvedVersion {
  26. const version = inputVersion ?? detectedVersion ?? '';
  27. assertIsValidVersion(language, 'Solana', version);
  28. const [full, withoutPatch] = getVersionAndVersionWithoutPatch(version, {
  29. '1.17': '1.17.34',
  30. '1.18': '1.18.18',
  31. '2.1': '2.1.16',
  32. });
  33. return { full, withoutPatch, detected: detectedVersion };
  34. }