@@ -540,20 +540,24 @@ export function findHomeDir(): string | null {
540
540
}
541
541
return null ;
542
542
}
543
+ // $HOME is always favored, but the k8s go-client prefers the other two env vars
544
+ // differently depending on whether .kube/config exists or not.
543
545
const homeDrivePath = process . env . HOMEDRIVE && process . env . HOMEPATH ?
544
546
path . join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) : null ;
545
- const dirList1 : string [ ] = dropDuplicatesAndNils ( [ process . env . HOME , homeDrivePath , process . env . USERPROFILE ] ) ;
546
- const dirList2 : string [ ] = dropDuplicatesAndNils ( [ process . env . HOME , process . env . USERPROFILE , homeDrivePath ] ) ;
547
+ const favourHomeDrivePathList : string [ ] =
548
+ dropDuplicatesAndNils ( [ process . env . HOME , homeDrivePath , process . env . USERPROFILE ] ) ;
549
+ const favourUserProfileList : string [ ] =
550
+ dropDuplicatesAndNils ( [ process . env . HOME , process . env . USERPROFILE , homeDrivePath ] ) ;
547
551
// 1. the first of %HOME%, %HOMEDRIVE%%HOMEPATH%, %USERPROFILE% containing a `.kube\config` file is returned.
548
- for ( const dir of dirList1 ) {
552
+ for ( const dir of favourHomeDrivePathList ) {
549
553
try {
550
554
fs . accessSync ( path . join ( dir , '.kube' , 'config' ) ) ;
551
555
return dir ;
552
556
// tslint:disable-next-line:no-empty
553
557
} catch ( ignore ) { }
554
558
}
555
559
// 2. ...the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that exists and is writeable is returned
556
- for ( const dir of dirList2 ) {
560
+ for ( const dir of favourUserProfileList ) {
557
561
try {
558
562
const lstat = fs . lstatSync ( dir ) ;
559
563
// tslint:disable-next-line:no-bitwise
@@ -564,7 +568,7 @@ export function findHomeDir(): string | null {
564
568
} catch ( ignore ) { }
565
569
}
566
570
// 3. ...the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that exists is returned.
567
- for ( const dir of dirList2 ) {
571
+ for ( const dir of favourUserProfileList ) {
568
572
try {
569
573
fs . accessSync ( dir ) ;
570
574
return dir ;
@@ -573,7 +577,7 @@ export function findHomeDir(): string | null {
573
577
}
574
578
// 4. if none of those locations exists, the first of
575
579
// %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that is set is returned.
576
- return dirList2 [ 0 ] || null ;
580
+ return favourUserProfileList [ 0 ] || null ;
577
581
}
578
582
579
583
export interface Named {
0 commit comments