@@ -4,32 +4,32 @@ import { DefaultLinuxVersion, DefaultVersions } from "./default_versions"
4
4
5
5
/** Get the default version if passed true or undefined, otherwise return the version itself */
6
6
export 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 ""
15
14
}
15
+ return version ?? ""
16
+ }
17
+
18
+ function isVersionDefault ( version : string | undefined ) {
19
+ return version === "true" || version === undefined
16
20
}
17
21
18
22
/// 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 > ) {
20
24
const osVersionMaj = osVersion [ 0 ]
21
25
22
26
// find which version block the os version is in
23
- const satisfyingVersion = Object . keys ( DefaultLinuxVersion [ name ] )
27
+ const satisfyingVersion = Object . keys ( toolLinuxVersions )
24
28
. map ( ( v ) => parseInt ( v , 10 ) )
25
29
. sort ( ( a , b ) => b - a ) // sort in descending order
26
30
. find ( ( v ) => osVersionMaj >= v )
27
31
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 ]
33
33
}
34
34
35
35
/**
@@ -39,7 +39,7 @@ function isDefault(version: string | undefined, name: string) {
39
39
*/
40
40
export function syncVersions ( opts : Opts , tools : Inputs [ ] ) : boolean {
41
41
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 ] ) )
43
43
44
44
const targetVersion = toolsNonDefaultVersion . length >= 1 ? opts [ toolsNonDefaultVersion [ 0 ] ] : "true"
45
45
0 commit comments