webpack.js.org
webpack.js.org copied to clipboard
now that `mtimes` has been removed from watchpack, how do we get all changed/removed files?
Feature request
What is the expected behavior?
It seems like the new version of WatchPack (v2.0.0) are getting rid of the mtimes
variable. However, from my research it seems like that variable was the only way to get the list of changed files that triggered a re-compilation (source).
As such, there should be an alternative way to get this list of changed files.
What is motivation or use case for adding/changing the behavior?
Seems like a pretty useful feature for the watchRun
hook, as there are already a couple people (including me) that use it.
How should this be implemented in your opinion?
Watchpack actually provides the info we need, in the variable filesModified
that it passes to Watching.js. However, Watching.js doesn't use it at all. Ideally I think this variable should be provided in the watchRun
hook, but it should also be fine to just store it as a property just like how it's done with removedFiles
, eg in Watching.js:
this.compiler.filesModified = filesModified;
Are you willing to work on this yourself? yes
Sounds good, send a PR
@sokra i think we should implement this in webpack@5 before stable release, can we move this in yes
?
The PR was merged last year, but I think more docs would be great, as it seems like the change is only mentioned vaguely once in https://webpack.js.org/blog/2020-10-10-webpack-5-release/#new-watching, no other documentation.
It also captures more information about filesystem while watching. It now captures mtimes and watches event times, as well as information about missing files. For this, the
WatchFileSystem
API changed a little bit. While on it we also converted Arrays to Sets and Objects to Maps.
Luckily I was able to figure it out - the tests were esp. helpful - and changed our usage of the plugin mentioned by @maxwoo-houzz
as there are already a couple people (including me) that use it.
like so:
class WatchRunPlugin {
apply(compiler) {
compiler.hooks.watchRun.tap('WatchRun', (comp) => {
if (comp.modifiedFiles) {
const changedFiles = Array.from(comp.modifiedFiles, (file) => `\n ${file}`).join('');
console.log('===============================');
console.log('FILES CHANGED:', changedFiles);
console.log('===============================');
}
});
}
}
Yes, let's documented this
We have 4 variables here:
// Timestamps for files
this.compiler.fileTimestamps;
// Timestamps for directories
this.compiler.contextTimestamps;
// Removed files
this.compiler.removedFiles;
// Modified files
this.compiler.modifiedFiles;
// Timestamps for directories this.compiler.contextTimestamps;
for directories, I am seeing empty objects in compiler.contextTimestamps
- is that expected?
// Removed files this.compiler.removedFiles; // Modified files this.compiler.modifiedFiles;
is there also anything like addedFiles
?
is there also anything like addedFiles?
I done a console.log
of each keys in compiler
that contains the string file
or File
, and it output this :
compiler.outputFileSystem
compiler.intermediateFileSystem
compiler.inputFileSystem
compiler.watchFileSystem
compiler.modifiedFiles
compiler.removedFiles
compiler._assetEmittingWrittenFiles
compiler._assetEmittingPreviousFiles