Skip to content

Commit f172092

Browse files
Teach client to find Homebrew installations on Apple Silicon (PowerShell#5164)
Since `/opt/homebrew` is now used instead of `/usr/local`.
1 parent ea22697 commit f172092

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/platform.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const SnapPreviewExePath = "/snap/bin/pwsh-preview";
2626
const MacOSExePath = "/usr/local/bin/pwsh";
2727
const 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+
2933
export 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
}

test/core/platform.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,26 @@ if (process.platform === "win32") {
595595
displayName: "PowerShell",
596596
supportsProperArguments: true
597597
},
598+
{
599+
exePath: "/opt/homebrew/bin/pwsh",
600+
displayName: "PowerShell (Homebrew)",
601+
supportsProperArguments: true
602+
},
603+
{
604+
exePath: "/opt/homebrew/bin/pwsh-lts",
605+
displayName: "PowerShell LTS (Homebrew)",
606+
supportsProperArguments: true
607+
},
598608
{
599609
exePath: "/usr/local/bin/pwsh-preview",
600610
displayName: "PowerShell Preview",
601611
supportsProperArguments: true
602612
},
613+
{
614+
exePath: "/opt/homebrew/bin/pwsh-preview",
615+
displayName: "PowerShell Preview (Homebrew)",
616+
supportsProperArguments: true
617+
},
603618
{
604619
exePath: path.join(pwshDailyDir, "pwsh"),
605620
displayName: "PowerShell Daily",
@@ -611,6 +626,11 @@ if (process.platform === "win32") {
611626
"pwsh": "",
612627
"pwsh-preview": "",
613628
},
629+
"/opt/homebrew/bin/": {
630+
"pwsh": "",
631+
"pwsh-lts": "",
632+
"pwsh-preview": "",
633+
},
614634
[pwshDailyDir]: {
615635
"pwsh": ""
616636
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy