Skip to content

Commit

Permalink
Merge pull request #8 from neb/master
Browse files Browse the repository at this point in the history
Preserve the pipeline's order
  • Loading branch information
galkinrost committed Jul 29, 2015
2 parents dd245ae + 77c202f commit bdd2a4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
17 changes: 9 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,24 @@ module.exports = function override() {
hashedPath: relPath(path.resolve(firstFile.base), file.path),
file: file
});

// sort by filename length to not replace the common part(s) of several filenames
f.sort(function (a, b) {
if(a.origPath.length > b.origPath.length) return -1;
if(a.origPath.length < b.origPath.length) return 1;
return 0;
});
}
cb();
}, function (cb) {
var self = this;

// sort by filename length to not replace the common part(s) of several filenames
var longestFirst = f.slice().sort(function (a, b) {
if(a.origPath.length > b.origPath.length) return -1;
if(a.origPath.length < b.origPath.length) return 1;
return 0;
});

f.forEach(function (_f) {
var file = _f.file;

if ((allowedPathRegExp.test(file.revOrigPath) ) && file.contents) {
var contents = file.contents.toString();
f.forEach(function (__f) {
longestFirst.forEach(function (__f) {
var origPath = __f.origPath.replace(new RegExp('\\' + path.sep, 'g'), '/').replace(/\./g, '\\.');
var hashedPath = __f.hashedPath.replace(new RegExp('\\' + path.sep, 'g'), '/');
contents = contents.replace(
Expand Down
18 changes: 18 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var gulp = require('gulp');
var fse = require('fs-extra');
var override = require('./index');
var expect = require('chai').expect;
var through = require('through2');

describe('gulp-rev-css-url', function () {
beforeEach(function (done) {
Expand Down Expand Up @@ -57,5 +58,22 @@ describe('gulp-rev-css-url', function () {
});
});

it('Should not reorder the pipeline', function (done) {
var outputOrder = [];
gulp.src(['./fixtures/scripts/script.js', './fixtures/scripts/application.js'])
.pipe(rev())
.pipe(override())
.pipe(through.obj(
function (file, enc, cb) {
outputOrder.push(file.revOrigPath.replace(file.revOrigBase, ''));
cb(null, file);
},
function (cb) {
expect(outputOrder).to.deep.equal(['script.js', 'application.js']);
done();
}
));
});

});

0 comments on commit bdd2a4e

Please sign in to comment.