Skip to content

Commit 1298f49

Browse files
authored
Revert changes to matchFiles/readDirectory made since 4.3 (#46787)
* Revert "Fix RWC missing file detection (#46673)" This reverts commit 4a065f5. * Revert "Pass absolute path to directoryExists (#46086)" This reverts commit 55b4928. * Revert "Reduce exceptions (#44710)" This reverts commit c0d5c29. * Add back system watcher limit
1 parent 7b86a65 commit 1298f49

File tree

7 files changed

+20
-55
lines changed

7 files changed

+20
-55
lines changed

src/compiler/sys.ts

Lines changed: 1 addition & 2 deletions
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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6629,7 +6629,7 @@ namespace ts {
66296629
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
66306630
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
66316631
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
6632-
basePaths: getBasePaths(absolutePath, includes, useCaseSensitiveFileNames)
6632+
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
66336633
};
66346634
}
66356635

@@ -6638,7 +6638,7 @@ namespace ts {
66386638
}
66396639

66406640
/** @param path directory of the tsconfig.json */
6641-
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[] {
6641+
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[] {
66426642
path = normalizePath(path);
66436643
currentDirectory = normalizePath(currentDirectory);
66446644

@@ -6653,22 +6653,20 @@ namespace ts {
66536653
const results: string[][] = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
66546654
const visited = new Map<string, true>();
66556655
const toCanonical = createGetCanonicalFileName(useCaseSensitiveFileNames);
6656-
for (const absoluteBasePath of patterns.basePaths) {
6657-
if (directoryExists(absoluteBasePath)) {
6658-
visitDirectory(absoluteBasePath, depth);
6659-
}
6656+
for (const basePath of patterns.basePaths) {
6657+
visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
66606658
}
66616659

66626660
return flatten(results);
66636661

6664-
function visitDirectory(absolutePath: string, depth: number | undefined) {
6662+
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
66656663
const canonicalPath = toCanonical(realpath(absolutePath));
66666664
if (visited.has(canonicalPath)) return;
66676665
visited.set(canonicalPath, true);
6668-
const { files, directories } = getFileSystemEntries(absolutePath);
6666+
const { files, directories } = getFileSystemEntries(path);
66696667

66706668
for (const current of sort<string>(files, compareStringsCaseSensitive)) {
6671-
const name = combinePaths(absolutePath, current);
6669+
const name = combinePaths(path, current);
66726670
const absoluteName = combinePaths(absolutePath, current);
66736671
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
66746672
if (excludeRegex && excludeRegex.test(absoluteName)) continue;
@@ -6691,32 +6689,32 @@ namespace ts {
66916689
}
66926690

66936691
for (const current of sort<string>(directories, compareStringsCaseSensitive)) {
6692+
const name = combinePaths(path, current);
66946693
const absoluteName = combinePaths(absolutePath, current);
66956694
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
66966695
(!excludeRegex || !excludeRegex.test(absoluteName))) {
6697-
visitDirectory(absoluteName, depth);
6696+
visitDirectory(name, absoluteName, depth);
66986697
}
66996698
}
67006699
}
67016700
}
67026701

67036702
/**
67046703
* Computes the unique non-wildcard base paths amongst the provided include patterns.
6705-
* @returns Absolute directory paths
67066704
*/
6707-
function getBasePaths(absoluteTsconfigPath: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
6705+
function getBasePaths(path: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
67086706
// Storage for our results in the form of literal paths (e.g. the paths as written by the user).
6709-
const basePaths: string[] = [absoluteTsconfigPath];
6707+
const basePaths: string[] = [path];
67106708

67116709
if (includes) {
67126710
// Storage for literal base paths amongst the include patterns.
67136711
const includeBasePaths: string[] = [];
67146712
for (const include of includes) {
67156713
// We also need to check the relative paths by converting them to absolute and normalizing
67166714
// in case they escape the base path (e.g "..\somedirectory")
6717-
const absoluteIncludePath: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(absoluteTsconfigPath, include));
6715+
const absolute: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include));
67186716
// Append the literal and canonical candidate base paths.
6719-
includeBasePaths.push(getIncludeBasePath(absoluteIncludePath));
6717+
includeBasePaths.push(getIncludeBasePath(absolute));
67206718
}
67216719

67226720
// Sort the offsets array using either the literal or canonical path representations.
@@ -6725,7 +6723,7 @@ namespace ts {
67256723
// Iterate over each include base path and include unique base paths that are not a
67266724
// subpath of an existing base path
67276725
for (const includeBasePath of includeBasePaths) {
6728-
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, absoluteTsconfigPath, !useCaseSensitiveFileNames))) {
6726+
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) {
67296727
basePaths.push(includeBasePath);
67306728
}
67316729
}

src/compiler/watchUtilities.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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/harnessIO.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,15 +1438,14 @@ namespace Harness {
14381438
}
14391439

14401440
const referenceDir = referencePath(relativeFileBase, opts && opts.Baselinefolder, opts && opts.Subfolder);
1441-
let existing = IO.readDirectory(referenceDir, referencedExtensions || [extension]); // always an _absolute_ path
1441+
let existing = IO.readDirectory(referenceDir, referencedExtensions || [extension]);
14421442
if (extension === ".ts" || referencedExtensions && referencedExtensions.indexOf(".ts") > -1 && referencedExtensions.indexOf(".d.ts") === -1) {
14431443
// special-case and filter .d.ts out of .ts results
14441444
existing = existing.filter(f => !ts.endsWith(f, ".d.ts"));
14451445
}
14461446
const missing: string[] = [];
1447-
const absoluteTestDir = `${process.cwd()}/${referenceDir}`;
14481447
for (const name of existing) {
1449-
const localCopy = name.substring(absoluteTestDir.length - relativeFileBase.length);
1448+
const localCopy = name.substring(referenceDir.length - relativeFileBase.length);
14501449
if (!writtenFiles.has(localCopy)) {
14511450
missing.push(localCopy);
14521451
}

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 31 deletions
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)