grunt-newer
grunt-newer copied to clipboard
New files not being detected when src and dest are the same
A bit more info. I'm using grunt-contrib-imagemin to optimise some folders of images, and grunt-newer to stop imagemin from optimising files it has already optimised.
I'm not sure if I'm just misunderstanding how grunt-newer works, but it doesn't seem to detect when I add new files to my image directories. It just says "No newer files to process":
$ grunt
Running "concurrent:first" (concurrent) task
Running "newer:imagemin" (newer) task
Running "newer:imagemin:dist" (newer) task
No newer files to process.
Done, without errors.
Done, without errors.
It seems the reason for this is because in my config I've set my source and destination directories to be the same location (which was intentional) - see my config below:
module.exports = {
options: {
cache: false,
optimizationLevel: 7, // (png) 0-7, 7 being the most optimised, but the slowest to execute
progressive: true, // (jpeg)
interlaced: true, // (gif)
},
dist: {
files: [{
expand: true,
cwd: 'public_html/',
src: [
'assets/**/*.{png,jpg,gif}',
'shop/media/**/*.{png,jpg,gif}'
],
dest: 'public_html/'
}]
}
};
Is there a way round this?
I'm dealing with this exact issue as well.
It seems like we can force grunt-newer into thinking that it's in the mode where there's only src and no dest then it should work (a naïve guess based on reading the README.)
Just tested my theory by changing lib/util.js line 72 from if (obj.dest) {
to if (false) {
and it does work as intended. I can't see a way to do this in an override and as of present there's no way to set a per-task options or I'd implement it myself.
I'm happy to fix it but I'm not sure what opinion you want imposed on it.
@btholt Looking forward to seeing if this gets implemented. I'll be revisiting my imagemin/newer project sometime next week so maybe @tschaub will have had a chance to look at it by then ;)
We're also running into this issue. Any thoughts on when the pull request might be merged @tschaub? Thanks.
@btholt's change merged (see #42). Test cases added (see #62). [email protected]
published.
Please report back about whether this addresses your issues.
Alas, can reproduce the issue using grunt-newer v.0.8.0. Shall I open a new issue with my config?
but it is still doesn't work...
Package version -
[email protected]
The problem persists in v1.1.0. I could solve it with the following override:
var fs=require('fs');
then in config:
newer:
{
options:
{
override: function(details, include)
{
//check if the was created after details.time and force run
var stats=fs.statSync(details.path);
include(stats.ctime.getTime()>details.time.getTime());
}
}
}
In the plugin mtime is used instead of ctime, and this may be the problem, since mtime is set with the last modification. If you are importing a file with git or bower, mtime may be older than the last time you last run the task. I tried to run the new plugin checking ctime, but had no success and at the time I have no time to look deeper in the plugin code. Still the code above is a quick fix for all newer tasks where files are added.