From 0ec0ff3bce6476a6903a160ecb03587f7453f35a Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 6 May 2020 21:51:08 +0100 Subject: [PATCH] fix(compiler-cli): fix case-sensitivity issues in NgtscCompilerHost (#36859) The `getCanonicalFileName()` method was not actually calling the `useCaseSensitiveFileNames()` method. So it always returned a case-sensitive canonical filename. PR Close #36859 --- .../ngtsc/file_system/src/compiler_host.ts | 2 +- .../file_system/test/compiler_host_spec.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/compiler_host.ts b/packages/compiler-cli/src/ngtsc/file_system/src/compiler_host.ts index 40717c44f5..98ef5a70ff 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/src/compiler_host.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/src/compiler_host.ts @@ -44,7 +44,7 @@ export class NgtscCompilerHost implements ts.CompilerHost { } getCanonicalFileName(fileName: string): string { - return this.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); + return this.useCaseSensitiveFileNames() ? fileName : fileName.toLowerCase(); } useCaseSensitiveFileNames(): boolean { diff --git a/packages/compiler-cli/src/ngtsc/file_system/test/compiler_host_spec.ts b/packages/compiler-cli/src/ngtsc/file_system/test/compiler_host_spec.ts index 6f53351737..8973ac7247 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/test/compiler_host_spec.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/test/compiler_host_spec.ts @@ -41,5 +41,27 @@ runInEachFileSystem(() => { expect(host.getSourceFile(directory, ts.ScriptTarget.ES2015)).toBe(undefined); }); }); + + describe('useCaseSensitiveFileNames()', () => { + it('should return the same as `FileSystem.isCaseSensitive()', () => { + const directory = absoluteFrom('/a/b/c'); + const fs = getFileSystem(); + fs.ensureDir(directory); + const host = new NgtscCompilerHost(fs); + expect(host.useCaseSensitiveFileNames()).toEqual(fs.isCaseSensitive()); + }); + }); + + describe('getCanonicalFileName()', () => { + it('should return the original filename if FS is case-sensitive or lower case otherwise', + () => { + const directory = absoluteFrom('/a/b/c'); + const fs = getFileSystem(); + fs.ensureDir(directory); + const host = new NgtscCompilerHost(fs); + expect(host.getCanonicalFileName(('AbCd.ts'))) + .toEqual(fs.isCaseSensitive() ? 'AbCd.ts' : 'abcd.ts'); + }); + }); }); });