@@ -182,23 +182,22 @@ namespace ts {
182182 return currentDirectory && getDefaultTypeRoots ( currentDirectory , host ) ;
183183 }
184184
185+ /**
186+ * Returns the path to every node_modules/@types directory from some ancestor directory.
187+ * Returns undefined if there are none.
188+ */
185189 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 {
191190 if ( ! host . directoryExists ) {
192191 return [ combinePaths ( currentDirectory , "node_modules" ) ] ;
193192 // And if it doesn't exist, tough.
194193 }
195194
196- const all : string [ ] = [ ] ;
195+ let typeRoots : string [ ] ;
197196
198197 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 ) ;
202201 }
203202
204203 const parent = getDirectoryPath ( currentDirectory ) ;
@@ -208,8 +207,10 @@ namespace ts {
208207 currentDirectory = parent ;
209208 }
210209
211- return all ;
210+ return typeRoots ;
212211 }
212+ const nodeModulesAtTypes = combinePaths ( "node_modules" , "@types" ) ;
213+
213214 /**
214215 * @param {string | undefined } containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
215216 * 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