ember-cli / broccoli-asset-rev

Broccoli plugin to add fingerprint checksums and CDN URLs to your assets
MIT License
86 stars 83 forks source link

Fix broccoli-filter breakage #75

Closed joliss closed 9 years ago

joliss commented 9 years ago

broccoli-asset-rev is using broccoli-filter in a bit of an unusual way, so it was affected by changes we thought would be non-breaking.

For what it's worth, I don't think it really benefits from broccoli-filter's caching functionality, so perhaps it's easier to derive this directly from broccoli-plugin at some point.

rickharrison commented 9 years ago

Thanks Jo! Sorry for the private api usage :x

Do you have any tips on how we could add caching to this? Personally, I'd like to run my plugin during development, but it just takes too long. Not sure what the best approach would be to introduce caching.

joliss commented 9 years ago

You mean for caching hashes? I'd say run your own cache, e.g. using a plain JS object.

// pseudocode
build = function() {
  var newCache = {}
  var filePaths = walkSync(this.inputPaths[0]) // or similar
  for file in filePaths {
    var stats = fs.statSync(file)
    var statsHash = require('broccoli-kitchen-sink-helpers').hashStats(stats, file)
    var contentHash = (this.cache[statsHash] || this.computeHash(file)) // computeHash reads the file from disk
    newCache[statsHash] = contentHash

    // now you have contentHash, so you can symlinkOrCopy from this.inputPaths[0] to this.outputPath
  }
  this.cache = newCache // this takes care of expiring old cache entries
}

The above should work without help from broccoli-filter - you can derive from broccoli-plugin directly.