11import * as os from 'os'
2- import * as s from 'semver'
2+ import * as semver from 'semver'
33import { SemVer } from 'semver'
44import { OutputChannel , extensions , version } from 'vscode'
55import { ExecutionExitCode , ExecutionResult , batchExecute } from '../utils/batch'
@@ -8,10 +8,11 @@ import {
88 ElanDumpStateWithoutNetResult ,
99 elanDumpStateWithNet ,
1010 elanDumpStateWithoutNet ,
11+ elanVersionRegex ,
1112 isElanEagerResolutionVersion ,
1213} from '../utils/elan'
1314import { FileUri } from '../utils/exturi'
14- import { ToolchainUpdateMode , leanRunner } from '../utils/leanCmdRunner'
15+ import { ToolchainUpdateMode , leanRunner , leanVersionRegex } from '../utils/leanCmdRunner'
1516import { checkParentFoldersForLeanProject , isValidLeanProject } from '../utils/projectInfo'
1617
1718const minimumSupportedMacOSVersion = new SemVer ( '19.0.0' )
@@ -23,11 +24,10 @@ export type OSVersionDiagnosis =
2324
2425function diagnoseOSVersion ( ) : OSVersionDiagnosis {
2526 // When in doubt, we consider an OS version as not being unsupported.
26- const release = os . release ( )
27- if ( ! s . valid ( release ) ) {
27+ const currentVersion = semver . parse ( os . release ( ) )
28+ if ( currentVersion === null ) {
2829 return { kind : 'NotUnsupported' }
2930 }
30- const currentVersion = new SemVer ( release )
3131 switch ( os . type ( ) ) {
3232 case 'Darwin' :
3333 if ( currentVersion . compare ( minimumSupportedMacOSVersion ) >= 0 ) {
@@ -114,7 +114,12 @@ export function versionQueryResult(executionResult: ExecutionResult, versionRege
114114 return { kind : 'InvalidVersion' , versionResult : executionResult . stdout }
115115 }
116116
117- return { kind : 'Success' , version : new SemVer ( match [ 1 ] ) }
117+ const parsed = semver . parse ( match [ 1 ] )
118+ if ( parsed === null ) {
119+ return { kind : 'InvalidVersion' , versionResult : executionResult . stdout }
120+ }
121+
122+ return { kind : 'Success' , version : parsed }
118123}
119124
120125export function checkElanVersion ( elanVersionResult : VersionQueryResult ) : ElanVersionDiagnosis {
@@ -313,12 +318,12 @@ export class SetupDiagnoser {
313318
314319 async queryLeanVersion ( ) : Promise < VersionQueryResult > {
315320 const leanVersionResult = await this . runLeanCommand ( 'lean' , [ '--version' ] , 'Checking Lean version' )
316- return versionQueryResult ( leanVersionResult , / v e r s i o n ( \d + \. \d + \. \d + ( \w | - ) * ) / )
321+ return versionQueryResult ( leanVersionResult , leanVersionRegex )
317322 }
318323
319324 async queryElanVersion ( ) : Promise < VersionQueryResult > {
320325 const elanVersionResult = await this . runSilently ( 'elan' , [ '--version' ] )
321- return versionQueryResult ( elanVersionResult , / e l a n ( \d + \. \d + \. \d + ) / )
326+ return versionQueryResult ( elanVersionResult , elanVersionRegex )
322327 }
323328
324329 async queryElanShow ( ) : Promise < ExecutionResult > {
0 commit comments