@@ -73,26 +73,40 @@ export class Pnpm extends Resource<PnpmConfig> {
7373 : path . join ( os . homedir ( ) , '.local' , 'share' , 'pnpm' ) ;
7474
7575 const { data : pnpmLocation } = await $ . spawn ( 'which pnpm' , { interactive : true } ) ;
76- if ( pnpmLocation . trim ( ) . toLowerCase ( ) !== path . join ( expectedPnpmHome , 'pnpm' ) . trim ( ) . toLowerCase ( ) ) {
77- throw new Error ( 'pnpm was installed outside of Codify. Please uninstall manually and re-run Codify' ) ;
78- }
76+ const actual = pnpmLocation . trim ( ) . toLowerCase ( ) ;
7977
80- const { data : pnpmHome } = await $ . spawnSafe ( 'echo $PNPM_HOME' , { interactive : true } ) ;
81- if ( ! pnpmHome ) {
82- throw new Error ( '$PNPM_HOME variable is not set. Unable to determine how to uninstall pnpm. Please uninstall manually and re-run Codify.' )
83- }
78+ const expectedPnpmBin = path . join ( expectedPnpmHome , 'bin' , 'pnpm' ) . toLowerCase ( ) ;
79+ const expectedPnpmBinFallback = path . join ( expectedPnpmHome , 'pnpm' ) . toLowerCase ( ) ;
80+ const isInstalledByScript = actual === expectedPnpmBin || actual === expectedPnpmBinFallback ;
81+ const isInstalledByNpm = actual . includes ( 'node_modules/.bin/pnpm' ) || actual . includes ( 'node_modules/pnpm' ) ;
82+ const isInstalledByHomebrew = actual . includes ( '/homebrew/' ) || actual . includes ( '/linuxbrew/' ) || actual . includes ( '/opt/homebrew/' ) ;
8483
85- await fs . rm ( pnpmHome , { recursive : true , force : true } ) ;
86- console . log ( 'Successfully uninstalled pnpm' ) ;
84+ if ( isInstalledByScript ) {
85+ const { data : pnpmHome } = await $ . spawnSafe ( 'echo $PNPM_HOME' , { interactive : true } ) ;
86+ await fs . rm ( pnpmHome ?. trim ( ) || expectedPnpmHome , { recursive : true , force : true } ) ;
8787
88- const shellRc = Utils . getPrimaryShellRc ( ) ;
89- await FileUtils . removeLineFromStartupFile ( '# pnpm' )
90- await FileUtils . removeLineFromStartupFile ( `export PNPM_HOME="${ expectedPnpmHome } "` )
91- await FileUtils . removeFromFile ( shellRc ,
88+ const shellRc = Utils . getPrimaryShellRc ( ) ;
89+ await FileUtils . removeLineFromStartupFile ( '# pnpm' )
90+ await FileUtils . removeLineFromStartupFile ( `export PNPM_HOME="${ expectedPnpmHome } "` )
91+ await FileUtils . removeFromFile ( shellRc ,
92+ `case ":$PATH:" in
93+ *":$PNPM_HOME/bin:"*) ;;
94+ *) export PATH="$PNPM_HOME/bin:$PATH" ;;
95+ esac` )
96+ await FileUtils . removeFromFile ( shellRc ,
9297`case ":$PATH:" in
9398 *":$PNPM_HOME:"*) ;;
9499 *) export PATH="$PNPM_HOME:$PATH" ;;
95100esac` )
96- await FileUtils . removeLineFromStartupFile ( '# pnpm end' )
101+ await FileUtils . removeLineFromStartupFile ( '# pnpm end' )
102+ } else if ( isInstalledByNpm ) {
103+ await $ . spawn ( 'npm uninstall -g pnpm' , { interactive : true } ) ;
104+ } else if ( isInstalledByHomebrew ) {
105+ await Utils . uninstallViaPkgMgr ( 'pnpm' ) ;
106+ } else {
107+ throw new Error ( `pnpm is installed at an unrecognized location: ${ actual } . Please uninstall manually and re-run Codify` ) ;
108+ }
109+
110+ console . log ( 'Successfully uninstalled pnpm' ) ;
97111 }
98112}
0 commit comments