Skip to content

Commit 460515f

Browse files
TypeScript Botandrewbranch
TypeScript Bot
andauthored
Cherry-pick PR #46787 into release-4.5 (#46789)
Component commits: 931b504 Revert "Fix RWC missing file detection (#46673)" This reverts commit 4a065f5. afef282 Revert "Pass absolute path to directoryExists (#46086)" This reverts commit 55b4928. f1a20b3 Revert "Reduce exceptions (#44710)" This reverts commit c0d5c29. 56842cd Add back system watcher limit Co-authored-by: Andrew Branch <[email protected]>
1 parent ec158f9 commit 460515f

File tree

6 files changed

+18
-52
lines changed

6 files changed

+18
-52
lines changed

src/compiler/sys.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,6 @@ namespace ts {
16251625
sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`);
16261626
return watchPresentFileSystemEntryWithFsWatchFile();
16271627
}
1628-
16291628
try {
16301629
const presentWatcher = _fs.watch(
16311630
fileOrDirectory,
@@ -1804,7 +1803,7 @@ namespace ts {
18041803
}
18051804

18061805
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);
18081807
}
18091808

18101809
function fileSystemEntryExists(path: string, entryKind: FileSystemEntryKind): boolean {

src/compiler/utilities.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -6615,7 +6615,7 @@ namespace ts {
66156615
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
66166616
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
66176617
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
6618-
basePaths: getBasePaths(absolutePath, includes, useCaseSensitiveFileNames)
6618+
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
66196619
};
66206620
}
66216621

@@ -6624,7 +6624,7 @@ namespace ts {
66246624
}
66256625

66266626
/** @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[] {
66286628
path = normalizePath(path);
66296629
currentDirectory = normalizePath(currentDirectory);
66306630

@@ -6639,22 +6639,20 @@ namespace ts {
66396639
const results: string[][] = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
66406640
const visited = new Map<string, true>();
66416641
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);
66466644
}
66476645

66486646
return flatten(results);
66496647

6650-
function visitDirectory(absolutePath: string, depth: number | undefined) {
6648+
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
66516649
const canonicalPath = toCanonical(realpath(absolutePath));
66526650
if (visited.has(canonicalPath)) return;
66536651
visited.set(canonicalPath, true);
6654-
const { files, directories } = getFileSystemEntries(absolutePath);
6652+
const { files, directories } = getFileSystemEntries(path);
66556653

66566654
for (const current of sort<string>(files, compareStringsCaseSensitive)) {
6657-
const name = combinePaths(absolutePath, current);
6655+
const name = combinePaths(path, current);
66586656
const absoluteName = combinePaths(absolutePath, current);
66596657
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
66606658
if (excludeRegex && excludeRegex.test(absoluteName)) continue;
@@ -6677,32 +6675,32 @@ namespace ts {
66776675
}
66786676

66796677
for (const current of sort<string>(directories, compareStringsCaseSensitive)) {
6678+
const name = combinePaths(path, current);
66806679
const absoluteName = combinePaths(absolutePath, current);
66816680
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
66826681
(!excludeRegex || !excludeRegex.test(absoluteName))) {
6683-
visitDirectory(absoluteName, depth);
6682+
visitDirectory(name, absoluteName, depth);
66846683
}
66856684
}
66866685
}
66876686
}
66886687

66896688
/**
66906689
* Computes the unique non-wildcard base paths amongst the provided include patterns.
6691-
* @returns Absolute directory paths
66926690
*/
6693-
function getBasePaths(absoluteTsconfigPath: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
6691+
function getBasePaths(path: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
66946692
// 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];
66966694

66976695
if (includes) {
66986696
// Storage for literal base paths amongst the include patterns.
66996697
const includeBasePaths: string[] = [];
67006698
for (const include of includes) {
67016699
// We also need to check the relative paths by converting them to absolute and normalizing
67026700
// 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));
67046702
// Append the literal and canonical candidate base paths.
6705-
includeBasePaths.push(getIncludeBasePath(absoluteIncludePath));
6703+
includeBasePaths.push(getIncludeBasePath(absolute));
67066704
}
67076705

67086706
// Sort the offsets array using either the literal or canonical path representations.
@@ -6711,7 +6709,7 @@ namespace ts {
67116709
// Iterate over each include base path and include unique base paths that are not a
67126710
// subpath of an existing base path
67136711
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))) {
67156713
basePaths.push(includeBasePath);
67166714
}
67176715
}

src/compiler/watchUtilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace ts {
184184
const rootResult = tryReadDirectory(rootDir, rootDirPath);
185185
let rootSymLinkResult: FileSystemEntries | undefined;
186186
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);
188188
}
189189
return host.readDirectory!(rootDir, extensions, excludes, includes, depth);
190190

src/harness/fakesHosts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace fakes {
9595
}
9696

9797
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));
9999
}
100100

101101
public getAccessibleFileSystemEntries(path: string): ts.FileSystemEntries {

src/harness/virtualFileSystemWithWatch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ interface Array<T> { length: number; [n: number]: T; }`
922922
});
923923
}
924924
return { directories, files };
925-
}, path => this.realpath(path), path => this.directoryExists(path));
925+
}, path => this.realpath(path));
926926
}
927927

928928
createHash(s: string): string {

src/testRunner/unittests/publicApi.ts

-31
Original file line numberDiff line numberDiff line change
@@ -182,34 +182,3 @@ describe("unittests:: Public APIs:: getChild* methods on EndOfFileToken with JSD
182182
assert.equal(endOfFileToken.getChildCount(), 1);
183183
assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined);
184184
});
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-
});

0 commit comments

Comments
 (0)