grunt
grunt copied to clipboard
`cwd` option should also be available when `expand` is undefined (or false)
Using the cwd
option when defining a fileset has no effect if the expand
option has not been enabled. Under some circumstances, it would be very handful to prefix the current fileset with the defined cwd
option value.
Here is a common usecase (uglify & concatenate):
uglify: {
app: {
files: [{
cwd: '<%= pkg.target %>',
src: '<%= pkg.resources.js %>', // JS resources are dynamic and ordered!
dest: '<%= pkg.target %>js/<%= pkg.name %>.min.js'
}]
}
}
When adding the expand
option, Grunt creates a file mapping for the uglify
task, which outputs multiple minified resources.
It took me a while to find a workaround for that:
uglify: {
app: {
files: [{
src: '{<%= _prefixSrc(pkg.target, pkg.resources.js) %>}', // Note the brackets!
dest: '<%= pkg.target %>min/<%= pkg.name %>.min.js'
}]
}
},
_prefixSrc: function(prefix, files) {
return files.map(function(file){
return prefix + file;
});
},
Seems that the current usage is misleading and this feature could be useful to others as well, cf.: #917
https://github.com/gruntjs/grunt-contrib-copy/pull/169 http://stackoverflow.com/questions/28847471/grunt-how-to-build-the-files-object-dynamically http://stackoverflow.com/questions/15284556/how-can-i-run-a-grunt-task-from-within-a-grunt-task http://stackoverflow.com/questions/15927368/gruntjs-use-files-with-dynamic-mapping-in-multitask-config-once-for-all-targets http://stackoverflow.com/questions/22098528/lazily-evaluate-grunt-task-options
According to #1403 (specifically this comment) this sounds like a good candidate for 0.4.7. It's a very simple fix and makes the grunt API less surprising. 0.4.6 already has a bunch of issues assigned to it.
The only question is: do we consider this a breaking change or not? E.g. currently you can specify cwd
and know it'll be ignored without expand
. Technically breaking, but not really a big deal. I'd argue that it makes perfect sense to use cwd
without expand
, and anyone relying on cwd
being ignored should just update their code.
anyone relying on cwd being ignored should just update their code.
I agree, :+1: