55
66"use strict" ;
77
8+ const util = require ( "util" ) ;
89const Watchpack = require ( "watchpack" ) ;
910
1011/** @typedef {import("../../declarations/WebpackOptions").WatchOptions } WatchOptions */
@@ -68,7 +69,22 @@ class NodeWatchFileSystem {
6869 if ( callbackUndelayed ) {
6970 this . watcher . once ( "change" , callbackUndelayed ) ;
7071 }
72+
73+ const fetchTimeInfo = ( ) => {
74+ const fileTimeInfoEntries = new Map ( ) ;
75+ const contextTimeInfoEntries = new Map ( ) ;
76+ if ( this . watcher ) {
77+ this . watcher . collectTimeInfoEntries (
78+ fileTimeInfoEntries ,
79+ contextTimeInfoEntries
80+ ) ;
81+ }
82+ return { fileTimeInfoEntries, contextTimeInfoEntries } ;
83+ } ;
7184 this . watcher . once ( "aggregated" , ( changes , removals ) => {
85+ // pause emitting events (avoids clearing aggregated changes and removals on timeout)
86+ this . watcher . pause ( ) ;
87+
7288 if ( this . inputFileSystem && this . inputFileSystem . purge ) {
7389 const fs = this . inputFileSystem ;
7490 for ( const item of changes ) {
@@ -78,8 +94,14 @@ class NodeWatchFileSystem {
7894 fs . purge ( item ) ;
7995 }
8096 }
81- const times = this . watcher . getTimeInfoEntries ( ) ;
82- callback ( null , times , times , changes , removals ) ;
97+ const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo ( ) ;
98+ callback (
99+ null ,
100+ fileTimeInfoEntries ,
101+ contextTimeInfoEntries ,
102+ changes ,
103+ removals
104+ ) ;
83105 } ) ;
84106
85107 this . watcher . watch ( { files, directories, missing, startTime } ) ;
@@ -99,39 +121,71 @@ class NodeWatchFileSystem {
99121 this . watcher . pause ( ) ;
100122 }
101123 } ,
102- getAggregatedRemovals : ( ) => {
103- const items = this . watcher && this . watcher . aggregatedRemovals ;
104- if ( items && this . inputFileSystem && this . inputFileSystem . purge ) {
105- const fs = this . inputFileSystem ;
106- for ( const item of items ) {
107- fs . purge ( item ) ;
124+ getAggregatedRemovals : util . deprecate (
125+ ( ) => {
126+ const items = this . watcher && this . watcher . aggregatedRemovals ;
127+ if ( items && this . inputFileSystem && this . inputFileSystem . purge ) {
128+ const fs = this . inputFileSystem ;
129+ for ( const item of items ) {
130+ fs . purge ( item ) ;
131+ }
108132 }
109- }
110- return items ;
111- } ,
112- getAggregatedChanges : ( ) => {
113- const items = this . watcher && this . watcher . aggregatedChanges ;
114- if ( items && this . inputFileSystem && this . inputFileSystem . purge ) {
133+ return items ;
134+ } ,
135+ "Watcher.getAggregatedRemovals is deprecated in favor of Watcher.getInfo since that's more performant." ,
136+ "DEP_WEBPACK_WATCHER_GET_AGGREGATED_REMOVALS"
137+ ) ,
138+ getAggregatedChanges : util . deprecate (
139+ ( ) => {
140+ const items = this . watcher && this . watcher . aggregatedChanges ;
141+ if ( items && this . inputFileSystem && this . inputFileSystem . purge ) {
142+ const fs = this . inputFileSystem ;
143+ for ( const item of items ) {
144+ fs . purge ( item ) ;
145+ }
146+ }
147+ return items ;
148+ } ,
149+ "Watcher.getAggregatedChanges is deprecated in favor of Watcher.getInfo since that's more performant." ,
150+ "DEP_WEBPACK_WATCHER_GET_AGGREGATED_CHANGES"
151+ ) ,
152+ getFileTimeInfoEntries : util . deprecate (
153+ ( ) => {
154+ return fetchTimeInfo ( ) . fileTimeInfoEntries ;
155+ } ,
156+ "Watcher.getFileTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant." ,
157+ "DEP_WEBPACK_WATCHER_FILE_TIME_INFO_ENTRIES"
158+ ) ,
159+ getContextTimeInfoEntries : util . deprecate (
160+ ( ) => {
161+ return fetchTimeInfo ( ) . contextTimeInfoEntries ;
162+ } ,
163+ "Watcher.getContextTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant." ,
164+ "DEP_WEBPACK_WATCHER_CONTEXT_TIME_INFO_ENTRIES"
165+ ) ,
166+ getInfo : ( ) => {
167+ const removals = this . watcher && this . watcher . aggregatedRemovals ;
168+ const changes = this . watcher && this . watcher . aggregatedChanges ;
169+ if ( this . inputFileSystem && this . inputFileSystem . purge ) {
115170 const fs = this . inputFileSystem ;
116- for ( const item of items ) {
117- fs . purge ( item ) ;
171+ if ( removals ) {
172+ for ( const item of removals ) {
173+ fs . purge ( item ) ;
174+ }
175+ }
176+ if ( changes ) {
177+ for ( const item of changes ) {
178+ fs . purge ( item ) ;
179+ }
118180 }
119181 }
120- return items ;
121- } ,
122- getFileTimeInfoEntries : ( ) => {
123- if ( this . watcher ) {
124- return this . watcher . getTimeInfoEntries ( ) ;
125- } else {
126- return new Map ( ) ;
127- }
128- } ,
129- getContextTimeInfoEntries : ( ) => {
130- if ( this . watcher ) {
131- return this . watcher . getTimeInfoEntries ( ) ;
132- } else {
133- return new Map ( ) ;
134- }
182+ const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo ( ) ;
183+ return {
184+ changes,
185+ removals,
186+ fileTimeInfoEntries,
187+ contextTimeInfoEntries
188+ } ;
135189 }
136190 } ;
137191 }
0 commit comments