Skip to content

Commit 66faa7f

Browse files
committed
ps1
1 parent 9e323b6 commit 66faa7f

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

bin/package-manager-completion.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,34 @@ function runCompletionCommand(
2626
): string {
2727
const args = [...leadingArgs, 'complete', '--', ...completionArgs];
2828

29-
// On Windows, prefer invoking the PowerShell shim (.ps1) so global installs work.
30-
const maybePs1Command =
31-
process.platform === 'win32' && path.extname(command) === ''
32-
? `${command}.ps1`
33-
: command;
34-
35-
let result = spawnSync(maybePs1Command, args, completionSpawnOptions);
29+
// On Windows, prefer invoking via powershell.exe so .ps1 shims work.
30+
if (process.platform === 'win32' && path.extname(command) === '') {
31+
const ps1Path = `${command}.ps1`;
32+
const psResult = spawnSync(
33+
'powershell.exe',
34+
[
35+
'-NoLogo',
36+
'-NoProfile',
37+
'-ExecutionPolicy',
38+
'Bypass',
39+
'-File',
40+
ps1Path,
41+
...args,
42+
],
43+
completionSpawnOptions
44+
);
3645

37-
// If the .ps1 shim is not found, fall back to the original command.
38-
if (result.error && maybePs1Command !== command) {
39-
result = spawnSync(command, args, completionSpawnOptions);
46+
// If that fails, fall back to invoking the command directly.
47+
if (
48+
!psResult.error &&
49+
(typeof psResult.status !== 'number' || psResult.status === 0)
50+
) {
51+
return (psResult.stdout ?? '').trim();
52+
}
4053
}
4154

55+
const result = spawnSync(command, args, completionSpawnOptions);
56+
4257
if (result.error) {
4358
throw result.error;
4459
}

0 commit comments

Comments
 (0)