5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { Path , getSystemPath , normalize } from '@angular-devkit/core' ;
8
+ import { FileDoesNotExistException , Path , getSystemPath , normalize } from '@angular-devkit/core' ;
9
9
import { Stats } from 'fs' ;
10
10
import { InputFileSystem } from 'webpack' ;
11
11
import { WebpackCompilerHost } from './compiler_host' ;
@@ -21,33 +21,17 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
21
21
private _webpackCompilerHost : WebpackCompilerHost ,
22
22
) { }
23
23
24
- private _readFileSync ( path : string ) : Buffer | null {
25
- if ( this . _webpackCompilerHost . fileExists ( path ) ) {
26
- return this . _webpackCompilerHost . readFileBuffer ( path ) || null ;
27
- }
28
-
29
- return null ;
30
- }
31
-
32
- private _statSync ( path : string ) : Stats | null {
33
- if ( this . _webpackCompilerHost . fileExists ( path ) ) {
34
- return this . _webpackCompilerHost . stat ( path ) ;
35
- }
36
-
37
- return null ;
38
- }
39
-
40
24
getVirtualFilesPaths ( ) {
41
25
return this . _webpackCompilerHost . getNgFactoryPaths ( ) ;
42
26
}
43
27
44
28
stat ( path : string , callback : ( err : Error , stats : Stats ) => void ) : void {
45
- const result = this . _statSync ( path ) ;
46
- if ( result ) {
29
+ try {
30
+ // tslint:disable-next-line:no-any
31
+ callback ( null as any , this . _webpackCompilerHost . stat ( path ) as any ) ;
32
+ } catch ( e ) {
47
33
// tslint:disable-next-line:no-any
48
- callback ( null as any , result ) ;
49
- } else {
50
- this . _inputFileSystem . stat ( path , callback ) ;
34
+ callback ( e , undefined as any ) ;
51
35
}
52
36
}
53
37
@@ -57,12 +41,12 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
57
41
}
58
42
59
43
readFile ( path : string , callback : ( err : Error , contents : Buffer ) => void ) : void {
60
- const result = this . _readFileSync ( path ) ;
61
- if ( result ) {
44
+ try {
62
45
// tslint:disable-next-line:no-any
63
- callback ( null as any , result ) ;
64
- } else {
65
- this . _inputFileSystem . readFile ( path , callback ) ;
46
+ callback ( null as any , this . _webpackCompilerHost . readFileBuffer ( path ) ) ;
47
+ } catch ( e ) {
48
+ // tslint:disable-next-line:no-any
49
+ callback ( e , undefined as any ) ;
66
50
}
67
51
}
68
52
@@ -76,9 +60,12 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
76
60
}
77
61
78
62
statSync ( path : string ) : Stats {
79
- const result = this . _statSync ( path ) ;
63
+ const stats = this . _webpackCompilerHost . stat ( path ) ;
64
+ if ( stats === null ) {
65
+ throw new FileDoesNotExistException ( path ) ;
66
+ }
80
67
81
- return result || this . _inputFileSystem . statSync ( path ) ;
68
+ return stats ;
82
69
}
83
70
84
71
readdirSync ( path : string ) : string [ ] {
@@ -87,9 +74,7 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
87
74
}
88
75
89
76
readFileSync ( path : string ) : Buffer {
90
- const result = this . _readFileSync ( path ) ;
91
-
92
- return result || this . _inputFileSystem . readFileSync ( path ) ;
77
+ return this . _webpackCompilerHost . readFileBuffer ( path ) ;
93
78
}
94
79
95
80
readJsonSync ( path : string ) : string {
0 commit comments