11import * as path from "path" ;
22import { BasePackageManager } from "./base-package-manager" ;
33import { exported } from './common/decorators' ;
4+ import { CACACHE_DIRECTORY_NAME } from "./constants" ;
45
56export class PnpmPackageManager extends BasePackageManager {
67
@@ -29,10 +30,11 @@ export class PnpmPackageManager extends BasePackageManager {
2930 const jsonContentBefore = this . $fs . readJson ( packageJsonPath ) ;
3031
3132 const flags = this . getFlagsString ( config , true ) ;
32- let params = [ ] ;
33+ // With pnpm we need to install as "flat" or some imports wont be found
34+ let params = [ 'i' , '--shamefully-hoist' ] ;
3335 const isInstallingAllDependencies = packageName === pathToSave ;
3436 if ( ! isInstallingAllDependencies ) {
35- params . push ( 'i' , packageName ) ;
37+ params . push ( packageName ) ;
3638 }
3739
3840 params = params . concat ( flags ) ;
@@ -64,15 +66,14 @@ export class PnpmPackageManager extends BasePackageManager {
6466 } catch ( e ) {
6567 this . $errors . fail ( e . message ) ;
6668 }
67-
6869 const result = JSON . parse ( viewResult ) ;
69- return result . data ;
70+ return result ;
7071 }
7172
7273 @exported ( "pnpm" )
7374 public search ( filter : string [ ] , config : IDictionary < string | boolean > ) : Promise < string > {
74- this . $errors . fail ( "Method not implemented. pnpm does not support searching for packages in the registry." ) ;
75- return null ;
75+ const flags = this . getFlagsString ( config , false ) ;
76+ return this . $childProcess . exec ( `pnpm search ${ filter . join ( " " ) } ${ flags } ` ) ;
7677 }
7778
7879 public async searchNpms ( keyword : string ) : Promise < INpmsResult > {
@@ -95,8 +96,8 @@ export class PnpmPackageManager extends BasePackageManager {
9596
9697 @exported ( "pnpm" )
9798 public async getCachePath ( ) : Promise < string > {
98- const result = await this . $childProcess . exec ( `pnpm cache dir ` ) ;
99- return result . toString ( ) . trim ( ) ;
99+ const cachePath = await this . $childProcess . exec ( `pnpm config get cache ` ) ;
100+ return path . join ( cachePath . trim ( ) , CACACHE_DIRECTORY_NAME ) ;
100101 }
101102}
102103
0 commit comments