-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add support for including dotted and .min.js files explicitly in include #9528
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
// The * and ? wildcards should not match directories or files that start with . if they | ||
// appear first in a component. Dotted directories and files can be included explicitly | ||
// like so: **/.*/.* | ||
if (component.indexOf("*") === 0) { |
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 use component.charCodeAt(0) === CharacterCodes.asterisk
here? It would be inefficient to look at every character of a component when we only care about the first one.
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.
Ha, yep. Good catch!
@@ -1020,6 +1020,10 @@ namespace ts { | |||
} | |||
|
|||
return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$"); | |||
} | |||
|
|||
function replaceWildcardCharacters(component: string, singleAsteriskRegexFragment: string) { |
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 still introduces a closure. Another approach would be:
// at :924
const singleAsteriskRegexFragmentForFiles = "([^./]*(\\.(?!min\\.js$))?)*";
const singleAsteriskRegexFragmentForOther = "[^/]*";
// at :938
const singleAsteriskRegexFragment = usage === "files" ? singleAsteriskRegexFragmentForFiles : singleAsteriskRegexFragmentForOther;
const replaceWildcardCharacter = usage === "files" ? replaceWildcardCharacterForFiles : replaceWildcardCharacterForOther;
// at :1000
subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter); // uses local from :939
// at :1025
function replaceWildcardCharacterForFiles(match: string) {
return replaceWildcardCharacter(match, singleAsteriskRegexFragmentForFiles);
}
function replaceWildcardCharacterForOther(match: string) {
return replaceWildcardCharacter(match, singleAsteriskRegexFragmentForOther);
}
function replaceWildcardCharacter(match: string, singleAsteriskRegexFragment: string) {
return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
}
With this, no new closures are introduced.
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.
Done
👍 |
Porting #9528 to release 2.0 branch
Porting #9528 to release 2.0 branch
Fixes #9472
This PR lets you explicitly include dotted files/folders and
.min.js
files in your"include"
globs. Previously, these files were always ignored unless listed in the"files"
property of tsconfig.json. By "explicitly included", I mean that either the glob has no wildcards or the substrings.
or.min.js
are explicitly part of the wildcard. Here are some examples for how each wildcard behaves when used within"include"
globs:*/*
will not match any dotted files/folders, but the glob.*/.*
will?git/*
will not match the.git
directory but.git/*
will*.js
will not match any.min.js
files but the glob*.min.js
will**
will never match any dotted directoriesIn
"exclude"
globs, wildcards still match dotted files/folders and.min.js
files implicitly. This is necessary to preserve the behavior of being able to exclude entire directories using globs likenode_modules/**/*