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

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

Open
matt-bailey opened this issue May 2, 2014 · 8 comments
Open

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

matt-bailey opened this issue May 2, 2014 · 8 comments

Comments

@matt-bailey
Copy link

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

btholt commented May 8, 2014

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

btholt commented May 8, 2014

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

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

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

@tschaub
Copy link
Owner

tschaub commented Oct 21, 2014

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

skip405 commented Oct 28, 2014

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

@trikon
Copy link

trikon commented Oct 28, 2014

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

@ghost
Copy link

ghost commented Aug 19, 2015

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.

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

No branches or pull requests

6 participants