@@ -63,26 +63,73 @@ namespace ts {
6363 /* @internal */
6464 export const missingFileModifiedTime = new Date ( 0 ) ; // Any subsequent modification will occur after this time
6565
66- enum ChunkSize {
67- Low = 32 ,
68- Medium = 64 ,
69- High = 256
66+ interface Levels {
67+ Low : number ;
68+ Medium : number ;
69+ High : number ;
7070 }
7171
72- function chunkSize ( pollingInterval : PollingInterval ) {
73- switch ( pollingInterval ) {
74- case PollingInterval . Low :
75- return ChunkSize . Low ;
76- case PollingInterval . Medium :
77- return ChunkSize . Medium ;
78- case PollingInterval . High :
79- return ChunkSize . High ;
80- }
72+ function createPollingIntervalBasedLevels ( levels : Levels ) {
73+ return {
74+ [ PollingInterval . Low ] : levels . Low ,
75+ [ PollingInterval . Medium ] : levels . Medium ,
76+ [ PollingInterval . High ] : levels . High
77+ } ;
8178 }
8279
83- /*@internal */
84- export function unChangedThreshold ( pollingInterval : PollingInterval ) {
85- return chunkSize ( pollingInterval ) ;
80+ const defaultChunkLevels : Levels = { Low : 32 , Medium : 64 , High : 256 } ;
81+ let pollingChunkSize = createPollingIntervalBasedLevels ( defaultChunkLevels ) ;
82+ /* @internal */
83+ export let unchangedPollThresholds = createPollingIntervalBasedLevels ( defaultChunkLevels ) ;
84+
85+ /* @internal */
86+ export function setCustomPollingValues ( system : System ) {
87+ if ( ! system . getEnvironmentVariable ) {
88+ return ;
89+ }
90+ const pollingIntervalChanged = setCustomLevels ( "TSC_WATCH_POLLINGINTERVAL" , PollingInterval ) ;
91+ pollingChunkSize = getCustomPollingBasedLevels ( "TSC_WATCH_POLLINGCHUNKSIZE" , defaultChunkLevels ) || pollingChunkSize ;
92+ unchangedPollThresholds = getCustomPollingBasedLevels ( "TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS" , defaultChunkLevels ) || unchangedPollThresholds ;
93+
94+ function getLevel ( envVar : string , level : keyof Levels ) {
95+ return system . getEnvironmentVariable ( `${ envVar } _${ level . toUpperCase ( ) } ` ) ;
96+ }
97+
98+ function getCustomLevels ( baseVariable : string ) {
99+ let customLevels : Partial < Levels > | undefined ;
100+ setCustomLevel ( "Low" ) ;
101+ setCustomLevel ( "Medium" ) ;
102+ setCustomLevel ( "High" ) ;
103+ return customLevels ;
104+
105+ function setCustomLevel ( level : keyof Levels ) {
106+ const customLevel = getLevel ( baseVariable , level ) ;
107+ if ( customLevel ) {
108+ ( customLevels || ( customLevels || { } ) ) [ level ] = Number ( customLevel ) ;
109+ }
110+ }
111+ }
112+
113+ function setCustomLevels ( baseVariable : string , levels : Levels ) {
114+ const customLevels = getCustomLevels ( baseVariable ) ;
115+ if ( customLevels ) {
116+ setLevel ( "Low" ) ;
117+ setLevel ( "Medium" ) ;
118+ setLevel ( "High" ) ;
119+ return true ;
120+ }
121+ return false ;
122+
123+ function setLevel ( level : keyof Levels ) {
124+ levels [ level ] = customLevels [ level ] || levels [ level ] ;
125+ }
126+ }
127+
128+ function getCustomPollingBasedLevels ( baseVariable : string , defaultLevels : Levels ) {
129+ let customLevels = getCustomLevels ( baseVariable ) ;
130+ return ( pollingIntervalChanged || customLevels ) &&
131+ createPollingIntervalBasedLevels ( customLevels ? { ...defaultLevels , ...customLevels } : defaultLevels ) ;
132+ }
86133 }
87134
88135 /* @internal */
@@ -138,7 +185,7 @@ namespace ts {
138185 }
139186
140187 function pollPollingIntervalQueue ( queue : PollingIntervalQueue ) {
141- queue . pollIndex = pollQueue ( queue , queue . pollingInterval , queue . pollIndex , chunkSize ( queue . pollingInterval ) ) ;
188+ queue . pollIndex = pollQueue ( queue , queue . pollingInterval , queue . pollIndex , pollingChunkSize [ queue . pollingInterval ] ) ;
142189 // Set the next polling index and timeout
143190 if ( queue . length ) {
144191 scheduleNextPoll ( queue . pollingInterval ) ;
@@ -190,7 +237,7 @@ namespace ts {
190237 addChangedFileToLowPollingIntervalQueue ( watchedFile ) ;
191238 }
192239 }
193- else if ( watchedFile . unchangedPolls !== unChangedThreshold ( pollingInterval ) ) {
240+ else if ( watchedFile . unchangedPolls !== unchangedPollThresholds [ pollingInterval ] ) {
194241 watchedFile . unchangedPolls ++ ;
195242 }
196243 else if ( queue === changedFilesInLastPoll ) {
@@ -575,6 +622,7 @@ namespace ts {
575622 process . stdout . write ( "\x1Bc" ) ;
576623 }
577624 } ;
625+
578626 nodeSystem . watchFile = getWatchFile ( ) ;
579627 nodeSystem . watchDirectory = getWatchDirectory ( ) ;
580628 return nodeSystem ;
@@ -1063,6 +1111,7 @@ namespace ts {
10631111 } ) ( ) ;
10641112
10651113 if ( sys && sys . getEnvironmentVariable ) {
1114+ setCustomPollingValues ( sys ) ;
10661115 Debug . currentAssertionLevel = / ^ d e v e l o p m e n t $ / i. test ( sys . getEnvironmentVariable ( "NODE_ENV" ) )
10671116 ? AssertionLevel . Normal
10681117 : AssertionLevel . None ;
0 commit comments