Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-cli): ensure LogicalProjectPaths always start with a slash #29627

Closed
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -81,7 +81,7 @@ export class LogicalFileSystem {
let logicalFile: LogicalProjectPath|null = null;
for (const rootDir of this.rootDirs) {
if (physicalFile.startsWith(rootDir)) {
logicalFile = stripExtension(physicalFile.substr(rootDir.length)) as LogicalProjectPath;
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,4 +94,10 @@ export class LogicalFileSystem {
}
return this.cache.get(physicalFile) !;
}

private createLogicalProjectPath(file: AbsoluteFsPath, rootDir: AbsoluteFsPath):
LogicalProjectPath {
const logicalPath = stripExtension(file.substr(rootDir.length));
return (logicalPath.startsWith('/') ? logicalPath : '/' + logicalPath) as LogicalProjectPath;
}
}
@@ -31,6 +31,16 @@ describe('logical paths', () => {
expect(fs.logicalPathOfFile(abs('/test/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
expect(fs.logicalPathOfFile(abs('/test/dist/foo.ts'))).toEqual('/foo' as LogicalProjectPath);
});

it('should always return `/` prefixed logical paths', () => {
const rootFs = new LogicalFileSystem([abs('/')]);
expect(rootFs.logicalPathOfFile(abs('/foo/foo.ts')))
.toEqual('/foo/foo' as LogicalProjectPath);

const nonRootFs = new LogicalFileSystem([abs('/test/')]);
expect(nonRootFs.logicalPathOfFile(abs('/test/foo/foo.ts')))
.toEqual('/foo/foo' as LogicalProjectPath);
});
});

describe('utilities', () => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.