Skip to content

now that mtimes has been removed from watchpack, how do we get all changed/removed files? #4106

Open
@maxwoo-houzz

Description

@maxwoo-houzz

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

Activity

sokra

sokra commented on Aug 27, 2019

@sokra
Member

Sounds good, send a PR

alexander-akait

alexander-akait commented on Aug 27, 2019

@alexander-akait
Member

@sokra i think we should implement this in webpack@5 before stable release, can we move this in yes?

Schweinepriester

Schweinepriester commented on Oct 27, 2020

@Schweinepriester

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('===============================');
            }
        });
    }
}
alexander-akait

alexander-akait commented on Oct 28, 2020

@alexander-akait
Member

Yes, let's documented this

alexander-akait

alexander-akait commented on Oct 28, 2020

@alexander-akait
Member

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;
stefanprobst

stefanprobst commented on Nov 21, 2021

@stefanprobst
// 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?

malopgrics

malopgrics commented on Nov 25, 2021

@malopgrics

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
self-assigned this
on Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @sokra@Schweinepriester@alexander-akait@stefanprobst@snitin315

    Issue actions

      now that `mtimes` has been removed from watchpack, how do we get all changed/removed files? · Issue #4106 · webpack/webpack.js.org