@@ -4,32 +4,32 @@ import { DefaultLinuxVersion, DefaultVersions } from "./default_versions"
44
55/** Get the default version if passed true or undefined, otherwise return the version itself */
66export function getVersion ( name : string , version : string | undefined , osVersion : number [ ] | null = null ) {
7- if ( isDefault ( version , name ) ) {
8- if ( process . platform === "linux" && osVersion !== null ) {
9- return getDefaultLinuxVersion ( name , osVersion )
10- }
11- // anything else
12- return DefaultVersions [ name ] ! // checked by isDefault
13- } else {
14- return version ?? ""
7+ console . log ( "isDefault" , version , name , isVersionDefault ( version ) )
8+ if ( isVersionDefault ( version ) && process . platform === "linux" && osVersion !== null && name in DefaultLinuxVersion ) {
9+ return getDefaultLinuxVersion ( osVersion , DefaultLinuxVersion [ name ] ! )
10+ } else if ( isVersionDefault ( version ) && name in DefaultVersions ) {
11+ return DefaultVersions [ name ] !
12+ } else if ( version === "true" ) {
13+ return ""
1514 }
15+ return version ?? ""
16+ }
17+
18+ function isVersionDefault ( version : string | undefined ) {
19+ return version === "true" || version === undefined
1620}
1721
1822/// choose the default linux version based on ubuntu version
19- function getDefaultLinuxVersion ( name : string , osVersion : number [ ] ) {
23+ function getDefaultLinuxVersion ( osVersion : number [ ] , toolLinuxVersions : Record < number , string > ) {
2024 const osVersionMaj = osVersion [ 0 ]
2125
2226 // find which version block the os version is in
23- const satisfyingVersion = Object . keys ( DefaultLinuxVersion [ name ] )
27+ const satisfyingVersion = Object . keys ( toolLinuxVersions )
2428 . map ( ( v ) => parseInt ( v , 10 ) )
2529 . sort ( ( a , b ) => b - a ) // sort in descending order
2630 . find ( ( v ) => osVersionMaj >= v )
2731
28- return satisfyingVersion === undefined ? "" : DefaultLinuxVersion [ name ] [ satisfyingVersion ]
29- }
30-
31- function isDefault ( version : string | undefined , name : string ) {
32- return ( version === "true" || version === undefined ) && name in DefaultLinuxVersion
32+ return satisfyingVersion === undefined ? "" : toolLinuxVersions [ satisfyingVersion ]
3333}
3434
3535/**
@@ -39,7 +39,7 @@ function isDefault(version: string | undefined, name: string) {
3939 */
4040export function syncVersions ( opts : Opts , tools : Inputs [ ] ) : boolean {
4141 const toolsInUse = tools . filter ( ( tool ) => opts [ tool ] !== undefined )
42- const toolsNonDefaultVersion = toolsInUse . filter ( ( tool ) => ! isDefault ( opts [ tool ] , tool ) )
42+ const toolsNonDefaultVersion = toolsInUse . filter ( ( tool ) => ! isVersionDefault ( opts [ tool ] ) )
4343
4444 const targetVersion = toolsNonDefaultVersion . length >= 1 ? opts [ toolsNonDefaultVersion [ 0 ] ] : "true"
4545
0 commit comments