grunt-newer
grunt-newer copied to clipboard
Add option to invalidate cache when Gruntfile.js changes
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'
]);
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']
}
}
}
These 2 issues are similar: https://github.com/tschaub/grunt-newer/issues/83 https://github.com/tschaub/grunt-newer/issues/32