@@ -42,6 +42,7 @@ export interface IPlatformDetails {
42
42
operatingSystem : OperatingSystem ;
43
43
isOS64Bit : boolean ;
44
44
isProcess64Bit : boolean ;
45
+ isArm64 : boolean ;
45
46
}
46
47
47
48
export interface IPowerShellExeDetails {
@@ -68,6 +69,7 @@ export function getPlatformDetails(): IPlatformDetails {
68
69
isOS64Bit :
69
70
isProcess64Bit || process . env . PROCESSOR_ARCHITEW6432 !== undefined ,
70
71
isProcess64Bit,
72
+ isArm64 : process . arch === "arm64" ,
71
73
} ;
72
74
}
73
75
@@ -562,93 +564,96 @@ export class PowerShellExeFinder {
562
564
} : { useAlternateBitness ?: boolean ; findPreview ?: boolean } = { } ) : Promise <
563
565
IPossiblePowerShellExe | undefined
564
566
> {
565
- const programFilesPath = this . getProgramFilesPath ( {
567
+ for ( const programFilesPath of this . getProgramFilesPath ( {
566
568
useAlternateBitness,
567
- } ) ;
569
+ } ) ) {
568
570
569
- if ( ! programFilesPath ) {
570
- return undefined ;
571
- }
571
+ if ( ! programFilesPath ) {
572
+ continue ;
573
+ }
572
574
573
- const powerShellInstallBaseDir = path . join (
574
- programFilesPath ,
575
- "PowerShell" ,
576
- ) ;
575
+ const powerShellInstallBaseDir = path . join (
576
+ programFilesPath ,
577
+ "PowerShell" ,
578
+ ) ;
577
579
578
- // Ensure the base directory exists
579
- if ( ! ( await utils . checkIfDirectoryExists ( powerShellInstallBaseDir ) ) ) {
580
- return undefined ;
581
- }
580
+ // Ensure the base directory exists
581
+ if ( ! ( await utils . checkIfDirectoryExists ( powerShellInstallBaseDir ) ) ) {
582
+ continue ;
583
+ }
582
584
583
- let highestSeenVersion = - 1 ;
584
- let pwshExePath : string | undefined ;
585
- for ( const item of await utils . readDirectory (
586
- powerShellInstallBaseDir ,
587
- ) ) {
588
- let currentVersion = - 1 ;
589
- if ( findPreview ) {
590
- // We are looking for something like "7-preview"
591
-
592
- // Preview dirs all have dashes in them
593
- const dashIndex : integer = item . indexOf ( "-" ) ;
594
- if ( dashIndex < 0 ) {
595
- continue ;
596
- }
585
+ let highestSeenVersion = - 1 ;
586
+ let pwshExePath : string | undefined ;
587
+ for ( const item of await utils . readDirectory (
588
+ powerShellInstallBaseDir ,
589
+ ) ) {
590
+ let currentVersion = - 1 ;
591
+ if ( findPreview ) {
592
+ // We are looking for something like "7-preview"
593
+
594
+ // Preview dirs all have dashes in them
595
+ const dashIndex : integer = item . indexOf ( "-" ) ;
596
+ if ( dashIndex < 0 ) {
597
+ continue ;
598
+ }
597
599
598
- // Verify that the part before the dash is an integer
599
- const intPart : string = item . substring ( 0 , dashIndex ) ;
600
- if ( ! PowerShellExeFinder . IntRegex . test ( intPart ) ) {
601
- continue ;
600
+ // Verify that the part before the dash is an integer
601
+ const intPart : string = item . substring ( 0 , dashIndex ) ;
602
+ if ( ! PowerShellExeFinder . IntRegex . test ( intPart ) ) {
603
+ continue ;
604
+ }
605
+
606
+ // Verify that the part after the dash is "preview"
607
+ if ( item . substring ( dashIndex + 1 ) !== "preview" ) {
608
+ continue ;
609
+ }
610
+
611
+ currentVersion = parseInt ( intPart , 10 ) ;
612
+ } else {
613
+ // Search for a directory like "6" or "7"
614
+ if ( ! PowerShellExeFinder . IntRegex . test ( item ) ) {
615
+ continue ;
616
+ }
617
+
618
+ currentVersion = parseInt ( item , 10 ) ;
602
619
}
603
620
604
- // Verify that the part after the dash is "preview"
605
- if ( item . substring ( dashIndex + 1 ) !== "preview" ) {
621
+ // Ensure we haven't already seen a higher version
622
+ if ( currentVersion <= highestSeenVersion ) {
606
623
continue ;
607
624
}
608
625
609
- currentVersion = parseInt ( intPart , 10 ) ;
610
- } else {
611
- // Search for a directory like "6" or "7"
612
- if ( ! PowerShellExeFinder . IntRegex . test ( item ) ) {
626
+ // Now look for the file
627
+ const exePath = path . join (
628
+ powerShellInstallBaseDir ,
629
+ item ,
630
+ "pwsh.exe" ,
631
+ ) ;
632
+ if ( ! ( await utils . checkIfFileExists ( exePath ) ) ) {
613
633
continue ;
614
634
}
615
635
616
- currentVersion = parseInt ( item , 10 ) ;
636
+ pwshExePath = exePath ;
637
+ highestSeenVersion = currentVersion ;
617
638
}
618
639
619
- // Ensure we haven't already seen a higher version
620
- if ( currentVersion <= highestSeenVersion ) {
640
+ if ( ! pwshExePath ) {
621
641
continue ;
622
642
}
623
643
624
- // Now look for the file
625
- const exePath = path . join (
626
- powerShellInstallBaseDir ,
627
- item ,
628
- "pwsh.exe" ,
629
- ) ;
630
- if ( ! ( await utils . checkIfFileExists ( exePath ) ) ) {
631
- continue ;
632
- }
644
+ const bitness : string = programFilesPath . includes ( "x86" )
645
+ ? "(x86)"
646
+ : "(x64)" ;
633
647
634
- pwshExePath = exePath ;
635
- highestSeenVersion = currentVersion ;
636
- }
648
+ const preview : string = findPreview ? " Preview" : "" ;
637
649
638
- if ( ! pwshExePath ) {
639
- return undefined ;
650
+ return new PossiblePowerShellExe (
651
+ pwshExePath ,
652
+ `PowerShell${ preview } ${ bitness } ` ,
653
+ ) ;
640
654
}
641
655
642
- const bitness : string = programFilesPath . includes ( "x86" )
643
- ? "(x86)"
644
- : "(x64)" ;
645
-
646
- const preview : string = findPreview ? " Preview" : "" ;
647
-
648
- return new PossiblePowerShellExe (
649
- pwshExePath ,
650
- `PowerShell${ preview } ${ bitness } ` ,
651
- ) ;
656
+ return undefined ;
652
657
}
653
658
654
659
private findWinPS ( {
@@ -707,24 +712,29 @@ export class PowerShellExeFinder {
707
712
708
713
private getProgramFilesPath ( {
709
714
useAlternateBitness = false ,
710
- } : { useAlternateBitness ?: boolean } = { } ) : string | undefined {
715
+ } : { useAlternateBitness ?: boolean } = { } ) : ( string | undefined ) [ ] {
716
+ const result : ( string | undefined ) [ ] = [ ] ;
717
+
711
718
if ( ! useAlternateBitness ) {
712
719
// Just use the native system bitness
713
- return process . env . ProgramFiles ;
714
- }
720
+ result . push ( process . env . ProgramFiles ) ;
715
721
716
- // We might be a 64-bit process looking for 32-bit program files
717
- if ( this . platformDetails . isProcess64Bit ) {
718
- return process . env [ "ProgramFiles(x86)" ] ;
719
- }
722
+ // We might be a Arm64 process looking for Arm program files
723
+ if ( this . platformDetails . isArm64 ) {
724
+ result . push ( process . env [ "ProgramFiles(Arm)" ] ) ;
725
+ }
726
+ } else {
727
+ // We might be a 64-bit process looking for 32-bit program files
728
+ if ( this . platformDetails . isProcess64Bit ) {
729
+ result . push ( process . env [ "ProgramFiles(x86)" ] ) ;
730
+ }
720
731
721
- // We might be a 32-bit process looking for 64-bit program files
722
- if ( this . platformDetails . isOS64Bit ) {
723
- return process . env . ProgramW6432 ;
732
+ // We might be a 32-bit process looking for 64-bit program files
733
+ if ( this . platformDetails . isOS64Bit ) {
734
+ result . push ( process . env . ProgramW6432 ) ;
735
+ }
724
736
}
725
-
726
- // We're a 32-bit process on 32-bit Windows, there is no other Program Files dir
727
- return undefined ;
737
+ return result ;
728
738
}
729
739
730
740
private getSystem32Path ( {
0 commit comments