From 3e49f4897cb5170d81c9028bc4e5c922f77cbeb5 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 12 Jan 2014 22:28:17 -0700 Subject: [PATCH] Compare to previous run time if src and dest are the same --- lib/util.js | 9 +++++++++ test/lib/util.spec.js | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/util.js b/lib/util.js index 07c459a..5c14279 100644 --- a/lib/util.js +++ b/lib/util.js @@ -75,6 +75,15 @@ var filterFilesByTime = exports.filterFilesByTime = function(files, previous, // dest file not yet created, use all src files return done(null, obj); } + if (obj.src && obj.src.length === 1 && obj.src[0] === obj.dest) { + // when src and dest are same, compare to previous + return filterPathsByTime(obj.src, previous, function(err, src) { + if (err) { + return done(err); + } + done(null, {src: src, dest: obj.dest}); + }); + } return anyNewer(obj.src, stats.mtime, function(err, any) { done(err, any && obj); }); diff --git a/test/lib/util.spec.js b/test/lib/util.spec.js index e69cae9..1a39314 100644 --- a/test/lib/util.spec.js +++ b/test/lib/util.spec.js @@ -187,6 +187,32 @@ describe('util', function() { }); }); + it('provides newer src files if same as dest', function(done) { + var files = [{ + src: ['src/js/a.js'], + dest: 'src/js/a.js' + }, { + src: ['src/js/b.js'], + dest: 'src/js/b.js' + }, { + src: ['src/js/c.js'], + dest: 'src/js/c.js' + }]; + util.filterFilesByTime(files, new Date(150), function(err, results) { + assert.isNull(err); + assert.equal(results.length, 2); + var first = results[0]; + assert.equal(first.dest, 'src/js/b.js'); + assert.equal(first.src.length, 1); + assert.deepEqual(first.src, files[1].src); + var second = results[1]; + assert.equal(second.dest, 'src/js/c.js'); + assert.equal(second.src.length, 1); + assert.deepEqual(second.src, files[2].src); + done(); + }); + }); + it('provides files newer than previous if no dest', function(done) { var files = [{ src: ['src/js/a.js', 'src/js/b.js', 'src/js/c.js']