From 00cc02fb0cc81025d7af86708cebff4a7b515946 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Fri, 8 May 2020 13:33:58 +0100 Subject: [PATCH] Revert "fix(compiler-cli): ensure `MockFileSystem` handles case-sensitivity (#36968)" (#37003) This reverts commit b6c042d0a35b977fc1ab51827805b73dfceefabb. The changes to the case-sensitivity handling in #36968 caused multiple projects to fail to build. See #36992, #36993 and #37000. The issue is related to the logical path handling. But it is felt that it is safer to revert the entire PR and then to investigate further. PR Close #37003 --- .../testing/src/mock_file_system.ts | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts index 8382d456f5..7731f5fea6 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts @@ -119,7 +119,7 @@ export abstract class MockFileSystem implements FileSystem { } ensureDir(path: AbsoluteFsPath): void { - const segments = this.splitPath(path).map(segment => this.getCanonicalPath(segment)); + const segments = this.splitPath(path); let current: Folder = this._fileTree; // Convert the root folder to a canonical empty string `''` (on Windows it would be `'C:'`). @@ -212,29 +212,12 @@ export abstract class MockFileSystem implements FileSystem { protected abstract splitPath(path: T): string[]; dump(): Folder { - return this.cloneFolder(this._fileTree); + return cloneFolder(this._fileTree); } init(folder: Folder): void { - this._fileTree = this.cloneFolder(folder); + this._fileTree = cloneFolder(folder); } - private cloneFolder(folder: Folder): Folder { - const clone: Folder = {}; - for (const path in folder) { - const item = folder[path]; - const canonicalPath = this.getCanonicalPath(path); - if (isSymLink(item)) { - clone[canonicalPath] = new SymLink(this.getCanonicalPath(item.path)); - } else if (isFolder(item)) { - clone[canonicalPath] = this.cloneFolder(item); - } else { - clone[canonicalPath] = folder[path]; - } - } - return clone; - } - - protected findFromPath(path: AbsoluteFsPath, options?: {followSymLinks: boolean}): FindResult { const followSymLinks = !!options && options.followSymLinks; const segments = this.splitPath(path); @@ -246,7 +229,7 @@ export abstract class MockFileSystem implements FileSystem { segments[0] = ''; let current: Entity|null = this._fileTree; while (segments.length) { - current = current[this.getCanonicalPath(segments.shift()!)]; + current = current[segments.shift()!]; if (current === undefined) { return {path, entity: null}; } @@ -269,14 +252,10 @@ export abstract class MockFileSystem implements FileSystem { } protected splitIntoFolderAndFile(path: AbsoluteFsPath): [AbsoluteFsPath, string] { - const segments = this.splitPath(this.getCanonicalPath(path)); + const segments = this.splitPath(path); const file = segments.pop()!; return [path.substring(0, path.length - file.length - 1) as AbsoluteFsPath, file]; } - - protected getCanonicalPath(p: T): T { - return this.isCaseSensitive() ? p : p.toLowerCase() as T; - } } export interface FindResult { path: AbsoluteFsPath; @@ -321,3 +300,18 @@ export function isSymLink(item: Entity|null): item is SymLink { export function isFolder(item: Entity|null): item is Folder { return item !== null && !isFile(item) && !isSymLink(item); } + +function cloneFolder(folder: Folder): Folder { + const clone: Folder = {}; + for (const path in folder) { + const item = folder[path]; + if (isSymLink(item)) { + clone[path] = new SymLink(item.path); + } else if (isFolder(item)) { + clone[path] = cloneFolder(item); + } else { + clone[path] = folder[path]; + } + } + return clone; +}