Skip to content

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

Merged
merged 3 commits into from
Apr 19, 2018

Conversation

sheetalkamat
Copy link
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
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
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
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
Member Author

@mhegazy fixed all the comments.

@amcasey
Copy link
Member

amcasey commented Apr 18, 2018

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

Copy link
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
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
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.

@@ -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";
Copy link
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
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
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
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

// handler should be invoked once for the entire set of files since it will trigger full rediscovery of typings
watchers.isInvoked = false;
Copy link
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
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
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