6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
+ import type { FSWatcher as ChokidarWatcher } from 'chokidar' ;
9
10
import fs , {
10
11
PathLike ,
11
12
Stats ,
@@ -20,7 +21,7 @@ import fs, {
20
21
unlinkSync ,
21
22
writeFileSync ,
22
23
} from 'fs' ;
23
- import { dirname as pathDirname , join as pathJoin } from 'path' ;
24
+ import { dirname as pathDirname } from 'path' ;
24
25
import { Observable , concat , from as observableFrom , of , throwError } from 'rxjs' ;
25
26
import { concatMap , map , mergeMap , publish , refCount } from 'rxjs/operators' ;
26
27
import {
@@ -34,18 +35,6 @@ import {
34
35
virtualFs ,
35
36
} from '../src' ;
36
37
37
- interface ChokidarWatcher {
38
- // eslint-disable-next-line @typescript-eslint/no-misused-new
39
- new ( options : { } ) : ChokidarWatcher ;
40
-
41
- add ( path : string ) : ChokidarWatcher ;
42
- on ( type : 'change' , cb : ( path : string ) => void ) : ChokidarWatcher ;
43
- on ( type : 'add' , cb : ( path : string ) => void ) : ChokidarWatcher ;
44
- on ( type : 'unlink' , cb : ( path : string ) => void ) : ChokidarWatcher ;
45
-
46
- close ( ) : void ;
47
- }
48
-
49
38
async function exists ( path : PathLike ) : Promise < boolean > {
50
39
try {
51
40
await fsPromises . access ( path , constants . F_OK ) ;
@@ -59,7 +48,7 @@ async function exists(path: PathLike): Promise<boolean> {
59
48
// This will only be initialized if the watch() method is called.
60
49
// Otherwise chokidar appears only in type positions, and shouldn't be referenced
61
50
// in the JavaScript output.
62
- let FSWatcher : ChokidarWatcher ;
51
+ let FSWatcher : typeof ChokidarWatcher ;
63
52
function loadFSWatcher ( ) {
64
53
if ( ! FSWatcher ) {
65
54
try {
@@ -161,7 +150,8 @@ export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
161
150
) : Observable < virtualFs . HostWatchEvent > | null {
162
151
return new Observable < virtualFs . HostWatchEvent > ( ( obs ) => {
163
152
loadFSWatcher ( ) ;
164
- const watcher = new FSWatcher ( { persistent : true } ) . add ( getSystemPath ( path ) ) ;
153
+ const watcher = new FSWatcher ( { persistent : true } ) ;
154
+ watcher . add ( getSystemPath ( path ) ) ;
165
155
166
156
watcher
167
157
. on ( 'change' , ( path ) => {
@@ -308,9 +298,9 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
308
298
_options ?: virtualFs . HostWatchOptions ,
309
299
) : Observable < virtualFs . HostWatchEvent > | null {
310
300
return new Observable < virtualFs . HostWatchEvent > ( ( obs ) => {
311
- const opts = { persistent : false } ;
312
301
loadFSWatcher ( ) ;
313
- const watcher = new FSWatcher ( opts ) . add ( getSystemPath ( path ) ) ;
302
+ const watcher = new FSWatcher ( { persistent : false } ) ;
303
+ watcher . add ( getSystemPath ( path ) ) ;
314
304
315
305
watcher
316
306
. on ( 'change' , ( path ) => {
0 commit comments