Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/asset-rev.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ function AssetRev(inputTree, options) {
this.replaceExtensions = options.replaceExtensions || defaults.replaceExtensions;
this.exclude = exclude;
this.fingerprintAssetMap = options.fingerprintAssetMap || defaults.fingerprintAssetMap;
this.generateAssetMap = options.generateAssetMap;
this.generateRailsManifest = options.generateRailsManifest;
this.assetMapPath = options.assetMapPath || defaults.assetMapPath;
this.railsManifestPath = options.railsManifestPath || defaults.railsManifestPath;
this.prepend = options.prepend || defaults.prepend;
Expand All @@ -29,12 +27,16 @@ function AssetRev(inputTree, options) {
// first pass - excludes replaceable source code
this.exclude = exclude.slice();
this.replaceExtensions.forEach(function(ext) { this.exclude.push('**/*.' + ext); }, this);
this.generateAssetMap = false; // Don't generate asset maps in this step
this.generateRailsManifest = false; // Don't generate rails manifest in this step
var fingerprintTree = Fingerprint(inputTree, this);
var assetRewrite = UseRev(fingerprintTree, this);

// second pass - fingerprints replaceable source code
this.exclude = exclude;
this.onlyHash = this.replaceExtensions;
this.generateAssetMap = options.generateAssetMap; // Do generate an asset map (if the options is enabled)
this.generateRailsManifest = options.generateRailsManifest; // Do generate a rails (if the options is enabled)
var fingerprintTree2 = Fingerprint(assetRewrite, this);
var assetRewrite2 = UseRev(fingerprintTree2, this);

Expand Down
18 changes: 15 additions & 3 deletions tests/filter-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ function confirmPathPresent(list, pattern) {
});
}

function countPathMatches(list, pattern) {
const count = list.reduce((count, current) => {
if (current.search(pattern) !== -1) {
return count + 1;
}
return count;
}, 0)

return count;
}

describe('broccoli-asset-rev', function() {
afterEach(function() {
if (builder) {
Expand Down Expand Up @@ -213,7 +224,7 @@ describe('broccoli-asset-rev', function() {
);

var mappedFiles = actualFiles.filter(function(name) {
if (-1 !== name.lastIndexOf('assetMap.json')) return true;
if (-1 !== name.lastIndexOf('assetMap.json')) return false; // AssetMap should not be included in the asset map
for (var i = 0; i < extensions.length; ++i) {
if (-1 !== name.lastIndexOf(extensions[i])) {
return fs.statSync(path.join(graph.directory, name)).isFile();
Expand Down Expand Up @@ -248,9 +259,10 @@ describe('broccoli-asset-rev', function() {
builder = new broccoli.Builder(node);
return builder.build().then(function(graph) {
var actualFiles = walkSync(graph.directory);
var pathPresent = confirmPathPresent(actualFiles, /assetMap-[0-9a-f]{32}\.json/);
var matches = countPathMatches(actualFiles, /assetMap-[0-9a-f]{32}\.json/);

assert(pathPresent, "fingerprinted asset map file not found");
assert((matches > 0), "fingerprinted asset map file not found");
assert((matches < 2), "more than 1 asset map file found");
});
});

Expand Down
Loading