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

Adds glob-style pattern matching for files in tsconfig.json #5980

Merged
merged 14 commits into from
Jun 20, 2016
Merged

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Dec 7, 2015

Supersedes #3232.

Adds support for expanding glob-like patterns in "include" and "exclude" properties of tsconfig.json. The following patterns are supported:

  • * - Matches zero or more characters, excluding directory separators.
  • ? - Matches any one character, excluding directory separators.
  • **/ - Recursively matches any subdirectory.
  • If the file segment of a path contains only * or .*, only supported extensions are considered (e.g. ".ts", ".tsx", and ".d.ts" by default, and also ".js" and ".jsx" if allowJs is true).

At this time, character escape sequences are not supported, as there is no standard cross-platform convention. The standard escape sequence in a Unix shell is prefixed with \, which is reserved as a directory separator on Windows, and is normalized to / by TypeScript. Character ranges are also not included at this time.

This does not use the glob module, as TypeScript runs in more host environments than just NodeJS, and this would need to interoperate with the language service host.

{
    "compilerOptions": {
        "out": "test.js"
    },
    "files": [
      "literal.ts"
    ],
    "include": [
        "**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "tests/**/*.spec.ts",
        "utils/t2.ts"
    ]
}

Notes:

  • Files in the "files" list are always added to the list of files.
  • The "exclude" list only applies to files matched via "include". If the leading directory of a path is excluded, it will not be traversed. You cannot re-include an excluded file, other than through providing it as a literal path in the "files" list.
  • If neither "files" nor "include" are present, "include" defaults to "**/*" but only includes files with supported extensions. This preserves the existing behavior.

// wildcard paths.
const literalFiles = createFileMap<Path>(keyMapper);

// Wildcard paths (provided via the "includes" array in tscofnig.json) are stored in a
Copy link
Member

Choose a reason for hiding this comment

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

tsconfig.json

@@ -161,7 +161,8 @@ var harnessSources = harnessCoreSources.concat([
"reuseProgramStructure.ts",
"cachingInServerLSHost.ts",
"moduleResolution.ts",
"tsconfigParsing.ts"
"tsconfigParsing.ts",
"expandFiles.ts"
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this file to the tsconfig.json files in src\**\

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no tsconfig.json in either src/harness or tests/cases/unittests

@rbuckton
Copy link
Member Author

@paulvanbrenk, @DanielRosenwasser, @vladima, @ahejlsberg Any comments on this approach?

@@ -584,4 +581,233 @@ namespace ts {

return { options, errors };
}

const invalidTrailingRecursionPattern = /(^|\/)\*\*\/?$/;
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 add comments to all these regular expressions.. they are impossible to parse.

directories: string[];
}

export function matchFiles(path: string, extensions: string[], excludes: string[], includes: string[], useCaseSensitiveFileNames: boolean, currentDirectory: string, getFileSystemEntries: (path: string) => FileSystemEntries): string[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this make more sense in sys.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.

Most of our other path logic exists in core.ts.

@ryasmi
Copy link

ryasmi commented Dec 25, 2015

Need this so badly

@rbuckton
Copy link
Member Author

rbuckton commented Jan 5, 2016

Odd. All I did was merge from master. I'll check into this shortly.

@glen-84
Copy link

glen-84 commented Feb 5, 2016

What still needs to be done before this can be merged? (other than resolving the conflicts)

const keyMapper = host.useCaseSensitiveFileNames ? caseSensitiveKeyMapper : caseInsensitiveKeyMapper;

// Literal file names (provided via the "files" array in tsconfig.json) are stored in a
// file map with a possibly case insensitive key. We use this map later when when including
Copy link
Contributor

Choose a reason for hiding this comment

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

We use this map later when including

@glen-84
Copy link

glen-84 commented Feb 15, 2016

@rbuckton Is there any way that TypeScript could expose the globbing logic so that other libraries could easily get the list of files, without having to re-implement all of the rules?

I was trying to implement the include/exclude stuff using globby, but it seems that an exclude entry like node_modules won't work, as it needs to be node_modules/**.

Edit: The use case is getting a list of files for gulp.watch, but I'd imagine that it might be useful for other libraries like gulp-typescript.

Edit 2: Actually getting a list of files isn't really useful, as it won't match files created later. 😞

@nevir
Copy link

nevir commented Apr 22, 2016

Curious what the status on this one is

@LPGhatguy
Copy link
Contributor

Why isn't TypeScript using a community-vetted library like minimatch that WILL run in all environments?

Implementing glob and not doing it fully is not as helpful as supporting the standard glob syntax used throughout the JS ecosystem.

@mhegazy
Copy link
Contributor

mhegazy commented May 25, 2016

Why isn't TypeScript using a community-vetted library like minimatch that WILL run in all environments?

The typescript compiler runs in other environments other than node, e.g. web (monaco web editor), VSCode, (uses its own require implementation), VS (chakra), etc.. so dependencies can be tricky.

We are working on getting this done soon. so please bear with us for a bit longer.

@riknoll riknoll merged commit c1205eb into master Jun 20, 2016
@mhegazy mhegazy deleted the glob2 branch June 20, 2016 23:31
@wyntau
Copy link

wyntau commented Jun 21, 2016

Exciting 😀

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.