Skip to content

Commit 17d44ec

Browse files
author
contra
committed
Merge pull request #56 from Josiah/clone-original-file
Clone the original file prior to renaming
2 parents ba5ab6d + 5001e08 commit 17d44ec

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ function gulpRename(obj) {
1616
};
1717
}
1818

19-
stream._transform = function (file, unused, callback) {
19+
stream._transform = function (originalFile, unused, callback) {
2020

21+
22+
var file = originalFile.clone({contents: false});
2123
var parsedPath = parsePath(file.relative);
2224
var path;
2325

test/rename.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/* global helper, helperError */
33

44
require('./spec-helper');
5+
var rename = require('../');
6+
var gulp = require('gulp');
7+
var Path = require('path');
58

69
describe('gulp-rename', function () {
710
context('with string parameter', function () {
@@ -172,6 +175,50 @@ describe('gulp-rename', function () {
172175
});
173176
});
174177

178+
context('in parallel streams', function () {
179+
it('only changes the file in the current stream', function (done) {
180+
var files = gulp.src('test/fixtures/hello.txt');
181+
182+
var pipe1 = files.pipe(rename({suffix: '-1'}));
183+
var pipe2 = files.pipe(rename({suffix: '-2'}));
184+
var end1 = false;
185+
var end2 = false;
186+
var file1;
187+
var file2;
188+
189+
pipe1
190+
.on('data', function (file) {
191+
file1 = file;
192+
})
193+
.on('end', function () {
194+
end1 = true;
195+
196+
if (end2) {
197+
return check();
198+
}
199+
});
200+
201+
pipe2
202+
.on('data', function (file) {
203+
file2 = file;
204+
})
205+
.on('end', function () {
206+
end2 = true;
207+
208+
if (end1) {
209+
return check();
210+
}
211+
});
212+
213+
function check() {
214+
file1.path.should.equal(Path.resolve('test/fixtures/hello-1.txt'));
215+
file2.path.should.equal(Path.resolve('test/fixtures/hello-2.txt'));
216+
217+
return done();
218+
}
219+
});
220+
});
221+
175222
context('throws unsupported parameter type', function () {
176223
var srcPattern;
177224
beforeEach(function () {

0 commit comments

Comments
 (0)