Skip to content

Commit 97011d6

Browse files
committed
Fix when real path results in value that differs only in case
Fixes #49470
1 parent 4a808aa commit 97011d6

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

src/compiler/moduleNameResolver.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,11 @@ namespace ts {
392392
if (resolved) {
393393
const { fileName, packageId } = resolved;
394394
const resolvedFileName = options.preserveSymlinks ? fileName : realPath(fileName, host, traceEnabled);
395+
const pathsAreEqual = arePathsEqual(fileName, resolvedFileName, host);
395396
resolvedTypeReferenceDirective = {
396397
primary,
397-
resolvedFileName,
398-
originalPath: arePathsEqual(fileName, resolvedFileName, host) ? undefined : fileName,
398+
resolvedFileName: pathsAreEqual ? fileName : resolvedFileName,
399+
originalPath: pathsAreEqual ? undefined : fileName,
399400
packageId,
400401
isExternalLibraryImport: pathContainsNodeModules(fileName),
401402
};
@@ -1406,8 +1407,9 @@ namespace ts {
14061407
let resolvedValue = resolved.value;
14071408
if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {
14081409
const path = realPath(resolvedValue.path, host, traceEnabled);
1409-
const originalPath = arePathsEqual(path, resolvedValue.path, host) ? undefined : resolvedValue.path;
1410-
resolvedValue = { ...resolvedValue, path, originalPath };
1410+
const pathsAreEqual = arePathsEqual(path, resolvedValue.path, host);
1411+
const originalPath = pathsAreEqual ? undefined : resolvedValue.path;
1412+
resolvedValue = { ...resolvedValue, path: pathsAreEqual ? resolvedValue.path : path, originalPath };
14111413
}
14121414
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
14131415
return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };

src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const Fragment: unique symbol;
113113
path: `${projectRoot}/tsconfig.json`,
114114
content: JSON.stringify({
115115
compilerOptions: { jsx: "react-jsx", jsxImportSource: "react", forceConsistentCasingInFileNames: true },
116-
files: ["node_modules/react/jsx-Runtime/index.d.ts", "index.tsx"] // NB: casing does not match disk
116+
files: ["node_modules/react/Jsx-Runtime/index.d.ts", "index.tsx"]
117117
})
118118
}
119119
], { currentDirectory: projectRoot }),

tests/baselines/reference/tsc/forceConsistentCasingInFileNames/with-relative-and-non-relative-file-resolutions.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ import * as xs4 from "./struct";
2828

2929
Output::
3030
/lib/tsc /src/project/src/struct.d.ts --forceConsistentCasingInFileNames --explainFiles
31+
src/project/src/struct.d.ts:2:22 - error TS1149: File name '/src/project/node_modules/fp-ts/lib/struct.d.ts' differs from already included file name '/src/project/node_modules/fp-ts/lib/Struct.d.ts' only in casing.
32+
The file is in the program because:
33+
Imported via "fp-ts/lib/Struct" from file '/src/project/src/struct.d.ts'
34+
Imported via "fp-ts/lib/struct" from file '/src/project/src/struct.d.ts'
35+
36+
2 import * as xs2 from "fp-ts/lib/struct";
37+
   ~~~~~~~~~~~~~~~~~~
38+
39+
src/project/src/struct.d.ts:1:22
40+
1 import * as xs1 from "fp-ts/lib/Struct";
41+
   ~~~~~~~~~~~~~~~~~~
42+
File is included via import here.
43+
3144
src/project/src/struct.d.ts:3:22 - error TS1149: File name '/src/project/src/Struct.d.ts' differs from already included file name '/src/project/src/struct.d.ts' only in casing.
3245
The file is in the program because:
3346
Root file specified for compilation
@@ -44,15 +57,15 @@ Output::
4457

4558
lib/lib.d.ts
4659
Default library for target 'es3'
47-
src/project/node_modules/fp-ts/lib/struct.d.ts
60+
src/project/node_modules/fp-ts/lib/Struct.d.ts
4861
Imported via "fp-ts/lib/Struct" from file 'src/project/src/struct.d.ts'
4962
Imported via "fp-ts/lib/struct" from file 'src/project/src/struct.d.ts'
5063
src/project/src/struct.d.ts
5164
Root file specified for compilation
5265
Imported via "./Struct" from file 'src/project/src/struct.d.ts'
5366
Imported via "./struct" from file 'src/project/src/struct.d.ts'
5467

