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

Add option to invalidate cache when Gruntfile.js changes #90

Open
dmartin-gh opened this issue Jan 9, 2016 · 2 comments
Open

Add option to invalidate cache when Gruntfile.js changes #90

dmartin-gh opened this issue Jan 9, 2016 · 2 comments

Comments

@dmartin-gh
Copy link

When using grunt-jscs or grunt-contrib-jshint, editing your linting rules does not cause your entire source tree to be re-linted unless you run grunt clean or manually remove the .cache/ directory. This can lead to mistakenly thinking your source tree is compliant with the linting changes until you run a clean build at a later time.

It would be nice if there was an option to grunt-newer to tell it to invalidate the entire .cache/ directory if Gruntfile.js has been modified since the last run. Finding a solution that also works with load-grunt-config could be tricky.

If you're not using load-grunt-config, a workaround is (Unix only):

/** Clear grunt-newer cache when gruntfile.js changes */
function maybeClearNewerCache(grunt) {
    var lastRunTime;
    try {
        lastRunTime = fs.statSync('.grunt-record').mtime;
    } catch (e) {
        lastRunTime = new Date(0);
    }   

    if (fs.statSync(__filename).mtime > lastRunTime) {
        var cmd = { cmd: 'rm', args: ['-rf', './node_modules/grunt-newer/.cache'] };
        grunt.util.spawn(cmd, function (error, result, code) {
            if (error) { grunt.fatal(error); }
        }); 
    }   
}
maybeClearNewerCache(grunt);
grunt.registerTask('record', 'Record the build time', function () {
    grunt.file.write('.grunt-record', 'blah');
});
grunt.registerTask('default', [
    ... // other tasks here
    'record'
]);
@shospodarets
Copy link

It's not only Gruntfile.js
There are plenty options:
.eslintrc
.jshintrc
and others.
So the best if there would be an options to define that for particular task on changing some files cache must be cleaned.
E.g.:

newer: {
 options: {
  ...
  revalidate: {
   "eslint": ['.eslintrc', '.eslintignore'],
   "jshint": ['.jshintrc', '.jshintignore']
  }
 }
}

@shospodarets
Copy link

These 2 issues are similar:
#83
#32

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

2 participants