Skip to content

Commit 9076f4d

Browse files
committed
Fix self reference package with casing
1 parent fc35e0a commit 9076f4d

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/compiler/moduleNameResolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ namespace ts {
22492249
if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json)
22502250
&& (state.compilerOptions.declarationDir || state.compilerOptions.outDir)
22512251
&& finalPath.indexOf("/node_modules/") === -1
2252-
&& (state.compilerOptions.configFile ? startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)
2252+
&& (state.compilerOptions.configFile ? containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)
22532253
) {
22542254
// So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings.
22552255
// Even with all that, we still don't know if the root of the output file structure will be (relative to the package file)
@@ -2310,7 +2310,7 @@ namespace ts {
23102310
for (const commonSourceDirGuess of commonSourceDirGuesses) {
23112311
const candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess);
23122312
for (const candidateDir of candidateDirectories) {
2313-
if (startsWith(finalPath, candidateDir)) {
2313+
if (containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) {
23142314
// The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension
23152315
const pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator
23162316
const possibleInputBase = combinePaths(commonSourceDirGuess, pathFragment);

tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,19 @@ Found 'package.json' at '/users/name/projects/web/package.json'.
3535
======== Resolving module '@this/package' from '/Users/name/projects/web/index.ts'. ========
3636
Module resolution kind is not specified, using 'NodeNext'.
3737
File '/users/name/projects/web/package.json' exists according to earlier cached lookups.
38-
File '/users/name/projects/web/index.ts' exist - use it as a name resolution result.
39-
Resolving real path for '/users/name/projects/web/index.ts', result '/Users/name/projects/web/index.ts'.
40-
======== Module name '@this/package' was successfully resolved to '/users/name/projects/web/index.ts'. ========
38+
File '/Users/name/projects/web/index.ts' exist - use it as a name resolution result.
39+
Resolving real path for '/Users/name/projects/web/index.ts', result '/Users/name/projects/web/index.ts'.
40+
======== Module name '@this/package' was successfully resolved to '/Users/name/projects/web/index.ts'. ========
4141
File '/a/lib/package.json' does not exist.
4242
File '/a/package.json' does not exist.
4343
File '/package.json' does not exist.
44-
index.ts:1:21 - error TS1149: File name '/users/name/projects/web/index.ts' differs from already included file name '/Users/name/projects/web/index.ts' only in casing.
45-
The file is in the program because:
46-
Matched by default include pattern '**/*'
47-
Imported via "@this/package" from file '/Users/name/projects/web/index.ts'
48-
File is ECMAScript module because '/users/name/projects/web/package.json' has field "type" with value "module"
49-
50-
1 import * as me from "@this/package";
51-
   ~~~~~~~~~~~~~~~
52-
5344
../../../../a/lib/lib.esnext.full.d.ts
5445
Default library for target 'esnext'
5546
index.ts
5647
Matched by default include pattern '**/*'
5748
Imported via "@this/package" from file 'index.ts'
5849
File is ECMAScript module because 'package.json' has field "type" with value "module"
59-
[[90m12:00:36 AM[0m] Found 1 error. Watching for file changes.
50+
[[90m12:00:36 AM[0m] Found 0 errors. Watching for file changes.
6051

6152

6253

0 commit comments

Comments
 (0)