55-
Found 1 error in src/project/src/struct.d.ts[90m:3[0m
68+
Found 2 errors in the same file, starting at: src/project/src/struct.d.ts[90m:2[0m
5669

5770
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
5871

tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/jsxImportSource-option-changed.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ export const Fragment: unique symbol;
3333
export const App = () => <div propA={true}></div>;
3434

3535
//// [/user/username/projects/myproject/tsconfig.json]
36-
{"compilerOptions":{"jsx":"react-jsx","jsxImportSource":"react","forceConsistentCasingInFileNames":true},"files":["node_modules/react/jsx-Runtime/index.d.ts","index.tsx"]}
36+
{"compilerOptions":{"jsx":"react-jsx","jsxImportSource":"react","forceConsistentCasingInFileNames":true},"files":["node_modules/react/Jsx-Runtime/index.d.ts","index.tsx"]}
3737

3838

3939
/a/lib/tsc.js --w --p . --explainFiles
4040
Output::
4141
>> Screen clear
4242
[12:00:31 AM] Starting compilation in watch mode...
4343

44-
[91merror[0m[90m TS1149: [0mFile name '/user/username/projects/myproject/node_modules/react/Jsx-runtime/index.d.ts' differs from already included file name '/user/username/projects/myproject/node_modules/react/jsx-Runtime/index.d.ts' only in casing.
44+
[91merror[0m[90m TS1149: [0mFile name '/user/username/projects/myproject/node_modules/react/jsx-runtime/index.d.ts' differs from already included file name '/user/username/projects/myproject/node_modules/react/Jsx-Runtime/index.d.ts' only in casing.
4545
The file is in the program because:
4646
Part of 'files' list in tsconfig.json
4747
Imported via "react/jsx-runtime" from file '/user/username/projects/myproject/index.tsx' with packageId 'react/jsx-runtime/[email protected]' to import 'jsx' and 'jsxs' factory functions
4848

4949
tsconfig.json:1:115
50-
[7m1[0m {"compilerOptions":{"jsx":"react-jsx","jsxImportSource":"react","forceConsistentCasingInFileNames":true},"files":["node_modules/react/jsx-Runtime/index.d.ts","index.tsx"]}
50+
[7m1[0m {"compilerOptions":{"jsx":"react-jsx","jsxImportSource":"react","forceConsistentCasingInFileNames":true},"files":["node_modules/react/Jsx-Runtime/index.d.ts","index.tsx"]}
5151
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5252
File is matched by 'files' list specified here.
5353

5454
../../../../a/lib/lib.d.ts
5555
Default library for target 'es3'
56-
node_modules/react/jsx-Runtime/index.d.ts
56+
node_modules/react/Jsx-Runtime/index.d.ts
5757
Part of 'files' list in tsconfig.json
5858
Imported via "react/jsx-runtime" from file 'index.tsx' with packageId 'react/jsx-runtime/[email protected]' to import 'jsx' and 'jsxs' factory functions
5959
index.tsx
@@ -62,12 +62,12 @@ index.tsx
6262

6363

6464

65-
Program root files: ["/user/username/projects/myproject/node_modules/react/jsx-Runtime/index.d.ts","/user/username/projects/myproject/index.tsx"]
65+
Program root files: ["/user/username/projects/myproject/node_modules/react/Jsx-Runtime/index.d.ts","/user/username/projects/myproject/index.tsx"]
6666
Program options: {"jsx":4,"jsxImportSource":"react","forceConsistentCasingInFileNames":true,"watch":true,"project":"/user/username/projects/myproject","explainFiles":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
6767
Program structureReused: Not
6868
Program files::
6969
/a/lib/lib.d.ts
70-
/user/username/projects/myproject/node_modules/react/jsx-Runtime/index.d.ts
70+
/user/username/projects/myproject/node_modules/react/Jsx-Runtime/index.d.ts
7171
/user/username/projects/myproject/index.tsx
7272

7373
No cached semantic diagnostics in the builder::
@@ -81,7 +81,7 @@ WatchedFiles::
8181
/user/username/projects/myproject/tsconfig.json:
8282
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
8383
/user/username/projects/myproject/node_modules/react/jsx-runtime/index.d.ts:
84-
{"fileName":"/user/username/projects/myproject/node_modules/react/jsx-Runtime/index.d.ts","pollingInterval":250}
84+
{"fileName":"/user/username/projects/myproject/node_modules/react/Jsx-Runtime/index.d.ts","pollingInterval":250}
8585
/user/username/projects/myproject/index.tsx:
8686
{"fileName":"/user/username/projects/myproject/index.tsx","pollingInterval":250}
8787
/a/lib/lib.d.ts:

0 commit comments

Comments
 (0)