Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #31503 from microsoft/casing
Ignore drive letters when comparing casings of the files with forceConsistentCasingInFileNames
  • Loading branch information
sheetalkamat committed May 22, 2019
2 parents de96b41 + db15051 commit 1e7a77c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/compiler/program.ts
Expand Up @@ -2232,7 +2232,10 @@ namespace ts {
if (isRedirect) {
inputName = getProjectReferenceRedirect(fileName) || fileName;
}
if (getNormalizedAbsolutePath(checkedName, currentDirectory) !== getNormalizedAbsolutePath(inputName, currentDirectory)) {
// Check if it differs only in drive letters its ok to ignore that error:
const checkedAbsolutePath = getNormalizedAbsolutePathWithoutRoot(checkedName, currentDirectory);
const inputAbsolutePath = getNormalizedAbsolutePathWithoutRoot(inputName, currentDirectory);
if (checkedAbsolutePath !== inputAbsolutePath) {
reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/utilities.ts
Expand Up @@ -7646,6 +7646,14 @@ namespace ts {
return root + pathComponents.slice(1).join(directorySeparator);
}

export function getNormalizedAbsolutePathWithoutRoot(fileName: string, currentDirectory: string | undefined) {
return getPathWithoutRoot(getNormalizedPathComponents(fileName, currentDirectory));
}

function getPathWithoutRoot(pathComponents: ReadonlyArray<string>) {
if (pathComponents.length === 0) return "";
return pathComponents.slice(1).join(directorySeparator);
}
}

/* @internal */
Expand Down
18 changes: 17 additions & 1 deletion src/testRunner/unittests/moduleResolution.ts
Expand Up @@ -530,7 +530,7 @@ export = C;
});
});

describe("unittests:: moduleResolution:: Files with different casing", () => {
describe("unittests:: moduleResolution:: Files with different casing with forceConsistentCasingInFileNames", () => {
let library: SourceFile;
function test(files: Map<string>, options: CompilerOptions, currentDirectory: string, useCaseSensitiveFileNames: boolean, rootFiles: string[], diagnosticCodes: number[]): void {
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
Expand Down Expand Up @@ -649,6 +649,22 @@ import b = require("./moduleB");
});
test(files, { module: ModuleKind.CommonJS, forceConsistentCasingInFileNames: true }, "/a/B/c", /*useCaseSensitiveFileNames*/ false, ["moduleD.ts"], []);
});

it("should succeed when the two files in program differ only in drive letter in their names", () => {
const files = createMapFromTemplate({
"d:/someFolder/moduleA.ts": `import a = require("D:/someFolder/moduleC")`,
"d:/someFolder/moduleB.ts": `import a = require("./moduleC")`,
"D:/someFolder/moduleC.ts": "export const x = 10",
});
test(
files,
{ module: ModuleKind.CommonJS, forceConsistentCasingInFileNames: true },
"d:/someFolder",
/*useCaseSensitiveFileNames*/ false,
["d:/someFolder/moduleA.ts", "d:/someFolder/moduleB.ts"],
[]
);
});
});

describe("unittests:: moduleResolution:: baseUrl augmented module resolution", () => {
Expand Down

0 comments on commit 1e7a77c

Please sign in to comment.