Skip to content

Use watch recursive directories instead of watchFile for node_modules and bower components#23484

Merged
sheetalkamat merged 3 commits into
masterfrom
typingInstallerWatch
Apr 19, 2018
Merged

Use watch recursive directories instead of watchFile for node_modules and bower components#23484
sheetalkamat merged 3 commits into
masterfrom
typingInstallerWatch

Conversation

@sheetalkamat
Copy link
Copy Markdown
Member

@sheetalkamat sheetalkamat commented Apr 17, 2018

This will help in reducing polling watches.
Fixes #23390

@sheetalkamat sheetalkamat force-pushed the typingInstallerWatch branch from 78955ac to db9620d Compare April 17, 2018 21:27

// Get path without node_modules and bower_components
let pathToWatch = getDirectoryPath(filePath);
while (isInNodeModulesOrBowerComponents(pathToWatch)) {
Copy link
Copy Markdown
Contributor

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"))) {
Copy link
Copy Markdown
Contributor

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.

@mhegazy mhegazy requested a review from amcasey April 17, 2018 23:05
@sheetalkamat sheetalkamat changed the base branch from typingsFiles to master April 18, 2018 18:35
@sheetalkamat
Copy link
Copy Markdown
Member Author

@amcasey can you please take a look. This helps in reducing 1200 odd files to single directory watcher for #23390

@sheetalkamat
Copy link
Copy Markdown
Member Author

@mhegazy fixed all the comments.

@amcasey
Copy link
Copy Markdown
Member

amcasey commented Apr 18, 2018

I'm looking, but you really want @RyanCavanaugh for the TI.

Copy link
Copy Markdown
Member

@amcasey amcasey left a 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/");
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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.


function isPackageOrBowerJson(fileName: string) {
const base = getBaseFileName(fileName);
return base === "package.json" || base === "bower.json";
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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 => {
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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


watchers.isInvoked = false;
// handler should be invoked once for the entire set of files since it will trigger full rediscovery of typings
watchers.isInvoked = false;
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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))

@sheetalkamat
Copy link
Copy Markdown
Member Author

@RyanCavanaugh can you take a look.

@sheetalkamat sheetalkamat merged commit 0526ff5 into master Apr 19, 2018
@sheetalkamat sheetalkamat deleted the typingInstallerWatch branch April 19, 2018 17:00
@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants