55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- import { Path , getSystemPath , normalize } from '@angular-devkit/core' ;
8+ import { FileDoesNotExistException , Path , getSystemPath , normalize } from '@angular-devkit/core' ;
99import { Stats } from 'fs' ;
1010import { InputFileSystem } from 'webpack' ;
1111import { WebpackCompilerHost } from './compiler_host' ;
@@ -21,33 +21,17 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
2121 private _webpackCompilerHost : WebpackCompilerHost ,
2222 ) { }
2323
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-
4024 getVirtualFilesPaths ( ) {
4125 return this . _webpackCompilerHost . getNgFactoryPaths ( ) ;
4226 }
4327
4428 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 ) {
4733 // 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 ) ;
5135 }
5236 }
5337
@@ -57,12 +41,12 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
5741 }
5842
5943 readFile ( path : string , callback : ( err : Error , contents : Buffer ) => void ) : void {
60- const result = this . _readFileSync ( path ) ;
61- if ( result ) {
44+ try {
6245 // 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 ) ;
6650 }
6751 }
6852
@@ -76,9 +60,12 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
7660 }
7761
7862 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+ }
8067
81- return result || this . _inputFileSystem . statSync ( path ) ;
68+ return stats ;
8269 }
8370
8471 readdirSync ( path : string ) : string [ ] {
@@ -87,9 +74,7 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
8774 }
8875
8976 readFileSync ( path : string ) : Buffer {
90- const result = this . _readFileSync ( path ) ;
91-
92- return result || this . _inputFileSystem . readFileSync ( path ) ;
77+ return this . _webpackCompilerHost . readFileBuffer ( path ) ;
9378 }
9479
9580 readJsonSync ( path : string ) : string {
0 commit comments