@@ -182,23 +182,22 @@ namespace ts {
182
182
return currentDirectory && getDefaultTypeRoots ( currentDirectory , host ) ;
183
183
}
184
184
185
+ /**
186
+ * Returns the path to every node_modules/@types directory from some ancestor directory.
187
+ * Returns undefined if there are none.
188
+ */
185
189
function getDefaultTypeRoots ( currentDirectory : string , host : ModuleResolutionHost ) : string [ ] | undefined {
186
- return map ( getAllNodeModulesDirectories ( currentDirectory , host ) , nodeModules => combinePaths ( nodeModules , "@types" ) ) ;
187
- }
188
-
189
- /** Returns the path to every node_modules directory from some ancestor directory. */
190
- function getAllNodeModulesDirectories ( currentDirectory : string , host : ModuleResolutionHost ) : string [ ] | undefined {
191
190
if ( ! host . directoryExists ) {
192
191
return [ combinePaths ( currentDirectory , "node_modules" ) ] ;
193
192
// And if it doesn't exist, tough.
194
193
}
195
194
196
- const all : string [ ] = [ ] ;
195
+ let typeRoots : string [ ] ;
197
196
198
197
while ( true ) {
199
- const nodeModules = combinePaths ( currentDirectory , "node_modules" ) ;
200
- if ( host . directoryExists ( nodeModules ) ) {
201
- all . push ( nodeModules ) ;
198
+ const atTypes = combinePaths ( currentDirectory , nodeModulesAtTypes ) ;
199
+ if ( host . directoryExists ( atTypes ) ) {
200
+ ( typeRoots || ( typeRoots = [ ] ) ) . push ( atTypes ) ;
202
201
}
203
202
204
203
const parent = getDirectoryPath ( currentDirectory ) ;
@@ -208,8 +207,10 @@ namespace ts {
208
207
currentDirectory = parent ;
209
208
}
210
209
211
- return all ;
210
+ return typeRoots ;
212
211
}
212
+ const nodeModulesAtTypes = combinePaths ( "node_modules" , "@types" ) ;
213
+
213
214
/**
214
215
* @param {string | undefined } containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
215
216
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
0 commit comments