Skip to content

Commit

Permalink
Merge pull request #82 from jrpomeroy/include-file-obj
Browse files Browse the repository at this point in the history
Pass the original file to the rename plugin
  • Loading branch information
contra authored Jul 23, 2018
2 parents 5a1f34b + 85346dc commit 82b1c4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function gulpRename(obj, options) {

} else if (type === 'function') {

obj(parsedPath);
obj(parsedPath, file);
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);

} else if (type === 'object' && obj !== undefined && obj !== null) {
Expand Down
23 changes: 23 additions & 0 deletions test/path-parsing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,27 @@ describe('gulp-rename path parsing', function () {
helper(srcPattern, obj, null, done, { multiExt: true });
});
});

describe('original file context', function () {
it('passed to plugin as second argument', function (done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function (path, file) {
file.should.be.instanceof(Object);
file.should.be.ok();
};
helper(srcPattern, obj, null, done, { multiExt: true });
});

it('has expected properties', function (done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function (path, file) {
file.path.should.equal(Path.resolve(srcPattern));
file.base.should.equal(Path.dirname(Path.resolve(srcPattern)));
file.basename.should.equal(Path.basename(srcPattern));
file.relative.should.equal(Path.basename(srcPattern));
file.extname.should.equal(Path.extname(srcPattern));
};
helper(srcPattern, obj, null, done, { multiExt: true });
});
});
});

0 comments on commit 82b1c4c

Please sign in to comment.