GeezerVison is showing github.com — Cherry-pick PR #46787 into release-4.5 (#46789) · microsoft/TypeScript@460515f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/compiler/sys.ts +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1625,7 +1625,6 @@ namespace ts { | 1625 | 1625 | sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`); | 1626 | 1626 | return watchPresentFileSystemEntryWithFsWatchFile(); | 1627 | 1627 | } | 1628 | | - | 1629 | 1628 | try { | 1630 | 1629 | const presentWatcher = _fs.watch( | 1631 | 1630 | fileOrDirectory, | @@ -1804,7 +1803,7 @@ namespace ts { | 1804 | 1803 | } | 1805 | 1804 |
| 1806 | 1805 | function readDirectory(path: string, extensions?: readonly string[], excludes?: readonly string[], includes?: readonly string[], depth?: number): string[] { | 1807 | | - return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries, realpath, directoryExists); | | 1806 | + return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries, realpath); | 1808 | 1807 | } | 1809 | 1808 |
| 1810 | 1809 | function fileSystemEntryExists(path: string, entryKind: FileSystemEntryKind): boolean { | |
Collapse file Copy file name to clipboardExpand all lines: src/compiler/utilities.ts +14-16Lines changed: 14 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6615,7 +6615,7 @@ namespace ts { | 6615 | 6615 | includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"), | 6616 | 6616 | includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"), | 6617 | 6617 | excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"), | 6618 | | - basePaths: getBasePaths(absolutePath, includes, useCaseSensitiveFileNames) | | 6618 | + basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames) | 6619 | 6619 | }; | 6620 | 6620 | } | 6621 | 6621 |
| @@ -6624,7 +6624,7 @@ namespace ts { | 6624 | 6624 | } | 6625 | 6625 |
| 6626 | 6626 | /** @param path directory of the tsconfig.json */ | 6627 | | - export function matchFiles(path: string, extensions: readonly string[] | undefined, excludes: readonly string[] | undefined, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number | undefined, getFileSystemEntries: (path: string) => FileSystemEntries, realpath: (path: string) => string, directoryExists: (path: string) => boolean): string[] { | | 6627 | + export function matchFiles(path: string, extensions: readonly string[] | undefined, excludes: readonly string[] | undefined, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number | undefined, getFileSystemEntries: (path: string) => FileSystemEntries, realpath: (path: string) => string): string[] { | 6628 | 6628 | path = normalizePath(path); | 6629 | 6629 | currentDirectory = normalizePath(currentDirectory); | 6630 | 6630 |
| @@ -6639,22 +6639,20 @@ namespace ts { | 6639 | 6639 | const results: string[][] = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]]; | 6640 | 6640 | const visited = new Map<string, true>(); | 6641 | 6641 | const toCanonical = createGetCanonicalFileName(useCaseSensitiveFileNames); | 6642 | | - for (const absoluteBasePath of patterns.basePaths) { | 6643 | | - if (directoryExists(absoluteBasePath)) { | 6644 | | - visitDirectory(absoluteBasePath, depth); | 6645 | | - } | | 6642 | + for (const basePath of patterns.basePaths) { | | 6643 | + visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth); | 6646 | 6644 | } | 6647 | 6645 |
| 6648 | 6646 | return flatten(results); | 6649 | 6647 |
| 6650 | | - function visitDirectory(absolutePath: string, depth: number | undefined) { | | 6648 | + function visitDirectory(path: string, absolutePath: string, depth: number | undefined) { | 6651 | 6649 | const canonicalPath = toCanonical(realpath(absolutePath)); | 6652 | 6650 | if (visited.has(canonicalPath)) return; | 6653 | 6651 | visited.set(canonicalPath, true); | 6654 | | - const { files, directories } = getFileSystemEntries(absolutePath); | | 6652 | + const { files, directories } = getFileSystemEntries(path); | 6655 | 6653 |
| 6656 | 6654 | for (const current of sort<string>(files, compareStringsCaseSensitive)) { | 6657 | | - const name = combinePaths(absolutePath, current); | | 6655 | + const name = combinePaths(path, current); | 6658 | 6656 | const absoluteName = combinePaths(absolutePath, current); | 6659 | 6657 | if (extensions && !fileExtensionIsOneOf(name, extensions)) continue; | 6660 | 6658 | if (excludeRegex && excludeRegex.test(absoluteName)) continue; | @@ -6677,32 +6675,32 @@ namespace ts { | 6677 | 6675 | } | 6678 | 6676 |
| 6679 | 6677 | for (const current of sort<string>(directories, compareStringsCaseSensitive)) { | | 6678 | + const name = combinePaths(path, current); | 6680 | 6679 | const absoluteName = combinePaths(absolutePath, current); | 6681 | 6680 | if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) && | 6682 | 6681 | (!excludeRegex || !excludeRegex.test(absoluteName))) { | 6683 | | - visitDirectory(absoluteName, depth); | | 6682 | + visitDirectory(name, absoluteName, depth); | 6684 | 6683 | } | 6685 | 6684 | } | 6686 | 6685 | } | 6687 | 6686 | } | 6688 | 6687 |
| 6689 | 6688 | /** | 6690 | 6689 | * Computes the unique non-wildcard base paths amongst the provided include patterns. | 6691 | | - * @returns Absolute directory paths | 6692 | 6690 | */ | 6693 | | - function getBasePaths(absoluteTsconfigPath: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] { | | 6691 | + function getBasePaths(path: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] { | 6694 | 6692 | // Storage for our results in the form of literal paths (e.g. the paths as written by the user). | 6695 | | - const basePaths: string[] = [absoluteTsconfigPath]; | | 6693 | + const basePaths: string[] = [path]; | 6696 | 6694 |
| 6697 | 6695 | if (includes) { | 6698 | 6696 | // Storage for literal base paths amongst the include patterns. | 6699 | 6697 | const includeBasePaths: string[] = []; | 6700 | 6698 | for (const include of includes) { | 6701 | 6699 | // We also need to check the relative paths by converting them to absolute and normalizing | 6702 | 6700 | // in case they escape the base path (e.g "..\somedirectory") | 6703 | | - const absoluteIncludePath: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(absoluteTsconfigPath, include)); | | 6701 | + const absolute: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include)); | 6704 | 6702 | // Append the literal and canonical candidate base paths. | 6705 | | - includeBasePaths.push(getIncludeBasePath(absoluteIncludePath)); | | 6703 | + includeBasePaths.push(getIncludeBasePath(absolute)); | 6706 | 6704 | } | 6707 | 6705 |
| 6708 | 6706 | // Sort the offsets array using either the literal or canonical path representations. | @@ -6711,7 +6709,7 @@ namespace ts { | 6711 | 6709 | // Iterate over each include base path and include unique base paths that are not a | 6712 | 6710 | // subpath of an existing base path | 6713 | 6711 | for (const includeBasePath of includeBasePaths) { | 6714 | | - if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, absoluteTsconfigPath, !useCaseSensitiveFileNames))) { | | 6712 | + if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) { | 6715 | 6713 | basePaths.push(includeBasePath); | 6716 | 6714 | } | 6717 | 6715 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/compiler/watchUtilities.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -184,7 +184,7 @@ namespace ts { | 184 | 184 | const rootResult = tryReadDirectory(rootDir, rootDirPath); | 185 | 185 | let rootSymLinkResult: FileSystemEntries | undefined; | 186 | 186 | if (rootResult !== undefined) { | 187 | | - return matchFiles(rootDir, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath, directoryExists); | | 187 | + return matchFiles(rootDir, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath); | 188 | 188 | } | 189 | 189 | return host.readDirectory!(rootDir, extensions, excludes, includes, depth); | 190 | 190 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/harness/fakesHosts.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -95,7 +95,7 @@ namespace fakes { | 95 | 95 | } | 96 | 96 |
| 97 | 97 | public readDirectory(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[] { | 98 | | - return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, path => this.getAccessibleFileSystemEntries(path), path => this.realpath(path), path => this.directoryExists(path)); | | 98 | + return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, path => this.getAccessibleFileSystemEntries(path), path => this.realpath(path)); | 99 | 99 | } | 100 | 100 |
| 101 | 101 | public getAccessibleFileSystemEntries(path: string): ts.FileSystemEntries { | |
Collapse file Copy file name to clipboardExpand all lines: src/harness/virtualFileSystemWithWatch.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -922,7 +922,7 @@ interface Array<T> { length: number; [n: number]: T; }` | 922 | 922 | }); | 923 | 923 | } | 924 | 924 | return { directories, files }; | 925 | | - }, path => this.realpath(path), path => this.directoryExists(path)); | | 925 | + }, path => this.realpath(path)); | 926 | 926 | } | 927 | 927 |
| 928 | 928 | createHash(s: string): string { | |
Collapse file Copy file name to clipboardExpand all lines: src/testRunner/unittests/publicApi.ts -31Lines changed: 0 additions & 31 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -182,34 +182,3 @@ describe("unittests:: Public APIs:: getChild* methods on EndOfFileToken with JSD | 182 | 182 | assert.equal(endOfFileToken.getChildCount(), 1); | 183 | 183 | assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined); | 184 | 184 | }); | 185 | | - | 186 | | -describe("unittests:: Public APIs:: sys", () => { | 187 | | - it("readDirectory", () => { | 188 | | - // #45990, testing passing a non-absolute path | 189 | | - // `sys.readDirectory` is just `matchFiles` plugged into the real FS | 190 | | - const read = ts.matchFiles( | 191 | | - /*path*/ "", | 192 | | - /*extensions*/ [".ts", ".tsx"], | 193 | | - /*excludes*/ ["node_modules", "dist"], | 194 | | - /*includes*/ ["**/*"], | 195 | | - /*useCaseSensitiveFileNames*/ true, | 196 | | - /*currentDirectory*/ "/", | 197 | | - /*depth*/ undefined, | 198 | | - /*getFileSystemEntries*/ path => { | 199 | | - switch (path) { | 200 | | - case "/": return { directories: [], files: ["file.ts"] }; | 201 | | - default: return { directories: [], files: [] }; | 202 | | - } | 203 | | - }, | 204 | | - /*realpath*/ ts.identity, | 205 | | - /*directoryExists*/ path => { | 206 | | - switch (path) { | 207 | | - case "/": return true; | 208 | | - default: return false; | 209 | | - } | 210 | | - } | 211 | | - ); | 212 | | - | 213 | | - assert.deepEqual(read, ["/file.ts"]); | 214 | | - }); | 215 | | -}); |
|