1
+ import { normalize } from 'path' ;
1
2
import { CancellationToken , CompilerHost , CompilerOptions , createCompilerHost , ScriptTarget , SourceFile } from 'typescript' ;
2
3
import { VirtualFileSystem } from '../util/interfaces' ;
3
4
import { getTypescriptSourceFile } from '../util/typescript-utils' ;
@@ -17,6 +18,7 @@ export class InMemoryCompilerHost implements CompilerHost {
17
18
}
18
19
19
20
fileExists ( filePath : string ) : boolean {
21
+ filePath = normalize ( filePath ) ;
20
22
const fileContent = this . fileSystem . getFileContent ( filePath ) ;
21
23
if ( fileContent ) {
22
24
return true ;
@@ -25,6 +27,7 @@ export class InMemoryCompilerHost implements CompilerHost {
25
27
}
26
28
27
29
readFile ( filePath : string ) : string {
30
+ filePath = normalize ( filePath ) ;
28
31
const fileContent = this . fileSystem . getFileContent ( filePath ) ;
29
32
if ( fileContent ) {
30
33
return fileContent ;
@@ -33,6 +36,7 @@ export class InMemoryCompilerHost implements CompilerHost {
33
36
}
34
37
35
38
directoryExists ( directoryPath : string ) : boolean {
39
+ directoryPath = normalize ( directoryPath ) ;
36
40
const stats = this . fileSystem . getDirectoryStats ( directoryPath ) ;
37
41
if ( stats ) {
38
42
return true ;
@@ -41,10 +45,12 @@ export class InMemoryCompilerHost implements CompilerHost {
41
45
}
42
46
43
47
getFiles ( directoryPath : string ) : string [ ] {
48
+ directoryPath = normalize ( directoryPath ) ;
44
49
return this . fileSystem . getFileNamesInDirectory ( directoryPath ) ;
45
50
}
46
51
47
52
getDirectories ( directoryPath : string ) : string [ ] {
53
+ directoryPath = normalize ( directoryPath ) ;
48
54
const subdirs = this . fileSystem . getSubDirs ( directoryPath ) ;
49
55
50
56
let delegated : string [ ] ;
@@ -57,6 +63,7 @@ export class InMemoryCompilerHost implements CompilerHost {
57
63
}
58
64
59
65
getSourceFile ( filePath : string , languageVersion : ScriptTarget , onError ?: OnErrorFn ) {
66
+ filePath = normalize ( filePath ) ;
60
67
const existingSourceFile = this . sourceFileMap . get ( filePath ) ;
61
68
if ( existingSourceFile ) {
62
69
return existingSourceFile ;
@@ -82,6 +89,7 @@ export class InMemoryCompilerHost implements CompilerHost {
82
89
}
83
90
84
91
writeFile ( fileName : string , data : string , writeByteOrderMark : boolean , onError ?: OnErrorFn ) {
92
+ fileName = normalize ( fileName ) ;
85
93
Logger . debug ( `[NgcCompilerHost] writeFile: adding ${ fileName } to virtual file system` ) ;
86
94
this . fileSystem . addVirtualFile ( fileName , data ) ;
87
95
}
0 commit comments