Skip to content

Commit a7251c8

Browse files
committed
Improve warning when additional PowerShell isn't found
Since we added logic which searches for possible intended permutations of the given additional PowerShell path, we needed to make the warning show only if none of the permutations were found. This was accomplished by suppressing it in the first iterator and then yielding it again after the permutations were exhausted with the warning unsuppressed.
1 parent 0b61253 commit a7251c8

File tree

2 files changed

+77
-8
lines changed

2 files changed

+77
-8
lines changed

src/platform.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,17 @@ export class PowerShellExeFinder {
239239
}
240240

241241
exePath = untildify(exePath);
242-
243-
// Always search for what the user gave us first
244-
yield new PossiblePowerShellExe(exePath, versionName);
245-
246-
// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
247242
const args: [string, undefined, boolean, boolean]
248243
// Must be a tuple type and is suppressing the warning
249244
= [versionName, undefined, true, true];
250245

251-
// Handle Windows where '.exe' and 'powershell' are things
246+
// Always search for what the user gave us first, but with the warning
247+
// suppressed so we can display it after all possibilities are exhausted
248+
yield new PossiblePowerShellExe(exePath, ...args);
249+
250+
// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
252251
if (this.platformDetails.operatingSystem === OperatingSystem.Windows) {
252+
// Handle Windows where '.exe' and 'powershell' are things
253253
if (!exePath.endsWith("pwsh.exe") && !exePath.endsWith("powershell.exe")) {
254254
if (exePath.endsWith("pwsh") || exePath.endsWith("powershell")) {
255255
// Add extension if that was missing
@@ -260,9 +260,13 @@ export class PowerShellExeFinder {
260260
yield new PossiblePowerShellExe(path.join(exePath, "pwsh.exe"), ...args);
261261
yield new PossiblePowerShellExe(path.join(exePath, "powershell.exe"), ...args);
262262
}
263-
} else if (!exePath.endsWith("pwsh")) { // Always just 'pwsh' on non-Windows
263+
} else if (!exePath.endsWith("pwsh")) {
264+
// Always just 'pwsh' on non-Windows
264265
yield new PossiblePowerShellExe(path.join(exePath, "pwsh"), ...args);
265266
}
267+
268+
// If we're still being iterated over, no permutation of the given path existed so yield an object with the warning unsuppressed
269+
yield new PossiblePowerShellExe(exePath, versionName, false, undefined, false);
266270
}
267271
}
268272
}

test/core/platform.test.ts

+66-1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ if (process.platform === "win32") {
469469
},
470470
environmentVars: {},
471471
expectedPowerShellSequence: [
472+
{
473+
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
474+
displayName: "pwsh",
475+
supportsProperArguments: true
476+
},
472477
{
473478
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
474479
displayName: "pwsh",
@@ -479,6 +484,11 @@ if (process.platform === "win32") {
479484
displayName: "pwsh-tilde",
480485
supportsProperArguments: true
481486
},
487+
{
488+
exePath: path.join(os.homedir(), "pwsh", "pwsh.exe"),
489+
displayName: "pwsh-tilde",
490+
supportsProperArguments: true
491+
},
482492
{
483493
exePath: "C:\\Users\\test\\pwsh\\pwsh",
484494
displayName: "pwsh-no-exe",
@@ -499,6 +509,11 @@ if (process.platform === "win32") {
499509
displayName: "pwsh-no-exe",
500510
supportsProperArguments: true
501511
},
512+
{
513+
exePath: "C:\\Users\\test\\pwsh\\pwsh",
514+
displayName: "pwsh-no-exe",
515+
supportsProperArguments: true
516+
},
502517
{
503518
exePath: "C:\\Users\\test\\pwsh\\",
504519
displayName: "pwsh-folder",
@@ -514,6 +529,11 @@ if (process.platform === "win32") {
514529
displayName: "pwsh-folder",
515530
supportsProperArguments: true
516531
},
532+
{
533+
exePath: "C:\\Users\\test\\pwsh\\",
534+
displayName: "pwsh-folder",
535+
supportsProperArguments: true
536+
},
517537
{
518538
exePath: "C:\\Users\\test\\pwsh",
519539
displayName: "pwsh-folder-no-slash",
@@ -534,6 +554,16 @@ if (process.platform === "win32") {
534554
displayName: "pwsh-folder-no-slash",
535555
supportsProperArguments: true
536556
},
557+
{
558+
exePath: "C:\\Users\\test\\pwsh",
559+
displayName: "pwsh-folder-no-slash",
560+
supportsProperArguments: true
561+
},
562+
{
563+
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
564+
displayName: "pwsh-single-quotes",
565+
supportsProperArguments: true
566+
},
537567
{
538568
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
539569
displayName: "pwsh-single-quotes",
@@ -544,6 +574,11 @@ if (process.platform === "win32") {
544574
displayName: "pwsh-double-quotes",
545575
supportsProperArguments: true
546576
},
577+
{
578+
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
579+
displayName: "pwsh-double-quotes",
580+
supportsProperArguments: true
581+
},
547582
],
548583
filesystem: {},
549584
}
@@ -760,7 +795,7 @@ if (process.platform === "win32") {
760795

761796
successAdditionalTestCases = [
762797
{ // Also sufficient for macOS as the behavior is the same
763-
name: "Linux (Additional PowerShell Executables)",
798+
name: "Linux/macOS (Additional PowerShell Executables)",
764799
platformDetails: {
765800
operatingSystem: platform.OperatingSystem.Linux,
766801
isOS64Bit: true,
@@ -773,6 +808,16 @@ if (process.platform === "win32") {
773808
displayName: "pwsh",
774809
supportsProperArguments: true
775810
},
811+
{
812+
exePath: "/home/bin/pwsh",
813+
displayName: "pwsh",
814+
supportsProperArguments: true
815+
},
816+
{
817+
exePath: path.join(os.homedir(), "bin", "pwsh"),
818+
displayName: "pwsh-tilde",
819+
supportsProperArguments: true
820+
},
776821
{
777822
exePath: path.join(os.homedir(), "bin", "pwsh"),
778823
displayName: "pwsh-tilde",
@@ -788,6 +833,11 @@ if (process.platform === "win32") {
788833
displayName: "pwsh-folder",
789834
supportsProperArguments: true
790835
},
836+
{
837+
exePath: "/home/bin/",
838+
displayName: "pwsh-folder",
839+
supportsProperArguments: true
840+
},
791841
{
792842
exePath: "/home/bin",
793843
displayName: "pwsh-folder-no-slash",
@@ -798,6 +848,16 @@ if (process.platform === "win32") {
798848
displayName: "pwsh-folder-no-slash",
799849
supportsProperArguments: true
800850
},
851+
{
852+
exePath: "/home/bin",
853+
displayName: "pwsh-folder-no-slash",
854+
supportsProperArguments: true
855+
},
856+
{
857+
exePath: "/home/bin/pwsh",
858+
displayName: "pwsh-single-quotes",
859+
supportsProperArguments: true
860+
},
801861
{
802862
exePath: "/home/bin/pwsh",
803863
displayName: "pwsh-single-quotes",
@@ -808,6 +868,11 @@ if (process.platform === "win32") {
808868
displayName: "pwsh-double-quotes",
809869
supportsProperArguments: true
810870
},
871+
{
872+
exePath: "/home/bin/pwsh",
873+
displayName: "pwsh-double-quotes",
874+
supportsProperArguments: true
875+
},
811876
],
812877
filesystem: {},
813878
}

0 commit comments

Comments
 (0)