Skip to content

Commit 9e323b6

Browse files
committed
ps1
1 parent 6454475 commit 9e323b6

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bin/package-manager-completion.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
spawnSync,
33
type SpawnSyncOptionsWithStringEncoding,
44
} from 'child_process';
5+
import path from 'node:path';
56
import { RootCommand } from '../src/t.js';
67

78
const noop = () => {};
@@ -23,11 +24,20 @@ function runCompletionCommand(
2324
leadingArgs: string[],
2425
completionArgs: string[]
2526
): string {
26-
const result = spawnSync(
27-
command,
28-
[...leadingArgs, 'complete', '--', ...completionArgs],
29-
completionSpawnOptions
30-
);
27+
const args = [...leadingArgs, 'complete', '--', ...completionArgs];
28+
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);
36+
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);
40+
}
3141

3242
if (result.error) {
3343
throw result.error;

0 commit comments

Comments
 (0)