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

Don't automatically add "ext" options as it makes it impossible to keep original filename #91

Closed
wants to merge 4 commits into from

Conversation

netpro2k
Copy link
Contributor

As per discussion in #79

existing extension without issue (see
gruntjs#79) if the user
wishes to add an extension they can do so via ext or rename.
@tkellen
Copy link
Member

tkellen commented Mar 15, 2014

@netpro2k Can you fix the failing tests please?

@netpro2k
Copy link
Contributor Author

Updated the tests to not expect any extensions. Thought about adding a test for extensions, but this should be covered already in tests for the grunt file API.

@RasterBurn
Copy link

👍 to this PR. I have the same issue where I want to upload compressed files to my CDN without renaming them to $basename.gz. For now I can use ext: '' and pin the grunt version to 0.4.2 and it works. But the new behavior of ext in 0.4.3 (see: gruntjs/grunt#1087) is breaking it for me.

@tkellen
Copy link
Member

tkellen commented Mar 26, 2014

Sorry for the delay on this everyone. @netpro2k, this would be a minor version bump (to 0.8) as it breaks backwards compat. Could you please add some documentation to /docs/compress-overview.md for people upgrading from the old behavior to the new? As soon as that is in I will get this merged and published.

@moodh
Copy link

moodh commented Apr 14, 2014

How is the progress with this pull request? It would let me clean up my Gruntfile quite a lot. :) Thanks!

@jamesplease
Copy link
Member

@moodh we're just waiting on a rebase and some docs. If you wanted to clean up the branch and open a new PR it would be merged!

@thomasgumz
Copy link

For anyone who wants to prevent their compressed files automatically getting renamed to the ".gz" extension, simply add ext: function(ext) {return ext}, like in the example below. Works great with grunt 0.4.5 and compress 0.9.1. I had this issue (need to upload gzip'ed files to AmazonS3 with their original file name) and ended up here via google...

compress: {
    options: {
        mode: 'gzip',
    },
    all: {
        expand: true,
        cwd: './content/',
        src: ['**'],
        dest: './final/',
        filter: 'isFile',
        // keep the original .ext(ension) rather than *.ext.gz
        ext: function(ext) {return ext}
    },
}

@moodh
Copy link

moodh commented May 26, 2014

@tgumz worth noting, that only works if the source and destination is different folders, otherwise they all end up (with the correct extension) as 20byte files. Hopefully this pull request fixes that. =)

@ChrisWren
Copy link

Any other changes this needs @tkellen?

@tkellen tkellen closed this in 4a553bf Jul 14, 2014
@tkellen
Copy link
Member

tkellen commented Jul 14, 2014

Nope! Sorry about the wait here ya'll. @netpro2k in the future, please don't increment versions in your PRs--it often causes needless conflicts when the version changes after a PR has been made. Also, many projects have a specific workflow for cutting releases.

@tkellen
Copy link
Member

tkellen commented Jul 14, 2014

In the wild as 0.10

@radkodinev
Copy link
Contributor

/ping @tkellen, @netpro2k

There's a side effect as a consequence of that change and it may be quite confusing. Bear with me, please.

If you have a file named jquery.pluginname.e732af12.js (e.g. that went throught grunt-filerev) and the following config:

compress: {
    options: {
        mode: 'gzip'
    },
    all: {
        expand: true,
        cwd: 'public/scripts',
        src: '**/*.js',
        dest: 'public/scripts'
        // notice `ext` was not provided
    },
}

Now, with the merged change, the default behavior in that case would be to overwrite jquery.pluginname.e732af12.js with the compressed file (how reasonable that is seems questionable to me). If you want the compressed file to be a different one, with the same name but an extension appended (e.g. jquery.pluginname.e732af12.js.gz), providing ext: '.js.gz' won't work because the output file would be jquery.js.gz. The reason is that Grunt considers everything after the first . to be the extension and it gets stripped from the destination filename before appending the given ext. So in this case the extensions is .pluginname.e732af12.js and the destination file becomes jquery.js.gz. It's even funnier if you have the files backbone.ae0af2f4.js, backbone.babysitter.b7863617.js and backbone.wreqr.b53adeeb.js - you get backbone.js.gz as destination three times (effectively the 2nd overwriting the 1st, and the 3rd overwriting the 2nd compressed file).

My solution/workaround was to use:

   ext: function (ext) { return ext + '.gz'; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants