Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore drive letters when comparing casings of the files with forceConsistentCasingInFileNames #31503

Merged
merged 1 commit into from May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it??

C:\file is indeed the same as c:\file — but it is most definitely NOT the same as D:\file.

Looking at the use below the code will wrongly assume C:\file match D:\file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's guaranteed to be match because the file was found by its name.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So pathComponents[0] is always / on *nix systems, and e.g. C:/ on Windows, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

}
}

/* @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