fix(compiler-cli): ensure file_system handles mixed Windows drives (#38030)
The `fs.relative()` method assumed that the file-system is a single tree, which is not the case in Windows, where you can have multiple drives, e.g. `C:`, `D:` etc. This commit changes `fs.relative()` so that it no longer forces the result to be a `PathSegment` and then flows that refactoring through the rest of the compiler-cli (and ngcc). The main difference is that now, in some cases, we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`, rather than a `PathSegment`, before using it. Fixes #36777 PR Close #38030
This commit is contained in:

committed by
Andrew Kushnir

parent
13d176302b
commit
dba402344f
@ -12,7 +12,7 @@ import * as ts from 'typescript';
|
||||
|
||||
import {createCompilerHost, createProgram} from '../../index';
|
||||
import {main, mainDiagnosticsForTest, readNgcCommandLineAndConfiguration} from '../../src/main';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, NgtscCompilerHost} from '../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, NgtscCompilerHost, relativeFrom} from '../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem} from '../../src/ngtsc/file_system/testing';
|
||||
import {IndexedComponent} from '../../src/ngtsc/indexer';
|
||||
import {NgtscProgram} from '../../src/ngtsc/program';
|
||||
@ -274,7 +274,8 @@ const ROOT_PREFIX = 'root/';
|
||||
|
||||
class FileNameToModuleNameHost extends AugmentedCompilerHost {
|
||||
fileNameToModuleName(importedFilePath: string): string {
|
||||
const relativeFilePath = this.fs.relative(this.fs.pwd(), this.fs.resolve(importedFilePath));
|
||||
const relativeFilePath =
|
||||
relativeFrom(this.fs.relative(this.fs.pwd(), this.fs.resolve(importedFilePath)));
|
||||
const rootedPath = this.fs.join('root', relativeFilePath);
|
||||
return rootedPath.replace(/(\.d)?.ts$/, '');
|
||||
}
|
||||
|
Reference in New Issue
Block a user