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
Only running multi-tasks for file targets that have changed #593
Comments
Any task can store persistent data in a database, temp file, etc. Grunt just runs tasks. |
Hey Ryan, Thanks for taking the time to share this idea with us! I just wanted to chime in to say that this could potentially be a really cool concept, but Ben is right, the implementation belongs outside of Grunt itself (we're moving in the direction of Grunt itself being a task runner only). That said, if you take a stab at making this and you find it works well, please let us know! Your solution likely wouldn't fit within the task runner itself, but it might find a home as a dependency somewhere. |
^ What he said |
Hmm.. Okay. I agree that the implementation itself belongs outside of What I'm thinking is basically a node.js module that exposes a filter method that takes the expanded form of the files object and returns those that have changed. This module would need to keep track of the files and the first time it was asked to filter it would simply record hashes and successive times it would compute and compare to filter the lists. Or perhaps a method |
Reliably determining which files have been modified is not as simple as it seems ;) This can be handled in grunt-contrib-watch without modifying grunt's core. It already essentially does what you're describing... just doesn't have an option to feed the modified files to the tasks yet. I think this just needs to be implemented. |
But it would be a lot more flexible if tasks were able to filter themselves by checking if files were modified with some utility library. That way watch doesn't care. It just re-runs tasks. Also running
I'll agree that it is not simple. But, yes, it is easy Maintaining an in-memory database (that is persisted to a file) of MD5 hashes of file contents and referencing this when asked if a file has changed is easy but complex.
That has hack written all over it. It will work for some cases sure. But its not flexible or powerful enough. All |
See the Example using grunt.initConfig({
coffee: {
all: {
expand: true,
cwd: 'path/to/src/',
src: '**/*.coffee',
dest: 'path/to/dest/',
ext: '.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-newer');
grunt.registerTask('compile', 'newer:coffee'); With the above config, running |
Let's say we have a repository with several
.coffee
files under asrc/
directory with a rootGruntfile.js
. ThisGruntfile.js
defines options for thegrunt-contrib-coffee
task (which it has loaded). Upon initially executinggrunt coffee
, every.coffee
file insrc/
is ran through thegrunt-contrib-coffee
task. Upon executinggrunt coffee
again, nothing happens. Becausegrunt
knows that the.coffee
files haven't changed therefore it has filtered the file mapping down to only the destination targets in which one or more of its source files have changed.If
grunt
were to maintain a simple hash of source file contents it could easily filter the file list for multi-target tasks.See gruntjs/grunt-contrib-watch#22 (comment) for more of my rambling.
Does this make sense to anyone? It seems this would be an awesome addition and allow for something like
grunt-contrib-watch
to just re-run tasks when it thinks files changed and not worry about anything becausegrunt
-itself filters thefile
lists.The text was updated successfully, but these errors were encountered: