@@ -26,15 +26,20 @@ function detectPackageManager(): string {
2626 return 'npm'
2727}
2828
29- function runInstall ( pm : string ) : Promise < number > {
29+ function runInstall ( pm : string ) : Promise < { exitCode : number ; stderr : string } > {
3030 const command = pm === 'pnpm' ? 'add' : 'install'
3131 return new Promise ( ( resolve , reject ) => {
3232 const child = spawn ( pm , [ command , '-g' , `${ PACKAGE_NAME } @latest` ] , {
33- stdio : 'inherit' ,
33+ stdio : 'pipe' ,
34+ } )
35+
36+ let stderr = ''
37+ child . stderr ?. on ( 'data' , ( data : Buffer ) => {
38+ stderr += data . toString ( )
3439 } )
3540
3641 child . on ( 'error' , reject )
37- child . on ( 'close' , ( code ) => resolve ( code ?? 1 ) )
42+ child . on ( 'close' , ( code ) => resolve ( { exitCode : code ?? 1 , stderr } ) )
3843 } )
3944}
4045
@@ -68,15 +73,13 @@ export async function updateAction(options: { check?: boolean }): Promise<void>
6873 }
6974
7075 const pm = detectPackageManager ( )
71- console . log ( chalk . dim ( `Updating to v${ latestVersion } ...` ) )
7276
77+ let result : { exitCode : number ; stderr : string }
7378 try {
74- const exitCode = await runInstall ( pm )
75- if ( exitCode !== 0 ) {
76- console . error ( chalk . red ( 'Error:' ) , `${ pm } exited with code ${ exitCode } ` )
77- process . exitCode = 1
78- return
79- }
79+ result = await withSpinner (
80+ { text : `Updating to v${ latestVersion } ...` , color : 'blue' } ,
81+ ( ) => runInstall ( pm ) ,
82+ )
8083 } catch ( error ) {
8184 if ( error instanceof Error && 'code' in error && error . code === 'EACCES' ) {
8285 console . error ( chalk . red ( 'Error:' ) , 'Permission denied. Try running with sudo:' )
@@ -93,6 +96,15 @@ export async function updateAction(options: { check?: boolean }): Promise<void>
9396 return
9497 }
9598
99+ if ( result . exitCode !== 0 ) {
100+ console . error ( chalk . red ( 'Error:' ) , `${ pm } exited with code ${ result . exitCode } ` )
101+ if ( result . stderr ) {
102+ console . error ( chalk . dim ( result . stderr . trim ( ) ) )
103+ }
104+ process . exitCode = 1
105+ return
106+ }
107+
96108 console . log ( chalk . green ( '✓' ) , `Updated to v${ latestVersion } ` )
97109}
98110
0 commit comments