chrisdanford / grunt-ver

MIT License
19 stars 15 forks source link

References replacements have no concept of path #4

Open stuartf opened 11 years ago

stuartf commented 11 years ago

If you hash two files on different paths that have the same filename all references that get replaced will only use the same hash. For instance if you have MathJax in your path like:

vendor/js/MathJax/jax/input/AsciiMath/config.js
vendor/js/MathJax/jax/input/MathML/config.js
vendor/js/MathJax/jax/input/TeX/config.js
vendor/js/MathJax/jax/output/HTML-CSS/config.js
vendor/js/MathJax/jax/output/NativeMML/config.js
vendor/js/MathJax/jax/output/SVG/config.js

Then when you hash it you get something like:

vendor/js/MathJax/jax/output/SVG/config.02437fe5.js
vendor/js/MathJax/jax/output/HTML-CSS/config.5ada570d.js
vendor/js/MathJax/jax/output/NativeMML/config.53a6cc82.js
vendor/js/MathJax/jax/input/MathML/config.49dbdf64.js
vendor/js/MathJax/jax/input/TeX/config.5b950842.js
vendor/js/MathJax/jax/input/AsciiMath/config.20e7393e.js

So far so good, but when you look in a file that references one of those say vendor/js/MathJax/jax/input/MathML/config.49dbdf64.js for example, you'll find stuff like:

MathJax.InputJax.MathML.loadComplete("config.20e7393e.js");

Which should actually be:

MathJax.InputJax.MathML.loadComplete("config.49dbdf64.js");

Separating the processing into phases won't fix this, but separate tasks will. For a large project it can result in a lot of headaches.

mattandrews commented 8 years ago

This might not be related, but I'm finding that running the task several times with two phases results in changing file hashes in the output file for unchanged assets.

This is my task config:

ver: {
    myapp: {
        phases: [{
            files: [
                '<%= dirs.publicDir.images %>/**/*'
            ],
            references: [
                "<%= dirs.publicDir.stylesheets %>/**/*"
            ]
        }, {
            files: [
                "<%= dirs.publicDir.stylesheets %>/**/*.css",
                "<%= dirs.publicDir.javascripts %>/**/*.js"
            ]
        }],
        baseDirFrom: 'public/dist',
        baseDirTo: 'public/',
        versionFile: '<%= dirs.assets.root %>/<%= filenames.assets %>',
    }
}

When I run it, some of the images (and only images) hashes change in the output file. When I take out the second phase (which doesn't run on the images), this stops happening.

I don't think this is a misconfiguration on my part as I'm following the examples in this repo's readme. I even ran md5 against the image files and confirmed they're unchanged so the hashes really should be consistent.

This might not be related to your issue, @stuartf, but it might be an indication that this plugin just isn't quite production-ready.

nadnoslen commented 8 years ago

Hey @mattandrews, That hash issue is a bug. I forked, fixed, and made a pull request for it but it hasn't been accepted. I guess I could create an issue for it and it might get some traction.

You can grab my fork if you want and it will likely fix this issue for you. In your package.json point to the fork:

...
"devDependencies": {
  ...
  "grunt-ver": "git://github.com/nadnoslen/grunt-ver.git",
  ...
}
...
nadnoslen commented 8 years ago

Issue #13 created concerning the previous hashing comments.