@@ -71,10 +71,19 @@ export class Project {
71
71
redirectedReference : ts . ResolvedProjectReference ,
72
72
options : ts . CompilerOptions ) {
73
73
74
+ let oppositePath =
75
+ this . virtualSourceRoot . toVirtualPath ( containingFile ) ||
76
+ this . virtualSourceRoot . fromVirtualPath ( containingFile ) ;
77
+
74
78
const { host, resolutionCache } = this ;
75
79
return moduleNames . map ( ( moduleName ) => {
76
80
let redirected = this . redirectModuleName ( moduleName , containingFile , options ) ;
77
81
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
+ }
78
87
return ts . resolveModuleName ( moduleName , containingFile , options , host , resolutionCache ) . resolvedModule ;
79
88
} ) ;
80
89
}
@@ -90,15 +99,7 @@ export class Project {
90
99
91
100
// Get the overridden location of this package, if one exists.
92
101
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 ;
102
103
103
104
// If the requested module name is exactly the overridden package name,
104
105
// return the entry point file (it is not necessarily called `index.ts`).
0 commit comments