grunt-s3
grunt-s3 copied to clipboard
Error: "has no method 'replace'" when src is array
Using fresh install from Git repository link (0.1.0 with Grunt 0.4.0rc7).
Here is my grunt-s3 configuration:
s3: {
key: '<%= aws.key %>',
secret: '<%= aws.secret %>',
bucket: '<%= aws.bucket %>',
access: 'public-read',
upload: [
{
rel: '<%= siteConfig.output %>',
src: ['<%= siteConfig.output %>/**/*.*', '!<%= siteConfig.output %>/js/*.js', '!<%= siteConfig.output %>/css/*.css', '!<%= siteConfig.output %>/img/*.*' ],
dest: '/',
gzip: true
},
{
rel: '<%= siteConfig.output %>',
src: ['<%= siteConfig.output %>/js/*.js', '<%= siteConfig.output %>/css/*.css', '<%= siteConfig.output %>/img/*.*'],
dest: '/',
gzip: true,
headers: { 'Cache-Control': 'public, max-age=' + (60 * 60 * 24 * 365) }
}
]
}
Seems to work fine when src properties are not arrays, but I get the following error with the above configuration:
Warning: Object /Users/Andrew/Dropbox/Projects/andrewduthie.com/output/**/*.*,!/Users/Andrew/Dropbox/Projects/andrewduthie.com/output/js/*.js,!/Users/Andrew/Dropbox/Projects/andrewduthie.com/output/css/*.css,!/Users/Andrew/Dropbox/Projects/andrewduthie.com/output/img/*.* has no method 'replace' Use --force to continue.
From my own debugging, seems to be caused at s3.js:54
upload.src = path.resolve(grunt.template.process(upload.src));
When I change upload.src to file, it seems to work correctly for me, but I'm not familiar enough with it to be able to say it's a fix in all cases.
Yeah, src doesn't support Arrays, but it absolutely should. I consider this a bug. I will look into it ASAP. In the mean time you can (painfully, I know), specify separate upload objects.
Please just use this.files instead of parsing src yourself. Grunt this for you and it just works. See Creating Tasks and Creating Plugins. Please follow the files conventions.
@davidpfahler can you elaborate on what you mean?
I think what @davidpfahler is eluding to can be found here https://github.com/gruntjs/grunt/wiki/Inside-Tasks#inside-multi-tasks. Grunt has file path parsing built in already, might as well use it to keep things DRY. In the meantime, wrapping that offending line identified by @aduth with:
if (Object.prototype.toString.call(upload.src) != '[object Array]') {
upload.src = path.resolve(grunt.template.process(upload.src));
}
seems to do the trick.
I’m running into this issue as well. I second the notion of using grunt’s built-in support for processing src+dest pairs inside tasks. The link provided by @danhapgood above is out of date, please see http://gruntjs.com/api/inside-tasks#this.files.
I was running in to the same issue, and what @danhapgood said fixed it! Thanks.