@@ -71,10 +71,19 @@ export class Project {
7171 redirectedReference : ts . ResolvedProjectReference ,
7272 options : ts . CompilerOptions ) {
7373
74+ let oppositePath =
75+ this . virtualSourceRoot . toVirtualPath ( containingFile ) ||
76+ this . virtualSourceRoot . fromVirtualPath ( containingFile ) ;
77+
7478 const { host, resolutionCache } = this ;
7579 return moduleNames . map ( ( moduleName ) => {
7680 let redirected = this . redirectModuleName ( moduleName , containingFile , options ) ;
7781 if ( redirected != null ) return redirected ;
82+ if ( oppositePath != null ) {
83+ // If the containing file is in the virtual source root, try resolving from the real source root, and vice versa.
84+ redirected = ts . resolveModuleName ( moduleName , oppositePath , options , host , resolutionCache ) . resolvedModule ;
85+ if ( redirected != null ) return redirected ;
86+ }
7887 return ts . resolveModuleName ( moduleName , containingFile , options , host , resolutionCache ) . resolvedModule ;
7988 } ) ;
8089 }
@@ -90,15 +99,7 @@ export class Project {
9099
91100 // Get the overridden location of this package, if one exists.
92101 let packageEntryPoint = this . packageEntryPoints . get ( packageName ) ;
93- if ( packageEntryPoint == null ) {
94- // The package is not overridden, but we have established that it begins with a valid package name.
95- // Do a lookup in the virtual source root (where dependencies are installed) by changing the 'containing file'.
96- let virtualContainingFile = this . virtualSourceRoot . toVirtualPath ( containingFile ) ;
97- if ( virtualContainingFile != null ) {
98- return ts . resolveModuleName ( moduleName , virtualContainingFile , options , this . host , this . resolutionCache ) . resolvedModule ;
99- }
100- return null ;
101- }
102+ if ( packageEntryPoint == null ) return null ;
102103
103104 // If the requested module name is exactly the overridden package name,
104105 // return the entry point file (it is not necessarily called `index.ts`).
0 commit comments