From d70ba0aa26e902b8c31036b26da4092554fbf967 Mon Sep 17 00:00:00 2001 From: Justin Pomeroy Date: Thu, 19 Jul 2018 13:54:41 -0500 Subject: [PATCH 1/2] Pass the original file to the rename plugin --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 48d232b..c249a71 100644 --- a/index.js +++ b/index.js @@ -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) { From 85346dcafe14b8a86d1c0096788603f535a44006 Mon Sep 17 00:00:00 2001 From: Justin Pomeroy Date: Mon, 23 Jul 2018 14:26:06 -0500 Subject: [PATCH 2/2] Add unit tests --- test/path-parsing.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/path-parsing.spec.js b/test/path-parsing.spec.js index 9dc2af0..bfec8ba 100644 --- a/test/path-parsing.spec.js +++ b/test/path-parsing.spec.js @@ -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 }); + }); + }); });