Skip to content
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

Implicitly consider an extensionless file in "includes" to be a recursive directory glob #11495

Merged
5 commits merged into from
Oct 31, 2016

Conversation

ghost
Copy link

@ghost ghost commented Oct 10, 2016

Fixes #10578

There is a lot of refactoring in this PR but the actual changes just have to do with uses of the isImpicitGlob function. If this always returns false then behavior will be the same as before. If wanted I could break this into 2 PRs, one which refactors and one which adds isImplicitGlob.

It would also be a good idea to someday rewrite this functionality into a) parsing globs, then b) doing things with parsed globs. Then we would pass around strings less often.

@ghost ghost force-pushed the includes_glob branch from 08791b7 to 2f77a54 Compare October 10, 2016 18:14
@ghost
Copy link
Author

ghost commented Oct 10, 2016

I tested this on the command-line with a real project and it worked. I'd still like to get @rbuckton's review before merging. Are there some additional tests that should be added?

@@ -1289,6 +1287,18 @@ namespace ts {
return wildcardDirectories;
}

function getWildcardDirectoryFromSpec(spec: string, useCaseSensitiveFileNames: boolean): { key: string, flags: WatchDirectoryFlags } | undefined {
const match = wildcardDirectoryPattern.exec(spec);
return match
Copy link
Member

@DanielRosenwasser DanielRosenwasser Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you turn this into a series of ifs? this is pretty unreadable to me.

}
}
/**
* An "includes" path "foo" is implicitly a glob "foo\**\*" (replace \ with /) if its last component has no extension,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "replace \ with /"?

@@ -1186,6 +1186,12 @@ namespace ts {
return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator)));
}

function getBasename(path: Path): Path;
function getBasename(path: string): string;
function getBasename(path: string): any {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to use any - our overload compatibility rules are bidirectional for return types.

@ghost ghost force-pushed the includes_glob branch from b7496d1 to 9b2e6a3 Compare October 12, 2016 17:13
else if (isImplicitGlob(spec)) {
return { key: spec, flags: WatchDirectoryFlags.Recursive };
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: when each branch of an if finishes in a return, we don't structure these as if-elses, since the logic is automatically exclusive.

if (hasWrittenComponent) {
subpattern += directorySeparator;
}
return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate the last part into a variable and comment what the purpose is.

}
else {
return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit as above about if-elses

function getIncludeBasePath(absolute: string): string {
const wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes);
if (wildcardOffset < 0) {
// No "*" in the path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't isImplicitGlob redoing the work of the call to indexOfAnyCharCode above? We have already eliminated * and ? as possible characters, so the only character you really need to test for is ..

Also the comment should probably read // No "*" or "?" in the path

@ghost ghost merged commit e6f6a5e into master Oct 31, 2016
@ghost ghost deleted the includes_glob branch October 31, 2016 20:56
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
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