@@ -24,6 +24,13 @@ interface PackageJson {
24
24
'ng-add' ?: {
25
25
save ?: NgAddSaveDependency ;
26
26
} ;
27
+ installConfig ?: {
28
+ pnp ?: boolean ;
29
+ } ;
30
+ }
31
+
32
+ interface YarnPnp {
33
+ resolveRequest : ( request : string , issuer : string ) => string | null ;
27
34
}
28
35
29
36
function getAllDependencies ( pkg : PackageJson ) : Set < [ string , string ] > {
@@ -50,7 +57,21 @@ export async function readPackageJson(packageJsonPath: string): Promise<PackageJ
50
57
}
51
58
}
52
59
53
- export function findPackageJson ( workspaceDir : string , packageName : string ) : string | undefined {
60
+ export function findPackageJson (
61
+ workspaceDir : string ,
62
+ packageName : string ,
63
+ usingPnP = false ,
64
+ ) : string | undefined {
65
+ if ( usingPnP ) {
66
+ if ( fs . existsSync ( join ( workspaceDir , '.pnp.js' ) ) ) {
67
+ const pnp : YarnPnp = require ( join ( workspaceDir , '.pnp.js' ) ) ;
68
+ const packageJsonPath = pnp . resolveRequest ( `${ packageName } /package.json` , workspaceDir ) ;
69
+
70
+ return packageJsonPath ?? undefined ;
71
+ } else {
72
+ throw new Error ( "Could not find .pnp.js of Yarn Plug'n'Play" ) ;
73
+ }
74
+ }
54
75
try {
55
76
// avoid require.resolve here, see: https://github.com/angular/angular-cli/pull/18610#issuecomment-681980185
56
77
const packageJsonPath = resolve . sync ( `${ packageName } /package.json` , { basedir : workspaceDir } ) ;
@@ -66,10 +87,10 @@ export async function getProjectDependencies(dir: string): Promise<Map<string, P
66
87
if ( ! pkg ) {
67
88
throw new Error ( 'Could not find package.json' ) ;
68
89
}
69
-
90
+ const usingPnP = ! ! pkg . installConfig ?. pnp ;
70
91
const results = new Map < string , PackageTreeNode > ( ) ;
71
92
for ( const [ name , version ] of getAllDependencies ( pkg ) ) {
72
- const packageJsonPath = findPackageJson ( dir , name ) ;
93
+ const packageJsonPath = findPackageJson ( dir , name , usingPnP ) ;
73
94
if ( ! packageJsonPath ) {
74
95
continue ;
75
96
}
0 commit comments