Only filter ignored paths from module specifier generation if there exists a better option (#43024)

* Only filter ignored paths from module specifier generation if there exists a better option

* Nit
This commit is contained in:
Andrew Branch
2021-03-01 16:12:03 -08:00
committed by GitHub
parent 4b67b4a7bc
commit 56f95d2a3f
5 changed files with 133 additions and 2 deletions

View File

@@ -282,10 +282,12 @@ namespace ts.moduleSpecifiers {
const redirects = host.redirectTargetsMap.get(importedPath) || emptyArray;
const importedFileNames = [...(referenceRedirect ? [referenceRedirect] : emptyArray), importedFileName, ...redirects];
const targets = importedFileNames.map(f => getNormalizedAbsolutePath(f, cwd));
let shouldFilterIgnoredPaths = !every(targets, containsIgnoredPath);
if (!preferSymlinks) {
// Symlinks inside ignored paths are already filtered out of the symlink cache,
// so we only need to remove them from the realpath filenames.
const result = forEach(targets, p => !containsIgnoredPath(p) && cb(p, referenceRedirect === p));
const result = forEach(targets, p => !(shouldFilterIgnoredPaths && containsIgnoredPath(p)) && cb(p, referenceRedirect === p));
if (result) return result;
}
const links = host.getSymlinkCache
@@ -312,12 +314,13 @@ namespace ts.moduleSpecifiers {
for (const symlinkDirectory of symlinkDirectories) {
const option = resolvePath(symlinkDirectory, relative);
const result = cb(option, target === referenceRedirect);
shouldFilterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
if (result) return result;
}
});
});
return result || (preferSymlinks
? forEach(targets, p => containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect))
? forEach(targets, p => shouldFilterIgnoredPaths && containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect))
: undefined);
}