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
This commit is contained in:
Pete Bacon Darwin 2020-05-08 13:33:58 +01:00 committed by Alex Rickabaugh
parent 0783d482a7
commit 00cc02fb0c

View File

@ -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<T extends PathString>(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<T extends string>(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;
}