-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Conversation
…sive directory glob
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 |
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.
can you turn this into a series of if
s? this is pretty unreadable to me.
} | ||
} | ||
/** | ||
* An "includes" path "foo" is implicitly a glob "foo\**\*" (replace \ with /) if its last component has no extension, |
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.
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 { |
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.
You shouldn't need to use any
- our overload compatibility rules are bidirectional for return types.
else if (isImplicitGlob(spec)) { | ||
return { key: spec, flags: WatchDirectoryFlags.Recursive }; | ||
} | ||
else { |
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.
Nit: when each branch of an if
finishes in a return
, we don't structure these as if
-else
s, since the logic is automatically exclusive.
if (hasWrittenComponent) { | ||
subpattern += directorySeparator; | ||
} | ||
return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$"); |
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.
Separate the last part into a variable and comment what the purpose is.
} | ||
else { | ||
return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset)); | ||
} |
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.
Same nit as above about if
-else
s
function getIncludeBasePath(absolute: string): string { | ||
const wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes); | ||
if (wildcardOffset < 0) { | ||
// No "*" in the path |
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.
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
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 returnsfalse
then behavior will be the same as before. If wanted I could break this into 2 PRs, one which refactors and one which addsisImplicitGlob
.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.