55
66"use strict" ;
77
8+ const util = require ( "util" ) ;
89const Watchpack = require ( "watchpack" ) ;
910
1011/** @typedef {import("../../declarations/WebpackOptions").WatchOptions } WatchOptions */
@@ -69,8 +70,21 @@ class NodeWatchFileSystem {
6970 this . watcher . once ( "change" , callbackUndelayed ) ;
7071 }
7172
72- let fileMap , directoryMap ;
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+ } ;
7384 this . watcher . once ( "aggregated" , ( changes , removals ) => {
85+ // pause emitting events (avoids clearing aggregated changes and removals on timeout)
86+ this . watcher . pause ( ) ;
87+
7488 if ( this . inputFileSystem && this . inputFileSystem . purge ) {
7589 const fs = this . inputFileSystem ;
7690 for ( const item of changes ) {
@@ -80,10 +94,14 @@ class NodeWatchFileSystem {
8094 fs . purge ( item ) ;
8195 }
8296 }
83- fileMap = new Map ( ) ;
84- directoryMap = new Map ( ) ;
85- this . watcher . collectTimeInfoEntries ( fileMap , directoryMap ) ;
86- callback ( null , fileMap , directoryMap , changes , removals ) ;
97+ const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo ( ) ;
98+ callback (
99+ null ,
100+ fileTimeInfoEntries ,
101+ contextTimeInfoEntries ,
102+ changes ,
103+ removals
104+ ) ;
87105 } ) ;
88106
89107 this . watcher . watch ( { files, directories, missing, startTime } ) ;
@@ -103,47 +121,71 @@ class NodeWatchFileSystem {
103121 this . watcher . pause ( ) ;
104122 }
105123 } ,
106- getAggregatedRemovals : ( ) => {
107- const items = this . watcher && this . watcher . aggregatedRemovals ;
108- if ( items && this . inputFileSystem && this . inputFileSystem . purge ) {
109- const fs = this . inputFileSystem ;
110- for ( const item of items ) {
111- 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+ }
112132 }
113- }
114- return items ;
115- } ,
116- getAggregatedChanges : ( ) => {
117- const items = this . watcher && this . watcher . aggregatedChanges ;
118- 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 ) {
119170 const fs = this . inputFileSystem ;
120- for ( const item of items ) {
121- 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+ }
122180 }
123181 }
124- return items ;
125- } ,
126- getFileTimeInfoEntries : ( ) => {
127- if ( fileMap ) return fileMap ;
128- if ( this . watcher ) {
129- this . watcher . collectTimeInfoEntries (
130- ( fileMap = new Map ( ) ) ,
131- ( directoryMap = new Map ( ) )
132- ) ;
133- return fileMap ;
134- }
135- return new Map ( ) ;
136- } ,
137- getContextTimeInfoEntries : ( ) => {
138- if ( directoryMap ) return directoryMap ;
139- if ( this . watcher ) {
140- this . watcher . collectTimeInfoEntries (
141- ( fileMap = new Map ( ) ) ,
142- ( directoryMap = new Map ( ) )
143- ) ;
144- return directoryMap ;
145- }
146- return new Map ( ) ;
182+ const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo ( ) ;
183+ return {
184+ changes,
185+ removals,
186+ fileTimeInfoEntries,
187+ contextTimeInfoEntries
188+ } ;
147189 }
148190 } ;
149191 }
0 commit comments