Skip to content

Commit 1c30bb4

Browse files
committed
Add useCaseSensitiveFileNames to ModuleResolutionHost
...so that path comparisons can use it during module resolution.
1 parent 97a9361 commit 1c30bb4

File tree

9 files changed

+19
-12
lines changed

9 files changed

+19
-12
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ namespace ts {
280280
}
281281
const nodeModulesAtTypes = combinePaths("node_modules", "@types");
282282

283+
function arePathsEqual(path1: string, path2: string, host: ModuleResolutionHost): boolean {
284+
const useCaseSensitiveFileNames = typeof host.useCaseSensitiveFileNames === "function" ? host.useCaseSensitiveFileNames() : host.useCaseSensitiveFileNames;
285+
return comparePaths(path1, path2, !useCaseSensitiveFileNames) === Comparison.EqualTo;
286+
}
287+
283288
/**
284289
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
285290
* 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 {
343348
resolvedTypeReferenceDirective = {
344349
primary,
345350
resolvedFileName,
346-
originalPath: fileName === resolvedFileName ? undefined : fileName,
351+
originalPath: arePathsEqual(fileName, resolvedFileName, host) ? undefined : fileName,
347352
packageId,
348353
isExternalLibraryImport: pathContainsNodeModules(fileName),
349354
};
@@ -1072,12 +1077,6 @@ namespace ts {
10721077
return resolvedModule.resolvedFileName;
10731078
}
10741079

1075-
/* @internal */
1076-
export function tryResolveJSModule(moduleName: string, initialDir: string, host: ModuleResolutionHost): string | undefined {
1077-
const { resolvedModule } = tryResolveJSModuleWorker(moduleName, initialDir, host);
1078-
return resolvedModule && resolvedModule.resolvedFileName;
1079-
}
1080-
10811080
const jsOnlyExtensions = [Extensions.JavaScript];
10821081
const tsExtensions = [Extensions.TypeScript, Extensions.JavaScript];
10831082
const tsPlusJsonExtensions = [...tsExtensions, Extensions.Json];
@@ -1118,7 +1117,7 @@ namespace ts {
11181117
let resolvedValue = resolved.value;
11191118
if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {
11201119
const path = realPath(resolvedValue.path, host, traceEnabled);
1121-
const originalPath = path === resolvedValue.path ? undefined : resolvedValue.path;
1120+
const originalPath = arePathsEqual(path, resolvedValue.path, host) ? undefined : resolvedValue.path;
11221121
resolvedValue = { ...resolvedValue, path, originalPath };
11231122
}
11241123
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3771,7 +3771,7 @@ namespace ts {
37713771
function fileExistsIfProjectReferenceDts(file: string) {
37723772
const source = host.getSourceOfProjectReferenceRedirect(host.toPath(file));
37733773
return source !== undefined ?
3774-
isString(source) ? originalFileExists.call(host.compilerHost, source) : true :
3774+
isString(source) ? originalFileExists.call(host.compilerHost, source) as boolean : true :
37753775
undefined;
37763776
}
37773777

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6451,6 +6451,7 @@ namespace ts {
64516451
realpath?(path: string): string;
64526452
getCurrentDirectory?(): string;
64536453
getDirectories?(path: string): string[];
6454+
useCaseSensitiveFileNames?: boolean | (() => boolean);
64546455
}
64556456

64566457
/**

src/compiler/utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6188,7 +6188,9 @@ namespace ts {
61886188
}
61896189

61906190
export interface SymlinkedDirectory {
6191+
/** Matches the casing returned by `realpath`. Used to compute the `realpath` of children. */
61916192
real: string;
6193+
/** toPath(real). Stored to avoid repeated recomputation. */
61926194
realPath: Path;
61936195
}
61946196

src/harness/harnessLanguageService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ namespace Harness.LanguageService {
325325
readFile: fileName => {
326326
const scriptInfo = this.getScriptInfo(fileName);
327327
return scriptInfo && scriptInfo.content;
328-
}
328+
},
329+
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames()
329330
};
330331
this.getModuleResolutionsForFile = (fileName) => {
331332
const scriptInfo = this.getScriptInfo(fileName)!;

src/server/project.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,7 @@ namespace ts.server {
17041704
readFile: this.projectService.host.readFile.bind(this.projectService.host),
17051705
getDirectories: this.projectService.host.getDirectories.bind(this.projectService.host),
17061706
trace: this.projectService.host.trace?.bind(this.projectService.host),
1707+
useCaseSensitiveFileNames: this.program.useCaseSensitiveFileNames(),
17071708
};
17081709
}
17091710
return this.projectService.host;

src/testRunner/unittests/moduleResolution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ namespace ts {
6565
fileExists: path => {
6666
assert.isTrue(directories.has(getDirectoryPath(path)), `'fileExists' '${path}' request in non-existing directory`);
6767
return map.has(path);
68-
}
68+
},
69+
useCaseSensitiveFileNames: true
6970
};
7071
}
7172
else {
72-
return { readFile, realpath, fileExists: path => map.has(path) };
73+
return { readFile, realpath, fileExists: path => map.has(path), useCaseSensitiveFileNames: true };
7374
}
7475
function readFile(path: string): string | undefined {
7576
const file = map.get(path);

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,7 @@ declare namespace ts {
30563056
realpath?(path: string): string;
30573057
getCurrentDirectory?(): string;
30583058
getDirectories?(path: string): string[];
3059+
useCaseSensitiveFileNames?: boolean | (() => boolean);
30593060
}
30603061
/**
30613062
* Represents the result of module resolution.

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,7 @@ declare namespace ts {
30563056
realpath?(path: string): string;
30573057
getCurrentDirectory?(): string;
30583058
getDirectories?(path: string): string[];
3059+
useCaseSensitiveFileNames?: boolean | (() => boolean);
30593060
}
30603061
/**
30613062
* Represents the result of module resolution.

0 commit comments

Comments
 (0)