From 27d074d203ffbcc42dd5ca764ad5620c8ff9b0b3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 21 Aug 2019 15:33:09 -0700 Subject: [PATCH] Expose matchFiles API as 'getMatchingFiles' --- src/compiler/utilities.ts | 61 +++++++++++++++++-- .../reference/api/tsserverlibrary.d.ts | 40 ++++++++++++ tests/baselines/reference/api/typescript.d.ts | 40 ++++++++++++ 3 files changed, 136 insertions(+), 5 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8de82631fb..09e89b29e2 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4715,6 +4715,62 @@ namespace ts { } namespace ts { + export interface FileSystemEntries { + /** + * The file names discovered within a parent directory. Each entry includes the base name and extension of the file, but does + * not include the parent path. + */ + readonly files: readonly string[]; + /** + * The directory names discovered within a parent directory. Each entry includes the base name and extension of the file, but + * does not include the parent path. + */ + readonly directories: readonly string[]; + } + + export interface FileMatcherHost { + useCaseSensitiveFileNames: boolean; + getCurrentDirectory(): string; + /** + * Gets the accessible file and directory names within a path, grouped by their kind. + * @param path The directory from which to retrieve entries. + */ + getAccessibleFileSystemEntries(path: string): FileSystemEntries; + realpath?(path: string): string; + } + + export interface FileMatcherOptions { + /** The set of extensions used to match files. */ + extensions?: readonly string[]; + /** A set of glob paths that should be excluded from the result. */ + exclude?: readonly string[]; + /** A set of glob paths that should be included in the result. */ + include?: readonly string[]; + /** The maximum depth at which to stop traversing the file system. */ + depth?: number; + } + + /** + * Finds matching files based on the provided options. + * @param path The directory in which to start matching. + * @param options The options used to control matching. + * @param host The host used to traverse the file system. + * @returns The fully qualified paths of the matching files. + */ + export function getMatchingFiles(path: string, options: FileMatcherOptions, host: FileMatcherHost): string[] { + return matchFiles( + path, + options.extensions, + options.exclude, + options.include, + host.useCaseSensitiveFileNames, + host.getCurrentDirectory(), + options.depth, + path => host.getAccessibleFileSystemEntries(path), + path => host.realpath ? host.realpath(path) : path + ); + } + export function getDefaultLibFileName(options: CompilerOptions): string { switch (options.target) { case ScriptTarget.ESNext: @@ -8164,11 +8220,6 @@ namespace ts { return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match; } - export interface FileSystemEntries { - readonly files: ReadonlyArray; - readonly directories: ReadonlyArray; - } - export interface FileMatcherPatterns { /** One pattern for each "include" spec. */ includeFilePatterns: ReadonlyArray | undefined; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index bffe2114d1..5862558cb7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3233,6 +3233,46 @@ declare namespace ts { function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): SortedReadonlyArray; } declare namespace ts { + interface FileSystemEntries { + /** + * The file names discovered within a parent directory. Each entry includes the base name and extension of the file, but does + * not include the parent path. + */ + readonly files: readonly string[]; + /** + * The directory names discovered within a parent directory. Each entry includes the base name and extension of the file, but + * does not include the parent path. + */ + readonly directories: readonly string[]; + } + interface FileMatcherHost { + useCaseSensitiveFileNames: boolean; + getCurrentDirectory(): string; + /** + * Gets the accessible file and directory names within a path, grouped by their kind. + * @param path The directory from which to retrieve entries. + */ + getAccessibleFileSystemEntries(path: string): FileSystemEntries; + realpath?(path: string): string; + } + interface FileMatcherOptions { + /** The set of extensions used to match files. */ + extensions?: readonly string[]; + /** A set of glob paths that should be excluded from the result. */ + exclude?: readonly string[]; + /** A set of glob paths that should be included in the result. */ + include?: readonly string[]; + /** The maximum depth at which to stop traversing the file system. */ + depth?: number; + } + /** + * Finds matching files based on the provided options. + * @param path The directory in which to start matching. + * @param options The options used to control matching. + * @param host The host used to traverse the file system. + * @returns The fully qualified paths of the matching files. + */ + function getMatchingFiles(path: string, options: FileMatcherOptions, host: FileMatcherHost): string[]; function getDefaultLibFileName(options: CompilerOptions): string; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 457a1acb22..c5cbcd2387 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3233,6 +3233,46 @@ declare namespace ts { function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): SortedReadonlyArray; } declare namespace ts { + interface FileSystemEntries { + /** + * The file names discovered within a parent directory. Each entry includes the base name and extension of the file, but does + * not include the parent path. + */ + readonly files: readonly string[]; + /** + * The directory names discovered within a parent directory. Each entry includes the base name and extension of the file, but + * does not include the parent path. + */ + readonly directories: readonly string[]; + } + interface FileMatcherHost { + useCaseSensitiveFileNames: boolean; + getCurrentDirectory(): string; + /** + * Gets the accessible file and directory names within a path, grouped by their kind. + * @param path The directory from which to retrieve entries. + */ + getAccessibleFileSystemEntries(path: string): FileSystemEntries; + realpath?(path: string): string; + } + interface FileMatcherOptions { + /** The set of extensions used to match files. */ + extensions?: readonly string[]; + /** A set of glob paths that should be excluded from the result. */ + exclude?: readonly string[]; + /** A set of glob paths that should be included in the result. */ + include?: readonly string[]; + /** The maximum depth at which to stop traversing the file system. */ + depth?: number; + } + /** + * Finds matching files based on the provided options. + * @param path The directory in which to start matching. + * @param options The options used to control matching. + * @param host The host used to traverse the file system. + * @returns The fully qualified paths of the matching files. + */ + function getMatchingFiles(path: string, options: FileMatcherOptions, host: FileMatcherHost): string[]; function getDefaultLibFileName(options: CompilerOptions): string; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean;