@@ -17,7 +17,6 @@ export class TargetProjectLocator {
1717 private tsConfig = this . getRootTsConfig ( ) ;
1818 private paths = this . tsConfig . config ?. compilerOptions ?. paths ;
1919 private typescriptResolutionCache = new Map < string , string | null > ( ) ;
20- private projectResolutionCache = new Map < string , string | null > ( ) ;
2120 private npmResolutionCache = new Map < string , string | null > ( ) ;
2221
2322 constructor (
@@ -52,12 +51,6 @@ export class TargetProjectLocator {
5251 }
5352 }
5453
55- // check if it exists in projects
56- const project = this . findProject ( normalizedImportExpr ) ;
57- if ( project ) {
58- return project ;
59- }
60-
6154 // try to find npm package before using expensive typescript resolution
6255 const npmProject = this . findNpmPackage ( normalizedImportExpr ) ;
6356 if ( npmProject ) {
@@ -77,6 +70,15 @@ export class TargetProjectLocator {
7770 }
7871 }
7972
73+ try {
74+ const resolvedModule = this . resolveImportWithRequire (
75+ normalizedImportExpr ,
76+ filePath
77+ ) ;
78+
79+ return this . findProjectOfResolvedModule ( resolvedModule ) ;
80+ } catch { }
81+
8082 // nothing found, cache for later
8183 this . npmResolutionCache . set ( normalizedImportExpr , undefined ) ;
8284 return null ;
@@ -135,22 +137,17 @@ export class TargetProjectLocator {
135137 return ;
136138 }
137139
138- private findProject ( importExpr : string ) : string | undefined {
139- if ( this . projectResolutionCache . has ( importExpr ) ) {
140- return this . projectResolutionCache . get ( importExpr ) ;
141- } else {
142- const project = Object . values ( this . nodes ) . find (
143- ( project ) =>
144- importExpr === project . name ||
145- importExpr . startsWith ( `${ project . name } /` )
146- ) ;
147- if ( project ) {
148- this . projectResolutionCache . set ( importExpr , project . name ) ;
149- return project . name ;
150- }
151- }
140+ private resolveImportWithRequire (
141+ normalizedImportExpr : string ,
142+ filePath : string
143+ ) {
144+ return posix . relative (
145+ workspaceRoot ,
146+ require . resolve ( normalizedImportExpr , {
147+ paths : [ dirname ( filePath ) ] ,
148+ } )
149+ ) ;
152150 }
153-
154151 private findNpmPackage ( npmImport : string ) : string | undefined {
155152 if ( this . npmResolutionCache . has ( npmImport ) ) {
156153 return this . npmResolutionCache . get ( npmImport ) ;
0 commit comments