Luismahou / grunt-hashres

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.
MIT License
115 stars 41 forks source link

Sort files by length ASC #33

Closed crodas closed 10 years ago

crodas commented 10 years ago

It is useful to fix a race condition when a two or more filenames share the same postfix. Foobar.js and mobile-Foobar.js sometime Foobar.<hash>.js would replace mobile-Foobar.js.

crodas commented 10 years ago

@Luismahou everything alright with this PR? I'm using it already on production and seems fine.

Luismahou commented 10 years ago

Thanks @crodas.

This PR is breaking the build: https://travis-ci.org/Luismahou/grunt-hashres/builds/18556951 Besides, it doesn't include any tests.

This issue is something I want to work on. I know it's an important problem and I was thinking in solving it in a different way. Sorting would fix your case, but I believe it won't work if we have two files called "bar.js" and "foobar.js".

Cheers

crodas commented 10 years ago

@Luismahou I'll add the tests if it'll be accepted (and will make pass tests which are broken)

And it will work, why? Because foobar.js will be translated to foobar.<hash>.js and bar.js won't match. Or am I missing smething?

crodas commented 10 years ago

@Luismahou added tests

Luismahou commented 10 years ago

Thanks mate!

crodas commented 10 years ago

No problem, thanks for sharing it in the first place!

vincaslt commented 7 years ago

"Sort files by length ASC"

You're sorting in descending order: file hashresHelper.js line 70:

files.sort(function(a, b) {
    return b[0].length - a[0].length;
  });

It still doesn't work for me because of this. Swapping a and b does what you intended, and works for me.