1
1
import * as path from "path" ;
2
2
import { BasePackageManager } from "./base-package-manager" ;
3
3
import { exported } from './common/decorators' ;
4
+ import { CACACHE_DIRECTORY_NAME } from "./constants" ;
4
5
5
6
export class PnpmPackageManager extends BasePackageManager {
6
7
@@ -29,10 +30,11 @@ export class PnpmPackageManager extends BasePackageManager {
29
30
const jsonContentBefore = this . $fs . readJson ( packageJsonPath ) ;
30
31
31
32
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' ] ;
33
35
const isInstallingAllDependencies = packageName === pathToSave ;
34
36
if ( ! isInstallingAllDependencies ) {
35
- params . push ( 'i' , packageName ) ;
37
+ params . push ( packageName ) ;
36
38
}
37
39
38
40
params = params . concat ( flags ) ;
@@ -64,15 +66,14 @@ export class PnpmPackageManager extends BasePackageManager {
64
66
} catch ( e ) {
65
67
this . $errors . fail ( e . message ) ;
66
68
}
67
-
68
69
const result = JSON . parse ( viewResult ) ;
69
- return result . data ;
70
+ return result ;
70
71
}
71
72
72
73
@exported ( "pnpm" )
73
74
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 } ` ) ;
76
77
}
77
78
78
79
public async searchNpms ( keyword : string ) : Promise < INpmsResult > {
@@ -95,8 +96,8 @@ export class PnpmPackageManager extends BasePackageManager {
95
96
96
97
@exported ( "pnpm" )
97
98
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 ) ;
100
101
}
101
102
}
102
103
0 commit comments