@@ -187,8 +187,22 @@ namespace ts {
187
187
const typeReferenceExtensions = [ ".d.ts" ] ;
188
188
189
189
function getEffectiveTypeRoots ( options : CompilerOptions , host : ModuleResolutionHost ) {
190
- return options . typeRoots ||
191
- map ( defaultTypeRoots , d => combinePaths ( options . configFilePath ? getDirectoryPath ( options . configFilePath ) : host . getCurrentDirectory ( ) , d ) ) ;
190
+ if ( options . typeRoots ) {
191
+ return options . typeRoots ;
192
+ }
193
+
194
+ let currentDirectory : string ;
195
+ if ( options . configFilePath ) {
196
+ currentDirectory = getDirectoryPath ( options . configFilePath ) ;
197
+ }
198
+ else if ( host . getCurrentDirectory ) {
199
+ currentDirectory = host . getCurrentDirectory ( ) ;
200
+ }
201
+
202
+ if ( ! currentDirectory ) {
203
+ return undefined ;
204
+ }
205
+ return map ( defaultTypeRoots , d => combinePaths ( currentDirectory , d ) ) ;
192
206
}
193
207
194
208
/**
@@ -228,7 +242,7 @@ namespace ts {
228
242
const failedLookupLocations : string [ ] = [ ] ;
229
243
230
244
// Check primary library paths
231
- if ( typeRoots . length ) {
245
+ if ( typeRoots && typeRoots . length ) {
232
246
if ( traceEnabled ) {
233
247
trace ( host , Diagnostics . Resolving_with_primary_search_path_0 , typeRoots . join ( ", " ) ) ;
234
248
}
@@ -1046,9 +1060,11 @@ namespace ts {
1046
1060
let result : string [ ] = [ ] ;
1047
1061
if ( host . directoryExists && host . getDirectories ) {
1048
1062
const typeRoots = getEffectiveTypeRoots ( options , host ) ;
1049
- for ( const root of typeRoots ) {
1050
- if ( host . directoryExists ( root ) ) {
1051
- result = result . concat ( host . getDirectories ( root ) ) ;
1063
+ if ( typeRoots ) {
1064
+ for ( const root of typeRoots ) {
1065
+ if ( host . directoryExists ( root ) ) {
1066
+ result = result . concat ( host . getDirectories ( root ) ) ;
1067
+ }
1052
1068
}
1053
1069
}
1054
1070
}
0 commit comments