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
9
import { Stats } from 'fs' ;
9
10
import { WebpackCompilerHost } from './compiler_host' ;
10
11
import { Callback , InputFileSystem , NodeWatchFileSystemInterface } from './webpack' ;
@@ -105,24 +106,27 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
105
106
}
106
107
107
108
export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
108
- constructor ( private _virtualInputFileSystem : VirtualFileSystemDecorator ) {
109
+ constructor (
110
+ private _virtualInputFileSystem : VirtualFileSystemDecorator ,
111
+ private _replacements ?: Map < Path , Path > ,
112
+ ) {
109
113
super ( _virtualInputFileSystem ) ;
110
114
}
111
115
112
116
watch (
113
- files : any , // tslint:disable-line:no-any
114
- dirs : any , // tslint:disable-line:no-any
115
- missing : any , // tslint:disable-line:no-any
116
- startTime : any , // tslint:disable-line:no-any
117
- options : any , // tslint:disable-line:no-any
117
+ files : string [ ] ,
118
+ dirs : string [ ] ,
119
+ missing : string [ ] ,
120
+ startTime : number | undefined ,
121
+ options : { } ,
118
122
callback : any , // tslint:disable-line:no-any
119
123
callbackUndelayed : any , // tslint:disable-line:no-any
120
124
) {
121
125
const newCallback = (
122
- err : any , // tslint:disable-line:no-any
123
- filesModified : any , // tslint:disable-line:no-any
124
- contextModified : any , // tslint:disable-line:no-any
125
- missingModified : any , // tslint:disable-line:no-any
126
+ err : Error | null ,
127
+ filesModified : string [ ] ,
128
+ contextModified : string [ ] ,
129
+ missingModified : string [ ] ,
126
130
fileTimestamps : { [ k : string ] : number } ,
127
131
contextTimestamps : { [ k : string ] : number } ,
128
132
) => {
@@ -137,6 +141,30 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
137
141
contextTimestamps ) ;
138
142
} ;
139
143
140
- return super . watch ( files , dirs , missing , startTime , options , newCallback , callbackUndelayed ) ;
144
+ const mapReplacements = ( original : string [ ] ) : string [ ] => {
145
+ if ( ! this . _replacements ) {
146
+ return original ;
147
+ }
148
+ const replacements = this . _replacements ;
149
+
150
+ return original . map ( file => {
151
+ const replacement = replacements . get ( normalize ( file ) ) ;
152
+ if ( replacement ) {
153
+ return getSystemPath ( replacement ) ;
154
+ } else {
155
+ return file ;
156
+ }
157
+ } ) ;
158
+ } ;
159
+
160
+ return super . watch (
161
+ mapReplacements ( files ) ,
162
+ mapReplacements ( dirs ) ,
163
+ mapReplacements ( missing ) ,
164
+ startTime ,
165
+ options ,
166
+ newCallback ,
167
+ callbackUndelayed ,
168
+ ) ;
141
169
}
142
170
}
0 commit comments