@@ -9,9 +9,10 @@ const shells = ['zsh', 'bash', 'fish', 'powershell'];
99
1010async function main ( ) {
1111 const args = process . argv . slice ( 2 ) ;
12+ const isPowerShell = process . platform === 'win32' && process . env . PSModulePath ;
1213
1314 if ( process . env . TAB_DEBUG ) {
14- console . error ( " RAW ARGS:" , process . argv ) ;
15+ console . error ( ' RAW ARGS:' , process . argv ) ;
1516 }
1617
1718 // <packageManager> complete -- <args>
@@ -27,28 +28,24 @@ async function main() {
2728 }
2829
2930 const dashIndex = process . argv . indexOf ( '--' ) ;
30- if ( dashIndex !== - 1 ) {
31- const completion = new PackageManagerCompletion ( packageManager ) ;
32- await setupCompletionForPackageManager ( packageManager , completion ) ;
33- const toComplete = process . argv . slice ( dashIndex + 1 ) ;
34- await completion . parse ( toComplete ) ;
35- process . exit ( 0 ) ;
36- } else {
37- // Handle PowerShell case where trailing '--' gets stripped by npm.cmd
38- // In PowerShell, args after 'complete' should be treated as completion args
39- const isPowerShell = process . platform === 'win32' && process . env . PSModulePath ;
40- if ( isPowerShell ) {
41- const completion = new PackageManagerCompletion ( packageManager ) ;
42- await setupCompletionForPackageManager ( packageManager , completion ) ;
43- // Take args after 'complete' (args[2..]) as the completion args
44- const toComplete = args . slice ( 2 ) ;
45- await completion . parse ( toComplete ) ;
46- process . exit ( 0 ) ;
47- } else {
48- console . error ( `Error: Expected '--' followed by command to complete` ) ;
49- process . exit ( 1 ) ;
50- }
31+ // When PowerShell shims drop the literal '--', fall back to treating
32+ // everything after "complete" as the completion payload.
33+ const completionArgs =
34+ dashIndex !== - 1
35+ ? process . argv . slice ( dashIndex + 1 )
36+ : isPowerShell
37+ ? args . slice ( 2 )
38+ : null ;
39+
40+ if ( ! completionArgs ) {
41+ console . error ( `Error: Expected '--' followed by command to complete` ) ;
42+ process . exit ( 1 ) ;
5143 }
44+
45+ const completion = new PackageManagerCompletion ( packageManager ) ;
46+ await setupCompletionForPackageManager ( packageManager , completion ) ;
47+ await completion . parse ( completionArgs ) ;
48+ process . exit ( 0 ) ;
5249 }
5350
5451 // <packageManager> <shell>
0 commit comments