Skip to content

Commit 4a5ad17

Browse files
JoostKthePunderWoman
authored andcommitted
fix(compiler-cli): ensure casing of logical paths is preserved (#44798)
The logical filesystem would store a cached result based on the canonical path, where the cached value contains the physical path that was originally provided. This meant that other physical paths with an identical canonical path would use a cached result derived from another physical path. This inconsistency is not known to result in actual issues but is primarily being made as a performance improvement, as using the provided physical paths as cache key avoids the need to canonicalize the path if its result is already cached. PR Close #44798
1 parent d65a42b commit 4a5ad17

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/compiler-cli/src/ngtsc/file_system/src/logical.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ export class LogicalFileSystem {
8383
* of the TS project's root directories.
8484
*/
8585
logicalPathOfFile(physicalFile: AbsoluteFsPath): LogicalProjectPath|null {
86-
const canonicalFilePath =
87-
this.compilerHost.getCanonicalFileName(physicalFile) as AbsoluteFsPath;
88-
if (!this.cache.has(canonicalFilePath)) {
86+
if (!this.cache.has(physicalFile)) {
87+
const canonicalFilePath =
88+
this.compilerHost.getCanonicalFileName(physicalFile) as AbsoluteFsPath;
8989
let logicalFile: LogicalProjectPath|null = null;
9090
for (let i = 0; i < this.rootDirs.length; i++) {
9191
const rootDir = this.rootDirs[i];
@@ -102,9 +102,9 @@ export class LogicalFileSystem {
102102
}
103103
}
104104
}
105-
this.cache.set(canonicalFilePath, logicalFile);
105+
this.cache.set(physicalFile, logicalFile);
106106
}
107-
return this.cache.get(canonicalFilePath)!;
107+
return this.cache.get(physicalFile)!;
108108
}
109109

110110
private createLogicalProjectPath(file: AbsoluteFsPath, rootDir: AbsoluteFsPath):

packages/compiler-cli/src/ngtsc/file_system/test/logical_spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ runInEachFileSystem(() => {
5757
const fs = new LogicalFileSystem([_('/Test')], host);
5858
expect(fs.logicalPathOfFile(_('/Test/foo/Foo.ts')))
5959
.toEqual('/foo/Foo' as LogicalProjectPath);
60+
expect(fs.logicalPathOfFile(_('/Test/foo/foo.ts')))
61+
.toEqual('/foo/foo' as LogicalProjectPath);
6062
expect(fs.logicalPathOfFile(_('/Test/bar/bAR.ts')))
6163
.toEqual('/bar/bAR' as LogicalProjectPath);
6264
});

0 commit comments

Comments
 (0)