This reverts commit 65337fb8b8
.
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:

committed by
Alex Rickabaugh

parent
4423ab5109
commit
00b9de56f5
@ -53,13 +53,10 @@ export class LogicalFileSystem {
|
||||
*/
|
||||
private cache: Map<AbsoluteFsPath, LogicalProjectPath|null> = new Map();
|
||||
|
||||
constructor(rootDirs: AbsoluteFsPath[], private compilerHost: ts.CompilerHost) {
|
||||
constructor(rootDirs: AbsoluteFsPath[]) {
|
||||
// Make a copy and sort it by length in reverse order (longest first). This speeds up lookups,
|
||||
// since there's no need to keep going through the array once a match is found.
|
||||
this.rootDirs =
|
||||
rootDirs.map(dir => this.compilerHost.getCanonicalFileName(dir) as AbsoluteFsPath)
|
||||
.concat([])
|
||||
.sort((a, b) => b.length - a.length);
|
||||
this.rootDirs = rootDirs.concat([]).sort((a, b) => b.length - a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,13 +76,11 @@ export class LogicalFileSystem {
|
||||
* of the TS project's root directories.
|
||||
*/
|
||||
logicalPathOfFile(physicalFile: AbsoluteFsPath): LogicalProjectPath|null {
|
||||
const canonicalFilePath =
|
||||
this.compilerHost.getCanonicalFileName(physicalFile) as AbsoluteFsPath;
|
||||
if (!this.cache.has(canonicalFilePath)) {
|
||||
if (!this.cache.has(physicalFile)) {
|
||||
let logicalFile: LogicalProjectPath|null = null;
|
||||
for (const rootDir of this.rootDirs) {
|
||||
if (isWithinBasePath(rootDir, canonicalFilePath)) {
|
||||
logicalFile = this.createLogicalProjectPath(canonicalFilePath, rootDir);
|
||||
if (physicalFile.startsWith(rootDir)) {
|
||||
logicalFile = this.createLogicalProjectPath(physicalFile, rootDir);
|
||||
// The logical project does not include any special "node_modules" nested directories.
|
||||
if (logicalFile.indexOf('/node_modules/') !== -1) {
|
||||
logicalFile = null;
|
||||
@ -94,9 +89,9 @@ export class LogicalFileSystem {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cache.set(canonicalFilePath, logicalFile);
|
||||
this.cache.set(physicalFile, logicalFile);
|
||||
}
|
||||
return this.cache.get(canonicalFilePath)!;
|
||||
return this.cache.get(physicalFile)!;
|
||||
}
|
||||
|
||||
private createLogicalProjectPath(file: AbsoluteFsPath, rootDir: AbsoluteFsPath):
|
||||
@ -105,11 +100,3 @@ export class LogicalFileSystem {
|
||||
return (logicalPath.startsWith('/') ? logicalPath : '/' + logicalPath) as LogicalProjectPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the `path` a descendant of the `base`?
|
||||
* E.g. `foo/bar/zee` is within `foo/bar` but not within `foo/car`.
|
||||
*/
|
||||
function isWithinBasePath(base: AbsoluteFsPath, path: AbsoluteFsPath): boolean {
|
||||
return !relative(base, path).startsWith('..');
|
||||
}
|
||||
|
@ -6,24 +6,18 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgtscCompilerHost} from '../src/compiler_host';
|
||||
import {absoluteFrom, getFileSystem} from '../src/helpers';
|
||||
import {absoluteFrom} from '../src/helpers';
|
||||
import {LogicalFileSystem, LogicalProjectPath} from '../src/logical';
|
||||
import {runInEachFileSystem} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('logical paths', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
let host: NgtscCompilerHost;
|
||||
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
host = new NgtscCompilerHost(getFileSystem());
|
||||
});
|
||||
beforeEach(() => _ = absoluteFrom);
|
||||
|
||||
describe('LogicalFileSystem', () => {
|
||||
it('should determine logical paths in a single root file system', () => {
|
||||
const fs = new LogicalFileSystem([_('/test')], host);
|
||||
const fs = new LogicalFileSystem([_('/test')]);
|
||||
expect(fs.logicalPathOfFile(_('/test/foo/foo.ts')))
|
||||
.toEqual('/foo/foo' as LogicalProjectPath);
|
||||
expect(fs.logicalPathOfFile(_('/test/bar/bar.ts')))
|
||||
@ -32,23 +26,23 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
it('should determine logical paths in a multi-root file system', () => {
|
||||
const fs = new LogicalFileSystem([_('/test/foo'), _('/test/bar')], host);
|
||||
const fs = new LogicalFileSystem([_('/test/foo'), _('/test/bar')]);
|
||||
expect(fs.logicalPathOfFile(_('/test/foo/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
|
||||
expect(fs.logicalPathOfFile(_('/test/bar/bar.ts'))).toEqual('/bar' as LogicalProjectPath);
|
||||
});
|
||||
|
||||
it('should continue to work when one root is a child of another', () => {
|
||||
const fs = new LogicalFileSystem([_('/test'), _('/test/dist')], host);
|
||||
const fs = new LogicalFileSystem([_('/test'), _('/test/dist')]);
|
||||
expect(fs.logicalPathOfFile(_('/test/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
|
||||
expect(fs.logicalPathOfFile(_('/test/dist/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
|
||||
});
|
||||
|
||||
it('should always return `/` prefixed logical paths', () => {
|
||||
const rootFs = new LogicalFileSystem([_('/')], host);
|
||||
const rootFs = new LogicalFileSystem([_('/')]);
|
||||
expect(rootFs.logicalPathOfFile(_('/foo/foo.ts')))
|
||||
.toEqual('/foo/foo' as LogicalProjectPath);
|
||||
|
||||
const nonRootFs = new LogicalFileSystem([_('/test/')], host);
|
||||
const nonRootFs = new LogicalFileSystem([_('/test/')]);
|
||||
expect(nonRootFs.logicalPathOfFile(_('/test/foo/foo.ts')))
|
||||
.toEqual('/foo/foo' as LogicalProjectPath);
|
||||
});
|
||||
|
Reference in New Issue
Block a user