@@ -22,18 +22,15 @@ export type CompletionHandler = (
2222) => void ;
2323export type OptionHandlers = Record < string , CompletionHandler > ;
2424
25- export const commonOptionHandlers = {
26- workspace : function ( complete : ( value : string , description : string ) => void ) {
27- const workspacePatterns = getWorkspacePatterns ( ) ;
28- workspacePatterns . forEach ( ( pattern ) => {
29- complete ( pattern , `Workspace pattern: ${ pattern } ` ) ;
30- } ) ;
31-
25+ export const commonOptionHandlers : OptionHandlers = {
26+ workspace ( complete ) {
27+ const patterns = getWorkspacePatterns ( ) ;
28+ patterns . forEach ( ( p ) => complete ( p , `Workspace pattern: ${ p } ` ) ) ;
3229 complete ( 'packages/*' , 'All packages in packages directory' ) ;
3330 complete ( 'apps/*' , 'All apps in apps directory' ) ;
3431 } ,
3532
36- registry : function ( complete : ( value : string , description : string ) => void ) {
33+ registry ( complete ) {
3734 complete ( 'https://registry.npmjs.org/' , 'Official npm registry' ) ;
3835 complete ( 'https://registry.npmmirror.com/' , 'npm China mirror' ) ;
3936 } ,
@@ -42,22 +39,22 @@ export const commonOptionHandlers = {
4239export function setupLazyOptionLoading (
4340 cmd : LazyCommand ,
4441 command : string ,
45- packageManager : string ,
42+ _packageManager : string ,
4643 loadOptionsSync : ( cmd : LazyCommand , command : string ) => void
4744) : void {
4845 cmd . _lazyCommand = command ;
4946 cmd . _optionsLoaded = false ;
5047
51- const optionsStore = cmd . options ;
52- cmd . optionsRaw = optionsStore ;
48+ const store = cmd . options ;
49+ cmd . optionsRaw = store ;
5350
5451 Object . defineProperty ( cmd , 'options' , {
5552 get ( ) {
5653 if ( ! this . _optionsLoaded ) {
5754 this . _optionsLoaded = true ;
5855 loadOptionsSync ( this , this . _lazyCommand ) ;
5956 }
60- return optionsStore ;
57+ return store ;
6158 } ,
6259 configurable : true ,
6360 } ) ;
@@ -66,14 +63,12 @@ export function setupLazyOptionLoading(
6663export function setupCommandArguments (
6764 cmd : LazyCommand ,
6865 command : string ,
69- packageManager : string
66+ _packageManager : string
7067) : void {
71- // Package removal commands
7268 if ( [ 'remove' , 'rm' , 'uninstall' , 'un' , 'update' , 'up' ] . includes ( command ) ) {
7369 cmd . argument ( 'package' , packageJsonDependencyCompletion ) ;
7470 }
7571
76- // Script running commands
7772 if ( [ 'run' , 'run-script' ] . includes ( command ) ) {
7873 cmd . argument ( 'script' , packageJsonScriptCompletion , true ) ;
7974 }
@@ -92,13 +87,13 @@ export async function safeExec(
9287 } ) ;
9388 return stdout as unknown as string ;
9489 } catch ( error ) {
95- // Many package managers exit with non-zero but still provide useful output
9690 if ( error instanceof Error && 'stdout' in error ) {
97- return error . stdout as unknown as string ;
91+ return ( error as any ) . stdout as string ;
9892 }
9993 return '' ;
10094 }
10195}
96+
10297export function safeExecSync ( command : string , options : any = { } ) : string {
10398 try {
10499 return execSync ( command , {
@@ -107,16 +102,10 @@ export function safeExecSync(command: string, options: any = {}): string {
107102 ...options ,
108103 } ) as unknown as string ;
109104 } catch ( error : any ) {
110- // Handle non-zero exit codes that still provide output
111- if ( error . stdout ) {
112- return error . stdout as unknown as string ;
113- }
114- return '' ;
105+ return error ?. stdout ? ( error . stdout as string ) : '' ;
115106 }
116107}
117108
118109export function createLogLevelHandler ( levels : string [ ] ) : CompletionHandler {
119- return function ( complete : ( value : string , description : string ) => void ) {
120- levels . forEach ( ( level ) => complete ( level , ' ' ) ) ;
121- } ;
110+ return ( complete ) => levels . forEach ( ( lvl ) => complete ( lvl , ' ' ) ) ;
122111}
0 commit comments