|
2 | 2 | spawnSync, |
3 | 3 | type SpawnSyncOptionsWithStringEncoding, |
4 | 4 | } from 'child_process'; |
5 | | -import fs from 'node:fs'; |
6 | 5 | import path from 'node:path'; |
7 | 6 | import { RootCommand } from '../src/t.js'; |
8 | 7 |
|
@@ -30,26 +29,12 @@ function runCompletionCommand( |
30 | 29 | ): string { |
31 | 30 | const args = [...leadingArgs, 'complete', '--', ...completionArgs]; |
32 | 31 |
|
33 | | - // In a PowerShell host, go through powershell.exe so .ps1 shims work. |
34 | | - if (isPowerShellEnv) { |
35 | | - if (process.env.TAB_DEBUG) { |
36 | | - console.error('[DEBUG] runCompletionCommand via powershell:', { |
37 | | - command, |
38 | | - args, |
39 | | - }); |
40 | | - } |
| 32 | + // PowerShell: prefer invoking via powershell.exe so .ps1 shims are resolved. |
| 33 | + if (isPowerShellEnv && path.extname(command) === '') { |
41 | 34 | return runCompletionViaPowerShell(command, args); |
42 | 35 | } |
43 | 36 |
|
44 | | - const targetCommand = preferCmdShim(command); |
45 | | - if (process.env.TAB_DEBUG) { |
46 | | - console.error('[DEBUG] runCompletionCommand via cmd path:', { |
47 | | - command, |
48 | | - targetCommand, |
49 | | - args, |
50 | | - }); |
51 | | - } |
52 | | - const result = spawnSync(targetCommand, args, completionSpawnOptions); |
| 37 | + const result = spawnSync(command, args, completionSpawnOptions); |
53 | 38 |
|
54 | 39 | return (result.stdout ?? '').trim(); |
55 | 40 | } |
@@ -173,17 +158,3 @@ export class PackageManagerCompletion extends RootCommand { |
173 | 158 | return super.parse(args); |
174 | 159 | } |
175 | 160 | } |
176 | | - |
177 | | -function preferCmdShim(command: string): string { |
178 | | - if (process.platform !== 'win32') return command; |
179 | | - if (path.extname(command) !== '') return command; |
180 | | - |
181 | | - const pathEntries = (process.env.PATH || '').split(path.delimiter); |
182 | | - for (const entry of pathEntries) { |
183 | | - const candidate = path.join(entry, `${command}.cmd`); |
184 | | - if (fs.existsSync(candidate)) { |
185 | | - return `${command}.cmd`; |
186 | | - } |
187 | | - } |
188 | | - return command; |
189 | | -} |
0 commit comments