Use realpathSync.native on case-insensitive file systems (#44966)

* Make getSourceOfProjectReferenceRedirect take a Path

* Add useCaseSensitiveFileNames to ModuleResolutionHost

...so that path comparisons can use it during module resolution.

* Re-enable realpathSync.native for case-insensitive file systems
This commit is contained in:
Andrew Casey
2021-08-26 15:35:04 -07:00
committed by GitHub
parent 983ddf5bb5
commit 7fc1cb4b36
10 changed files with 39 additions and 28 deletions

View File

@@ -280,6 +280,11 @@ namespace ts {
}
const nodeModulesAtTypes = combinePaths("node_modules", "@types");
function arePathsEqual(path1: string, path2: string, host: ModuleResolutionHost): boolean {
const useCaseSensitiveFileNames = typeof host.useCaseSensitiveFileNames === "function" ? host.useCaseSensitiveFileNames() : host.useCaseSensitiveFileNames;
return comparePaths(path1, path2, !useCaseSensitiveFileNames) === Comparison.EqualTo;
}
/**
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
@@ -343,7 +348,7 @@ namespace ts {
resolvedTypeReferenceDirective = {
primary,
resolvedFileName,
originalPath: fileName === resolvedFileName ? undefined : fileName,
originalPath: arePathsEqual(fileName, resolvedFileName, host) ? undefined : fileName,
packageId,
isExternalLibraryImport: pathContainsNodeModules(fileName),
};
@@ -1122,7 +1127,7 @@ namespace ts {
let resolvedValue = resolved.value;
if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {
const path = realPath(resolvedValue.path, host, traceEnabled);
const originalPath = path === resolvedValue.path ? undefined : resolvedValue.path;
const originalPath = arePathsEqual(path, resolvedValue.path, host) ? undefined : resolvedValue.path;
resolvedValue = { ...resolvedValue, path, originalPath };
}
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.