Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maxwoo-houzz opened this issue Aug 27, 2019 · 7 comments · May be fixed by #4150
Open

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

maxwoo-houzz opened this issue Aug 27, 2019 · 7 comments · May be fixed by #4150
Assignees

Comments

@maxwoo-houzz
Copy link

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

@sokra
Copy link
Member

sokra commented Aug 27, 2019

Sounds good, send a PR

@alexander-akait
Copy link
Member

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

@Schweinepriester
Copy link

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
Copy link
Member

Yes, let's documented this

@alexander-akait alexander-akait transferred this issue from webpack/webpack Oct 28, 2020
@alexander-akait
Copy link
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
Copy link

// 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
Copy link

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

@snitin315 snitin315 self-assigned this Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants