@@ -87,40 +87,50 @@ export class WebpackCompilerHost implements ts.CompilerHost {
87
87
fileExists ( fileName : string , delegate = true ) : boolean {
88
88
const p = this . resolve ( fileName ) ;
89
89
90
- const exists = this . _syncHost . exists ( p ) && this . _syncHost . isFile ( p ) ;
91
- if ( delegate ) {
92
- return exists ;
93
- } else {
94
- const backend = new virtualFs . SyncDelegateHost (
95
- ( this . _syncHost . delegate as virtualFs . CordHost ) . backend as virtualFs . Host ,
96
- ) ;
90
+ try {
91
+ const exists = this . _syncHost . isFile ( p ) ;
92
+ if ( delegate ) {
93
+ return exists ;
94
+ } else if ( exists ) {
95
+ const backend = new virtualFs . SyncDelegateHost (
96
+ ( this . _syncHost . delegate as virtualFs . CordHost ) . backend as virtualFs . Host ,
97
+ ) ;
98
+
99
+ return ! backend . isFile ( p ) ;
100
+ }
101
+ } catch { }
97
102
98
- return exists && ! ( backend . exists ( p ) && backend . isFile ( p ) ) ;
99
- }
103
+ return false ;
100
104
}
101
105
102
106
readFile ( fileName : string ) : string | undefined {
103
107
const filePath = this . resolve ( fileName ) ;
104
- if ( ! this . _syncHost . exists ( filePath ) || ! this . _syncHost . isFile ( filePath ) ) {
108
+
109
+ try {
110
+ return virtualFs . fileBufferToString ( this . _syncHost . read ( filePath ) ) ;
111
+ } catch {
105
112
return undefined ;
106
113
}
107
-
108
- return virtualFs . fileBufferToString ( this . _syncHost . read ( filePath ) ) ;
109
114
}
110
115
111
116
readFileBuffer ( fileName : string ) : Buffer | undefined {
112
117
const filePath = this . resolve ( fileName ) ;
113
- if ( ! this . _syncHost . exists ( filePath ) || ! this . _syncHost . isFile ( filePath ) ) {
118
+
119
+ try {
120
+ return Buffer . from ( this . _syncHost . read ( filePath ) ) ;
121
+ } catch {
114
122
return undefined ;
115
123
}
116
-
117
- return Buffer . from ( this . _syncHost . read ( filePath ) ) ;
118
124
}
119
125
120
126
stat ( path : string ) : Stats | null {
121
127
const p = this . resolve ( path ) ;
122
128
123
- const stats = this . _syncHost . exists ( p ) && this . _syncHost . stat ( p ) ;
129
+ let stats ;
130
+ try {
131
+ stats = this . _syncHost . stat ( p ) ;
132
+ } catch { }
133
+
124
134
if ( ! stats ) {
125
135
return null ;
126
136
}
@@ -151,7 +161,11 @@ export class WebpackCompilerHost implements ts.CompilerHost {
151
161
directoryExists ( directoryName : string ) : boolean {
152
162
const p = this . resolve ( directoryName ) ;
153
163
154
- return this . _syncHost . exists ( p ) && this . _syncHost . isDirectory ( p ) ;
164
+ try {
165
+ return this . _syncHost . isDirectory ( p ) ;
166
+ } catch {
167
+ return false ;
168
+ }
155
169
}
156
170
157
171
getDirectories ( path : string ) : string [ ] {
0 commit comments