Skip to content

Commit e02684e

Browse files
petebacondarwinIgorMinar
authored andcommittedApr 8, 2019
fix(compiler-cli): ensure LogicalProjectPaths always start with a slash (#29627)
Previously, if a matching rootDir ended with a slash then the path returned from `logicalPathOfFile()` would not start with a slash, which is inconsistent. PR Close #29627
1 parent ec56354 commit e02684e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎packages/compiler-cli/src/ngtsc/path/src/logical.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class LogicalFileSystem {
8181
let logicalFile: LogicalProjectPath|null = null;
8282
for (const rootDir of this.rootDirs) {
8383
if (physicalFile.startsWith(rootDir)) {
84-
logicalFile = stripExtension(physicalFile.substr(rootDir.length)) as LogicalProjectPath;
84+
logicalFile = this.createLogicalProjectPath(physicalFile, rootDir);
8585
// The logical project does not include any special "node_modules" nested directories.
8686
if (logicalFile.indexOf('/node_modules/') !== -1) {
8787
logicalFile = null;
@@ -94,4 +94,10 @@ export class LogicalFileSystem {
9494
}
9595
return this.cache.get(physicalFile) !;
9696
}
97+
98+
private createLogicalProjectPath(file: AbsoluteFsPath, rootDir: AbsoluteFsPath):
99+
LogicalProjectPath {
100+
const logicalPath = stripExtension(file.substr(rootDir.length));
101+
return (logicalPath.startsWith('/') ? logicalPath : '/' + logicalPath) as LogicalProjectPath;
102+
}
97103
}

‎packages/compiler-cli/src/ngtsc/path/test/logical_spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ describe('logical paths', () => {
3131
expect(fs.logicalPathOfFile(abs('/test/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
3232
expect(fs.logicalPathOfFile(abs('/test/dist/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
3333
});
34+
35+
it('should always return `/` prefixed logical paths', () => {
36+
const rootFs = new LogicalFileSystem([abs('/')]);
37+
expect(rootFs.logicalPathOfFile(abs('/foo/foo.ts')))
38+
.toEqual('/foo/foo' as LogicalProjectPath);
39+
40+
const nonRootFs = new LogicalFileSystem([abs('/test/')]);
41+
expect(nonRootFs.logicalPathOfFile(abs('/test/foo/foo.ts')))
42+
.toEqual('/foo/foo' as LogicalProjectPath);
43+
});
3444
});
3545

3646
describe('utilities', () => {

0 commit comments

Comments
 (0)