Skip to content

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

Merged
merged 7 commits into from
Jul 22, 2016

Conversation

riknoll
Copy link
Member

@riknoll riknoll commented Jul 5, 2016

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:

  • The glob */* will not match any dotted files/folders, but the glob .*/.* will
  • The glob ?git/* will not match the .git directory but .git/* will
  • The glob *.js will not match any .min.js files but the glob *.min.js will
  • The glob ** will never match any dotted directories

In "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 like node_modules/**/*

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

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.

Copy link
Member Author

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@rbuckton
Copy link
Contributor

👍

@riknoll riknoll merged commit 8b2ea39 into master Jul 22, 2016
riknoll added a commit that referenced this pull request Jul 26, 2016
riknoll added a commit that referenced this pull request Jul 29, 2016
@weswigham weswigham deleted the explicitly_included_globs branch August 11, 2016 01:44
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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.

3 participants