File tree Expand file tree Collapse file tree
src/server/typingsInstaller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,8 +69,13 @@ namespace ts.server.typingsInstaller {
6969 return base === "package.json" || base === "bower.json" ;
7070 }
7171
72- function isInNodeModulesOrBowerComponents ( f : string ) {
73- return stringContains ( f , "/node_modules/" ) || stringContains ( f , "/bower_components/" ) ;
72+ function getDirectoryExcludingNodeModulesOrBowerComponents ( f : string ) {
73+ const indexOfNodeModules = f . indexOf ( "/node_modules/" ) ;
74+ const indexOfBowerComponents = f . indexOf ( "/bower_components/" ) ;
75+ const subStrLength = indexOfNodeModules === - 1 || indexOfBowerComponents === - 1 ?
76+ Math . max ( indexOfNodeModules , indexOfBowerComponents ) :
77+ Math . min ( indexOfNodeModules , indexOfBowerComponents ) ;
78+ return subStrLength === - 1 ? f : f . substr ( 0 , subStrLength ) ;
7479 }
7580
7681 type ProjectWatchers = Map < FileWatcher > & { isInvoked ?: boolean ; } ;
@@ -478,12 +483,7 @@ namespace ts.server.typingsInstaller {
478483 }
479484
480485 // Get path without node_modules and bower_components
481- let pathToWatch = getDirectoryPath ( filePath ) ;
482- while ( isInNodeModulesOrBowerComponents ( pathToWatch ) ) {
483- pathToWatch = getDirectoryPath ( pathToWatch ) ;
484- }
485-
486- createProjectWatcher ( pathToWatch , createProjectDirectoryWatcher ) ;
486+ createProjectWatcher ( getDirectoryExcludingNodeModulesOrBowerComponents ( getDirectoryPath ( filePath ) ) , createProjectDirectoryWatcher ) ;
487487 }
488488
489489 // Remove unused watches
You can’t perform that action at this time.
0 commit comments