@@ -26,6 +26,10 @@ const SnapPreviewExePath = "/snap/bin/pwsh-preview";
2626const MacOSExePath = "/usr/local/bin/pwsh" ;
2727const MacOSPreviewExePath = "/usr/local/bin/pwsh-preview" ;
2828
29+ const MacOSHomebrewExePath = "/opt/homebrew/bin/pwsh" ;
30+ const MacOSHomebrewLTSExePath = "/opt/homebrew/bin/pwsh-lts" ;
31+ const MacOSHomebrewPreviewExePath = "/opt/homebrew/bin/pwsh-preview" ;
32+
2933export enum OperatingSystem {
3034 Unknown ,
3135 Windows ,
@@ -169,6 +173,7 @@ export class PowerShellExeFinder {
169173 * Iterates through all the possible well-known PowerShell installations on a machine.
170174 * Returned values may not exist, but come with an .exists property
171175 * which will check whether the executable exists.
176+ * TODO: We really need to define the order in which we search for stable/LTS/preview/daily
172177 */
173178 private async * enumerateDefaultPowerShellInstallations ( ) : AsyncIterable < IPossiblePowerShellExe | undefined > {
174179 // Find PSCore stable first
@@ -183,10 +188,14 @@ export class PowerShellExeFinder {
183188 case OperatingSystem . Windows :
184189 // Windows may have a 32-bit pwsh.exe
185190 yield this . findPSCoreWindowsInstallation ( { useAlternateBitness : true } ) ;
186-
187191 // Also look for the MSIX/UWP installation
188192 yield await this . findPSCoreMsix ( ) ;
193+ break ;
189194
195+ case OperatingSystem . MacOS :
196+ // On MacOS, find the Homebrew installations
197+ yield this . findPSCoreHomebrewStable ( ) ;
198+ yield this . findPSCoreHomebrewLTS ( ) ;
190199 break ;
191200 }
192201
@@ -220,6 +229,11 @@ export class PowerShellExeFinder {
220229 yield this . findWinPS ( { useAlternateBitness : true } ) ;
221230
222231 break ;
232+
233+ case OperatingSystem . MacOS :
234+ // On MacOS, find the Homebrew preview
235+ yield this . findPSCoreHomebrewPreview ( ) ;
236+ break ;
223237 }
224238
225239 // Look for PSCore daily
@@ -336,6 +350,8 @@ export class PowerShellExeFinder {
336350 * if ($Daily) {
337351 * $Destination = "${Destination}-daily"
338352 * }
353+ *
354+ * TODO: Remove this after the daily is officially no longer supported.
339355 */
340356 private findPSCoreDaily ( ) : IPossiblePowerShellExe | undefined {
341357 switch ( this . platformDetails . operatingSystem ) {
@@ -359,6 +375,19 @@ export class PowerShellExeFinder {
359375 }
360376 }
361377
378+ // The Homebrew installations of PowerShell on Apple Silicon are no longer in the default PATH.
379+ private findPSCoreHomebrewStable ( ) : IPossiblePowerShellExe {
380+ return new PossiblePowerShellExe ( MacOSHomebrewExePath , "PowerShell (Homebrew)" ) ;
381+ }
382+
383+ private findPSCoreHomebrewLTS ( ) : IPossiblePowerShellExe {
384+ return new PossiblePowerShellExe ( MacOSHomebrewLTSExePath , "PowerShell LTS (Homebrew)" ) ;
385+ }
386+
387+ private findPSCoreHomebrewPreview ( ) : IPossiblePowerShellExe {
388+ return new PossiblePowerShellExe ( MacOSHomebrewPreviewExePath , "PowerShell Preview (Homebrew)" ) ;
389+ }
390+
362391 private findPSCoreDotnetGlobalTool ( ) : IPossiblePowerShellExe {
363392 const exeName : string = this . platformDetails . operatingSystem === OperatingSystem . Windows
364393 ? "pwsh.exe"
@@ -398,6 +427,7 @@ export class PowerShellExeFinder {
398427 return undefined ;
399428 }
400429
430+ // TODO: Are snaps still a thing?
401431 private findPSCoreStableSnap ( ) : IPossiblePowerShellExe {
402432 return new PossiblePowerShellExe ( SnapExePath , "PowerShell Snap" ) ;
403433 }
0 commit comments