Skip to content

Commit afef282

Browse files
committed
Revert "Pass absolute path to directoryExists (microsoft#46086)"
This reverts commit 55b4928.
1 parent 931b504 commit afef282

File tree

2 files changed

+14
-45
lines changed

2 files changed

+14
-45
lines changed

src/compiler/utilities.ts

+14-14
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

@@ -6653,22 +6653,22 @@ 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);
6656+
for (const basePath of patterns.basePaths) {
6657+
if (directoryExists(basePath)) {
6658+
visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
66596659
}
66606660
}
66616661

66626662
return flatten(results);
66636663

6664-
function visitDirectory(absolutePath: string, depth: number | undefined) {
6664+
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
66656665
const canonicalPath = toCanonical(realpath(absolutePath));
66666666
if (visited.has(canonicalPath)) return;
66676667
visited.set(canonicalPath, true);
6668-
const { files, directories } = getFileSystemEntries(absolutePath);
6668+
const { files, directories } = getFileSystemEntries(path);
66696669

66706670
for (const current of sort<string>(files, compareStringsCaseSensitive)) {
6671-
const name = combinePaths(absolutePath, current);
6671+
const name = combinePaths(path, current);
66726672
const absoluteName = combinePaths(absolutePath, current);
66736673
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
66746674
if (excludeRegex && excludeRegex.test(absoluteName)) continue;
@@ -6691,32 +6691,32 @@ namespace ts {
66916691
}
66926692

66936693
for (const current of sort<string>(directories, compareStringsCaseSensitive)) {
6694+
const name = combinePaths(path, current);
66946695
const absoluteName = combinePaths(absolutePath, current);
66956696
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
66966697
(!excludeRegex || !excludeRegex.test(absoluteName))) {
6697-
visitDirectory(absoluteName, depth);
6698+
visitDirectory(name, absoluteName, depth);
66986699
}
66996700
}
67006701
}
67016702
}
67026703

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

67116711
if (includes) {
67126712
// Storage for literal base paths amongst the include patterns.
67136713
const includeBasePaths: string[] = [];
67146714
for (const include of includes) {
67156715
// We also need to check the relative paths by converting them to absolute and normalizing
67166716
// in case they escape the base path (e.g "..\somedirectory")
6717-
const absoluteIncludePath: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(absoluteTsconfigPath, include));
6717+
const absolute: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include));
67186718
// Append the literal and canonical candidate base paths.
6719-
includeBasePaths.push(getIncludeBasePath(absoluteIncludePath));
6719+
includeBasePaths.push(getIncludeBasePath(absolute));
67206720
}
67216721

67226722
// Sort the offsets array using either the literal or canonical path representations.
@@ -6725,7 +6725,7 @@ namespace ts {
67256725
// Iterate over each include base path and include unique base paths that are not a
67266726
// subpath of an existing base path
67276727
for (const includeBasePath of includeBasePaths) {
6728-
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, absoluteTsconfigPath, !useCaseSensitiveFileNames))) {
6728+
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) {
67296729
basePaths.push(includeBasePath);
67306730
}
67316731
}

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)