Revert changes to matchFiles/readDirectory made since 4.3 (#46787)
* Revert "Fix RWC missing file detection (#46673)" This reverts commit4a065f524c
. * Revert "Pass absolute path to directoryExists (#46086)" This reverts commit55b4928e82
. * Revert "Reduce exceptions (#44710)" This reverts commitc0d5c29080
. * Add back system watcher limit
This commit is contained in:
parent
7b86a65f22
commit
1298f498f4
|
@ -1625,7 +1625,6 @@ namespace ts {
|
||||||
sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`);
|
sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`);
|
||||||
return watchPresentFileSystemEntryWithFsWatchFile();
|
return watchPresentFileSystemEntryWithFsWatchFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const presentWatcher = _fs.watch(
|
const presentWatcher = _fs.watch(
|
||||||
fileOrDirectory,
|
fileOrDirectory,
|
||||||
|
@ -1804,7 +1803,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function readDirectory(path: string, extensions?: readonly string[], excludes?: readonly string[], includes?: readonly string[], depth?: number): string[] {
|
function readDirectory(path: string, extensions?: readonly string[], excludes?: readonly string[], includes?: readonly string[], depth?: number): string[] {
|
||||||
return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries, realpath, directoryExists);
|
return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries, realpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fileSystemEntryExists(path: string, entryKind: FileSystemEntryKind): boolean {
|
function fileSystemEntryExists(path: string, entryKind: FileSystemEntryKind): boolean {
|
||||||
|
|
|
@ -6629,7 +6629,7 @@ namespace ts {
|
||||||
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
|
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
|
||||||
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
|
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
|
||||||
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
|
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
|
||||||
basePaths: getBasePaths(absolutePath, includes, useCaseSensitiveFileNames)
|
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6638,7 +6638,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param path directory of the tsconfig.json */
|
/** @param path directory of the tsconfig.json */
|
||||||
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[] {
|
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[] {
|
||||||
path = normalizePath(path);
|
path = normalizePath(path);
|
||||||
currentDirectory = normalizePath(currentDirectory);
|
currentDirectory = normalizePath(currentDirectory);
|
||||||
|
|
||||||
|
@ -6653,22 +6653,20 @@ namespace ts {
|
||||||
const results: string[][] = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
|
const results: string[][] = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
|
||||||
const visited = new Map<string, true>();
|
const visited = new Map<string, true>();
|
||||||
const toCanonical = createGetCanonicalFileName(useCaseSensitiveFileNames);
|
const toCanonical = createGetCanonicalFileName(useCaseSensitiveFileNames);
|
||||||
for (const absoluteBasePath of patterns.basePaths) {
|
for (const basePath of patterns.basePaths) {
|
||||||
if (directoryExists(absoluteBasePath)) {
|
visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
|
||||||
visitDirectory(absoluteBasePath, depth);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return flatten(results);
|
return flatten(results);
|
||||||
|
|
||||||
function visitDirectory(absolutePath: string, depth: number | undefined) {
|
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
|
||||||
const canonicalPath = toCanonical(realpath(absolutePath));
|
const canonicalPath = toCanonical(realpath(absolutePath));
|
||||||
if (visited.has(canonicalPath)) return;
|
if (visited.has(canonicalPath)) return;
|
||||||
visited.set(canonicalPath, true);
|
visited.set(canonicalPath, true);
|
||||||
const { files, directories } = getFileSystemEntries(absolutePath);
|
const { files, directories } = getFileSystemEntries(path);
|
||||||
|
|
||||||
for (const current of sort<string>(files, compareStringsCaseSensitive)) {
|
for (const current of sort<string>(files, compareStringsCaseSensitive)) {
|
||||||
const name = combinePaths(absolutePath, current);
|
const name = combinePaths(path, current);
|
||||||
const absoluteName = combinePaths(absolutePath, current);
|
const absoluteName = combinePaths(absolutePath, current);
|
||||||
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
|
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
|
||||||
if (excludeRegex && excludeRegex.test(absoluteName)) continue;
|
if (excludeRegex && excludeRegex.test(absoluteName)) continue;
|
||||||
|
@ -6691,10 +6689,11 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const current of sort<string>(directories, compareStringsCaseSensitive)) {
|
for (const current of sort<string>(directories, compareStringsCaseSensitive)) {
|
||||||
|
const name = combinePaths(path, current);
|
||||||
const absoluteName = combinePaths(absolutePath, current);
|
const absoluteName = combinePaths(absolutePath, current);
|
||||||
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
|
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
|
||||||
(!excludeRegex || !excludeRegex.test(absoluteName))) {
|
(!excludeRegex || !excludeRegex.test(absoluteName))) {
|
||||||
visitDirectory(absoluteName, depth);
|
visitDirectory(name, absoluteName, depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6702,11 +6701,10 @@ namespace ts {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the unique non-wildcard base paths amongst the provided include patterns.
|
* Computes the unique non-wildcard base paths amongst the provided include patterns.
|
||||||
* @returns Absolute directory paths
|
|
||||||
*/
|
*/
|
||||||
function getBasePaths(absoluteTsconfigPath: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
|
function getBasePaths(path: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
|
||||||
// Storage for our results in the form of literal paths (e.g. the paths as written by the user).
|
// Storage for our results in the form of literal paths (e.g. the paths as written by the user).
|
||||||
const basePaths: string[] = [absoluteTsconfigPath];
|
const basePaths: string[] = [path];
|
||||||
|
|
||||||
if (includes) {
|
if (includes) {
|
||||||
// Storage for literal base paths amongst the include patterns.
|
// Storage for literal base paths amongst the include patterns.
|
||||||
|
@ -6714,9 +6712,9 @@ namespace ts {
|
||||||
for (const include of includes) {
|
for (const include of includes) {
|
||||||
// We also need to check the relative paths by converting them to absolute and normalizing
|
// We also need to check the relative paths by converting them to absolute and normalizing
|
||||||
// in case they escape the base path (e.g "..\somedirectory")
|
// in case they escape the base path (e.g "..\somedirectory")
|
||||||
const absoluteIncludePath: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(absoluteTsconfigPath, include));
|
const absolute: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include));
|
||||||
// Append the literal and canonical candidate base paths.
|
// Append the literal and canonical candidate base paths.
|
||||||
includeBasePaths.push(getIncludeBasePath(absoluteIncludePath));
|
includeBasePaths.push(getIncludeBasePath(absolute));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the offsets array using either the literal or canonical path representations.
|
// Sort the offsets array using either the literal or canonical path representations.
|
||||||
|
@ -6725,7 +6723,7 @@ namespace ts {
|
||||||
// Iterate over each include base path and include unique base paths that are not a
|
// Iterate over each include base path and include unique base paths that are not a
|
||||||
// subpath of an existing base path
|
// subpath of an existing base path
|
||||||
for (const includeBasePath of includeBasePaths) {
|
for (const includeBasePath of includeBasePaths) {
|
||||||
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, absoluteTsconfigPath, !useCaseSensitiveFileNames))) {
|
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) {
|
||||||
basePaths.push(includeBasePath);
|
basePaths.push(includeBasePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ namespace ts {
|
||||||
const rootResult = tryReadDirectory(rootDir, rootDirPath);
|
const rootResult = tryReadDirectory(rootDir, rootDirPath);
|
||||||
let rootSymLinkResult: FileSystemEntries | undefined;
|
let rootSymLinkResult: FileSystemEntries | undefined;
|
||||||
if (rootResult !== undefined) {
|
if (rootResult !== undefined) {
|
||||||
return matchFiles(rootDir, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath, directoryExists);
|
return matchFiles(rootDir, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath);
|
||||||
}
|
}
|
||||||
return host.readDirectory!(rootDir, extensions, excludes, includes, depth);
|
return host.readDirectory!(rootDir, extensions, excludes, includes, depth);
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace fakes {
|
||||||
}
|
}
|
||||||
|
|
||||||
public readDirectory(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[] {
|
public readDirectory(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[] {
|
||||||
return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, path => this.getAccessibleFileSystemEntries(path), path => this.realpath(path), path => this.directoryExists(path));
|
return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, path => this.getAccessibleFileSystemEntries(path), path => this.realpath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAccessibleFileSystemEntries(path: string): ts.FileSystemEntries {
|
public getAccessibleFileSystemEntries(path: string): ts.FileSystemEntries {
|
||||||
|
|
|
@ -1438,15 +1438,14 @@ namespace Harness {
|
||||||
}
|
}
|
||||||
|
|
||||||
const referenceDir = referencePath(relativeFileBase, opts && opts.Baselinefolder, opts && opts.Subfolder);
|
const referenceDir = referencePath(relativeFileBase, opts && opts.Baselinefolder, opts && opts.Subfolder);
|
||||||
let existing = IO.readDirectory(referenceDir, referencedExtensions || [extension]); // always an _absolute_ path
|
let existing = IO.readDirectory(referenceDir, referencedExtensions || [extension]);
|
||||||
if (extension === ".ts" || referencedExtensions && referencedExtensions.indexOf(".ts") > -1 && referencedExtensions.indexOf(".d.ts") === -1) {
|
if (extension === ".ts" || referencedExtensions && referencedExtensions.indexOf(".ts") > -1 && referencedExtensions.indexOf(".d.ts") === -1) {
|
||||||
// special-case and filter .d.ts out of .ts results
|
// special-case and filter .d.ts out of .ts results
|
||||||
existing = existing.filter(f => !ts.endsWith(f, ".d.ts"));
|
existing = existing.filter(f => !ts.endsWith(f, ".d.ts"));
|
||||||
}
|
}
|
||||||
const missing: string[] = [];
|
const missing: string[] = [];
|
||||||
const absoluteTestDir = `${process.cwd()}/${referenceDir}`;
|
|
||||||
for (const name of existing) {
|
for (const name of existing) {
|
||||||
const localCopy = name.substring(absoluteTestDir.length - relativeFileBase.length);
|
const localCopy = name.substring(referenceDir.length - relativeFileBase.length);
|
||||||
if (!writtenFiles.has(localCopy)) {
|
if (!writtenFiles.has(localCopy)) {
|
||||||
missing.push(localCopy);
|
missing.push(localCopy);
|
||||||
}
|
}
|
||||||
|
|
|
@ -922,7 +922,7 @@ interface Array<T> { length: number; [n: number]: T; }`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { directories, files };
|
return { directories, files };
|
||||||
}, path => this.realpath(path), path => this.directoryExists(path));
|
}, path => this.realpath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
createHash(s: string): string {
|
createHash(s: string): string {
|
||||||
|
|
|
@ -182,34 +182,3 @@ describe("unittests:: Public APIs:: getChild* methods on EndOfFileToken with JSD
|
||||||
assert.equal(endOfFileToken.getChildCount(), 1);
|
assert.equal(endOfFileToken.getChildCount(), 1);
|
||||||
assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined);
|
assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("unittests:: Public APIs:: sys", () => {
|
|
||||||
it("readDirectory", () => {
|
|
||||||
// #45990, testing passing a non-absolute path
|
|
||||||
// `sys.readDirectory` is just `matchFiles` plugged into the real FS
|
|
||||||
const read = ts.matchFiles(
|
|
||||||
/*path*/ "",
|
|
||||||
/*extensions*/ [".ts", ".tsx"],
|
|
||||||
/*excludes*/ ["node_modules", "dist"],
|
|
||||||
/*includes*/ ["**/*"],
|
|
||||||
/*useCaseSensitiveFileNames*/ true,
|
|
||||||
/*currentDirectory*/ "/",
|
|
||||||
/*depth*/ undefined,
|
|
||||||
/*getFileSystemEntries*/ path => {
|
|
||||||
switch (path) {
|
|
||||||
case "/": return { directories: [], files: ["file.ts"] };
|
|
||||||
default: return { directories: [], files: [] };
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/*realpath*/ ts.identity,
|
|
||||||
/*directoryExists*/ path => {
|
|
||||||
switch (path) {
|
|
||||||
case "/": return true;
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.deepEqual(read, ["/file.ts"]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue