@@ -133,11 +133,7 @@ namespace ts {
133
133
}
134
134
135
135
/* @internal */
136
- export function createDynamicPriorityPollingWatchFile ( host : System ) : HostWatchFile {
137
- if ( ! host . getModifiedTime || ! host . setTimeout ) {
138
- throw notImplemented ( ) ;
139
- }
140
-
136
+ export function createDynamicPriorityPollingWatchFile ( host : { getModifiedTime : System [ "getModifiedTime" ] ; setTimeout : System [ "setTimeout" ] ; } ) : HostWatchFile {
141
137
interface WatchedFile extends ts . WatchedFile {
142
138
isClosed ?: boolean ;
143
139
unchangedPolls : number ;
@@ -555,6 +551,8 @@ namespace ts {
555
551
} ,
556
552
readFile,
557
553
writeFile,
554
+ watchFile : getWatchFile ( ) ,
555
+ watchDirectory : getWatchDirectory ( ) ,
558
556
resolvePath : path => _path . resolve ( path ) ,
559
557
fileExists,
560
558
directoryExists,
@@ -574,14 +572,7 @@ namespace ts {
574
572
return process . env [ name ] || "" ;
575
573
} ,
576
574
readDirectory,
577
- getModifiedTime ( path ) {
578
- try {
579
- return _fs . statSync ( path ) . mtime ;
580
- }
581
- catch ( e ) {
582
- return undefined ;
583
- }
584
- } ,
575
+ getModifiedTime,
585
576
createHash : _crypto ? createMD5HashUsingNativeCrypto : generateDjb2Hash ,
586
577
getMemoryUsage ( ) {
587
578
if ( global . gc ) {
@@ -625,9 +616,6 @@ namespace ts {
625
616
process . stdout . write ( "\x1Bc" ) ;
626
617
}
627
618
} ;
628
-
629
- nodeSystem . watchFile = getWatchFile ( ) ;
630
- nodeSystem . watchDirectory = getWatchDirectory ( ) ;
631
619
return nodeSystem ;
632
620
633
621
function isFileSystemCaseSensitive ( ) : boolean {
@@ -654,13 +642,13 @@ namespace ts {
654
642
return fsWatchFile ;
655
643
case "DynamicPriorityPolling" :
656
644
// Use polling interval but change the interval depending on file changes and their default polling interval
657
- return createDynamicPriorityPollingWatchFile ( nodeSystem ) ;
645
+ return createDynamicPriorityPollingWatchFile ( { getModifiedTime , setTimeout } ) ;
658
646
case "UseFsEvents" :
659
647
// Use notifications from FS to watch with falling back to fs.watchFile
660
648
return watchFileUsingFsWatch ;
661
649
case "UseFsEventsWithFallbackDynamicPolling" :
662
650
// Use notifications from FS to watch with falling back to dynamic watch file
663
- dynamicPollingWatchFile = createDynamicPriorityPollingWatchFile ( nodeSystem ) ;
651
+ dynamicPollingWatchFile = createDynamicPriorityPollingWatchFile ( { getModifiedTime , setTimeout } ) ;
664
652
return createWatchFileUsingDynamicWatchFile ( dynamicPollingWatchFile ) ;
665
653
case "UseFsEventsOnParentDirectory" :
666
654
// Use notifications from FS to watch with falling back to fs.watchFile
@@ -683,7 +671,7 @@ namespace ts {
683
671
const watchDirectory = tscWatchDirectory === "RecursiveDirectoryUsingFsWatchFile" ?
684
672
createWatchDirectoryUsing ( fsWatchFile ) :
685
673
tscWatchDirectory === "RecursiveDirectoryUsingDynamicPriorityPolling" ?
686
- createWatchDirectoryUsing ( dynamicPollingWatchFile || createDynamicPriorityPollingWatchFile ( nodeSystem ) ) :
674
+ createWatchDirectoryUsing ( dynamicPollingWatchFile || createDynamicPriorityPollingWatchFile ( { getModifiedTime , setTimeout } ) ) :
687
675
watchDirectoryUsingFsWatch ;
688
676
const watchDirectoryRecursively = createRecursiveDirectoryWatcher ( {
689
677
filePathComparer : useCaseSensitiveFileNames ? compareStringsCaseSensitive : compareStringsCaseInsensitive ,
@@ -1027,6 +1015,15 @@ namespace ts {
1027
1015
return filter < string > ( _fs . readdirSync ( path ) , dir => fileSystemEntryExists ( combinePaths ( path , dir ) , FileSystemEntryKind . Directory ) ) ;
1028
1016
}
1029
1017
1018
+ function getModifiedTime ( path : string ) {
1019
+ try {
1020
+ return _fs . statSync ( path ) . mtime ;
1021
+ }
1022
+ catch ( e ) {
1023
+ return undefined ;
1024
+ }
1025
+ }
1026
+
1030
1027
/**
1031
1028
* djb2 hashing algorithm
1032
1029
* http://www.cse.yorku.ca/~oz/hash.html
0 commit comments