@@ -29,6 +29,72 @@ import {
2929// regex to detect options section in help text
3030const OPTIONS_SECTION_RE = / ^ \s * O p t i o n s : / i;
3131
32+ // completion handlers for pnpm options that take values
33+ const pnpmOptionHandlers = {
34+ dir : function ( complete : ( value : string , description : string ) => void ) {
35+ complete ( './' , 'Current directory' ) ;
36+ complete ( '../' , 'Parent directory' ) ;
37+ complete ( './packages' , 'Packages directory' ) ;
38+ } ,
39+ loglevel : function ( complete : ( value : string , description : string ) => void ) {
40+ complete ( 'debug' , 'Debug level' ) ;
41+ complete ( 'info' , 'Info level' ) ;
42+ complete ( 'warn' , 'Warning level' ) ;
43+ complete ( 'error' , 'Error level' ) ;
44+ complete ( 'silent' , 'Silent level' ) ;
45+ } ,
46+ reporter : function ( complete : ( value : string , description : string ) => void ) {
47+ complete ( 'default' , 'Default reporter' ) ;
48+ complete ( 'silent' , 'Silent reporter' ) ;
49+ complete ( 'append-only' , 'Append-only reporter' ) ;
50+ complete ( 'ndjson' , 'NDJSON reporter' ) ;
51+ } ,
52+ filter : function ( complete : ( value : string , description : string ) => void ) {
53+ complete ( './packages/*' , 'All packages in packages directory' ) ;
54+ complete ( './apps/*' , 'All apps in apps directory' ) ;
55+ complete ( '@scope/*' , 'All packages in scope' ) ;
56+ complete ( '.' , 'Current working directory' ) ;
57+ } ,
58+ 'modules-dir' : function (
59+ complete : ( value : string , description : string ) => void
60+ ) {
61+ complete ( 'node_modules' , 'Default modules directory' ) ;
62+ complete ( './modules' , 'Custom modules directory' ) ;
63+ } ,
64+ 'store-dir' : function (
65+ complete : ( value : string , description : string ) => void
66+ ) {
67+ complete ( '~/.pnpm-store' , 'Default pnpm store' ) ;
68+ complete ( './store' , 'Local store directory' ) ;
69+ } ,
70+ 'lockfile-dir' : function (
71+ complete : ( value : string , description : string ) => void
72+ ) {
73+ complete ( './' , 'Current directory' ) ;
74+ complete ( '../' , 'Parent directory' ) ;
75+ } ,
76+ 'virtual-store-dir' : function (
77+ complete : ( value : string , description : string ) => void
78+ ) {
79+ complete ( 'node_modules/.pnpm' , 'Default virtual store' ) ;
80+ complete ( './.pnpm' , 'Custom virtual store' ) ;
81+ } ,
82+ 'hoist-pattern' : function (
83+ complete : ( value : string , description : string ) => void
84+ ) {
85+ complete ( '*' , 'Hoist everything (default)' ) ;
86+ complete ( '@types/*' , 'Hoist only type packages' ) ;
87+ complete ( 'eslint*' , 'Hoist ESLint packages' ) ;
88+ } ,
89+ 'public-hoist-pattern' : function (
90+ complete : ( value : string , description : string ) => void
91+ ) {
92+ complete ( '*eslint*' , 'Hoist ESLint packages to root' ) ;
93+ complete ( '*prettier*' , 'Hoist Prettier packages to root' ) ;
94+ complete ( '@types/*' , 'Hoist type packages to root' ) ;
95+ } ,
96+ } ;
97+
3298// we parse the pnpm help text to extract commands and their descriptions!
3399export function parsePnpmHelp ( helpText : string ) : Record < string , string > {
34100 const helpLines = stripAnsiEscapes ( helpText ) . split ( / \r ? \n / ) ;
@@ -117,7 +183,7 @@ export function parsePnpmOptions(
117183 for ( const line of helpLines ) {
118184 const optionMatch = line . match ( OPTION_ROW_RE ) ;
119185 if ( ! optionMatch ) continue ;
120- if ( flagsOnly && optionMatch . groups ?. val ) continue ; // skip value-taking options, we will add them manually with their value
186+ if ( flagsOnly && optionMatch . groups ?. val ) continue ;
121187 const descColumnIndexOnThisLine = line . indexOf ( optionMatch . groups ! . desc ) ;
122188 if (
123189 descColumnIndexOnThisLine >= 0 &&
@@ -179,11 +245,19 @@ export function loadDynamicOptionsSync(
179245 timeout : 500 ,
180246 } ) ;
181247
182- const parsedOptions = parsePnpmOptions ( stdout , { flagsOnly : true } ) ;
248+ const allOptions = parsePnpmOptions ( stdout , { flagsOnly : false } ) ;
183249
184- for ( const { long, short, desc } of parsedOptions ) {
250+ for ( const { long, short, desc } of allOptions ) {
185251 const alreadyDefined = cmd . optionsRaw ?. get ?.( long ) ;
186- if ( ! alreadyDefined ) cmd . option ( long , desc , short ) ;
252+ if ( ! alreadyDefined ) {
253+ const handler =
254+ pnpmOptionHandlers [ long as keyof typeof pnpmOptionHandlers ] ;
255+ if ( handler ) {
256+ cmd . option ( long , desc , handler , short ) ;
257+ } else {
258+ cmd . option ( long , desc , short ) ;
259+ }
260+ }
187261 }
188262 } catch ( _err ) { }
189263}
0 commit comments