tschaub / grunt-newer

Configure Grunt tasks to run with newer files only.
https://npmjs.org/package/grunt-newer
MIT License
945 stars 53 forks source link

New files not being detected when src and dest are the same #40

Open matt-bailey opened 10 years ago

matt-bailey commented 10 years ago

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?

btholt commented 10 years ago

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.)

btholt commented 10 years ago

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.

matt-bailey commented 10 years ago

@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 ;)

leigeber commented 9 years ago

We're also running into this issue. Any thoughts on when the pull request might be merged @tschaub? Thanks.

tschaub commented 9 years ago

@btholt's change merged (see #42). Test cases added (see #62). grunt-newer@0.8.0 published.

Please report back about whether this addresses your issues.

skip405 commented 9 years ago

Alas, can reproduce the issue using grunt-newer v.0.8.0. Shall I open a new issue with my config?

trikon commented 9 years ago

but it is still doesn't work... image Package version - grunt-newer@0.8.0

ghost commented 8 years ago

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.