-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Use watch recursive directories instead of watchFile for node_modules and bower components #23484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… and bower components
78955ac
to
db9620d
Compare
|
||
// Get path without node_modules and bower_components | ||
let pathToWatch = getDirectoryPath(filePath); | ||
while (isInNodeModulesOrBowerComponents(pathToWatch)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indexof("/node_modules/")
? we also have a function similar to that in getNodeModulePathParts
return; | ||
} | ||
f = this.toCanonicalFileName(f); | ||
if (isPackageOrBowerJson(f) && f !== this.toCanonicalFileName(combinePaths(this.globalCachePath, "package.json"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the globalCache path is not going to change, we can cache that.
…stead of using loop
@mhegazy fixed all the comments. |
I'm looking, but you really want @RyanCavanaugh for the TI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I had understood you to say that directory watching was not reliable. Otherwise, this seems reasonable.
} | ||
|
||
function getDirectoryExcludingNodeModulesOrBowerComponents(f: string) { | ||
const indexOfNodeModules = f.indexOf("/node_modules/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have helpers for this? E.g. commonPackageFolders
in core.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But TI uses only these two locations.
@@ -64,6 +64,20 @@ namespace ts.server.typingsInstaller { | |||
onRequestCompleted: RequestCompletedAction; | |||
} | |||
|
|||
function isPackageOrBowerJson(fileName: string) { | |||
const base = getBaseFileName(fileName); | |||
return base === "package.json" || base === "bower.json"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this take a flag for case sensitivity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the file here is always canonical file name
|
||
watchers.set(path, createWatch(path)); | ||
}; | ||
const createProjectFileWatcher = (file: string): FileWatcher => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to prefer lambdas over functions or vice versa?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lambdas are needed because we use this
// handler should be invoked once for the entire set of files since it will trigger full rediscovery of typings | ||
watchers.isInvoked = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a dumb question, but isn't watchers
a map? Why would it have an isInvoked
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a expando on map.. This is so that we arent catching incorrect local variable. the state recides on the map (more on this #23438 (comment))
@RyanCavanaugh can you take a look. |
This will help in reducing polling watches.
Fixes #23390