@@ -20,13 +20,6 @@ export interface BuilderWatcherFactory {
20
20
) : { close ( ) : void } ;
21
21
}
22
22
23
- export interface WebpackWatcher {
24
- close ( ) : void ;
25
- pause ( ) : void ;
26
- getFileTimeInfoEntries ( ) : Map < string , { safeTime : number ; timestamp : number } > ;
27
- getContextTimeInfoEntries ( ) : Map < string , { safeTime : number ; timestamp : number } > ;
28
- }
29
-
30
23
class TimeInfoMap extends Map < string , { safeTime : number ; timestamp : number } > {
31
24
update ( path : string , timestamp : number ) : void {
32
25
this . set ( path , Object . freeze ( { safeTime : timestamp , timestamp } ) ) ;
@@ -42,41 +35,26 @@ class TimeInfoMap extends Map<string, { safeTime: number; timestamp: number }> {
42
35
}
43
36
}
44
37
45
- type WatchCallback = (
46
- error : Error | undefined ,
47
- files : Map < string , { safeTime : number ; timestamp : number } > ,
48
- contexts : Map < string , { safeTime : number ; timestamp : number } > ,
49
- changes : Set < string > ,
50
- removals : Set < string > ,
51
- ) => void ;
52
-
53
- export interface WebpackWatchFileSystem {
54
- watch (
55
- files : Iterable < string > ,
56
- directories : Iterable < string > ,
57
- missing : Iterable < string > ,
58
- startTime : number ,
59
- options : { } ,
60
- callback : WatchCallback ,
61
- callbackUndelayed : ( file : string , time : number ) => void ,
62
- ) : WebpackWatcher ;
63
- }
38
+ // Extract watch related types from the Webpack compiler type since they are not directly exported
39
+ type WebpackWatchFileSystem = Compiler [ 'watchFileSystem' ] ;
40
+ type WatchOptions = Parameters < WebpackWatchFileSystem [ 'watch' ] > [ 4 ] ;
41
+ type WatchCallback = Parameters < WebpackWatchFileSystem [ 'watch' ] > [ 5 ] ;
64
42
65
43
class BuilderWatchFileSystem implements WebpackWatchFileSystem {
66
44
constructor (
67
45
private readonly watcherFactory : BuilderWatcherFactory ,
68
- private readonly inputFileSystem : { purge ? ( path ?: string ) : void } ,
46
+ private readonly inputFileSystem : Compiler [ 'inputFileSystem' ] ,
69
47
) { }
70
48
71
49
watch (
72
50
files : Iterable < string > ,
73
51
directories : Iterable < string > ,
74
52
missing : Iterable < string > ,
75
53
startTime : number ,
76
- _options : { } ,
54
+ _options : WatchOptions ,
77
55
callback : WatchCallback ,
78
56
callbackUndelayed ?: ( file : string , time : number ) => void ,
79
- ) : WebpackWatcher {
57
+ ) : ReturnType < WebpackWatchFileSystem [ 'watch' ] > {
80
58
const watchedFiles = new Set ( files ) ;
81
59
const watchedDirectories = new Set ( directories ) ;
82
60
const watchedMissing = new Set ( missing ) ;
@@ -152,7 +130,7 @@ class BuilderWatchFileSystem implements WebpackWatchFileSystem {
152
130
export class BuilderWatchPlugin {
153
131
constructor ( private readonly watcherFactory : BuilderWatcherFactory ) { }
154
132
155
- apply ( compiler : Compiler & { watchFileSystem : unknown } ) : void {
133
+ apply ( compiler : Compiler ) : void {
156
134
compiler . hooks . environment . tap ( 'BuilderWatchPlugin' , ( ) => {
157
135
compiler . watchFileSystem = new BuilderWatchFileSystem (
158
136
this . watcherFactory ,
0 commit comments