From e1580efe9ee20bdf3ead635fe4f55212ce6ac379 Mon Sep 17 00:00:00 2001
From: shinout <shinout310@gmail.com>
Date: Mon, 8 Feb 2016 18:01:55 +0900
Subject: [PATCH 1/3] pass 'packageDir' option to transforms

---
 index.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/index.js b/index.js
index 0a8465c..b80f32b 100644
--- a/index.js
+++ b/index.js
@@ -255,6 +255,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
             trOpts = tr[1];
             tr = tr[0];
         }
+        trOpts.packageDir = pkg.__dirname;
         if (typeof tr === 'function') {
             var t = tr(file, trOpts);
             self.emit('transform', t, file);

From c4102693cecc0d563875d31dd0a5e80d47ff9018 Mon Sep 17 00:00:00 2001
From: shinout <shinout310@gmail.com>
Date: Mon, 8 Feb 2016 18:21:58 +0900
Subject: [PATCH 2/3] add test for trOpts.packageDir

---
 test/tr_opts.js                        |  2 +-
 test/tr_opts/foo/bar/hhh-value         |  1 +
 test/tr_opts/main.js                   |  2 +-
 test/tr_opts/node_modules/hhh/index.js | 22 ++++++++++++++++++++++
 test/tr_opts/package.json              |  3 ++-
 5 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 test/tr_opts/foo/bar/hhh-value
 create mode 100644 test/tr_opts/node_modules/hhh/index.js

diff --git a/test/tr_opts.js b/test/tr_opts.js
index cc821b9..2a922fc 100644
--- a/test/tr_opts.js
+++ b/test/tr_opts.js
@@ -15,7 +15,7 @@ test('transform options', function (t) {
     
     p.pipe(JSONStream.stringify()).pipe(pack).pipe(concat(function (src) {
         Function('console', src.toString('utf8'))({
-            log: function (msg) { t.equal(msg, 333) }
+            log: function (msg) { t.equal(msg, 666) }
         });
     }));
 });
diff --git a/test/tr_opts/foo/bar/hhh-value b/test/tr_opts/foo/bar/hhh-value
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/test/tr_opts/foo/bar/hhh-value
@@ -0,0 +1 @@
+2
diff --git a/test/tr_opts/main.js b/test/tr_opts/main.js
index 1f28407..d1efe1c 100644
--- a/test/tr_opts/main.js
+++ b/test/tr_opts/main.js
@@ -1 +1 @@
-console.log(FFF * GGG);
+console.log(FFF * GGG * HHH);
diff --git a/test/tr_opts/node_modules/hhh/index.js b/test/tr_opts/node_modules/hhh/index.js
new file mode 100644
index 0000000..59335f8
--- /dev/null
+++ b/test/tr_opts/node_modules/hhh/index.js
@@ -0,0 +1,22 @@
+var through = require('through2');
+var fs = require('fs');
+var path = require('path');
+
+module.exports = function (file, opts) {
+    var bufs = [];
+    return through(write, end);
+    
+    function write (buf, enc, next) {
+        if (!Buffer.isBuffer(buf)) buf = Buffer(buf);
+        bufs.push(buf);
+        next();
+    }
+    
+    function end () {
+        var str = Buffer.concat(bufs).toString('utf8');
+        var filepath = path.resolve(opts.packageDir, opts.dir, 'hhh-value');
+        var numstr = fs.readFileSync(filepath, 'utf8').trim();
+        this.push(str.replace(/HHH/g, numstr));
+        this.push(null);
+    }
+};
diff --git a/test/tr_opts/package.json b/test/tr_opts/package.json
index 6bc52d8..bf472d2 100644
--- a/test/tr_opts/package.json
+++ b/test/tr_opts/package.json
@@ -1,6 +1,7 @@
 {
   "mdtr": [
     [ "fff", { "x": 3 } ],
-    [ "ggg", { "z": 111 } ]
+    [ "ggg", { "z": 111 } ],
+    [ "hhh", { "dir": "foo/bar" } ]
   ]
 }

From 3958c48962f54cea25e0b98b4fd18fd4d4793b19 Mon Sep 17 00:00:00 2001
From: shinout <shinout310@gmail.com>
Date: Mon, 8 Feb 2016 18:28:55 +0900
Subject: [PATCH 3/3] make packageDir options optional

---
 index.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index b80f32b..8689136 100644
--- a/index.js
+++ b/index.js
@@ -255,7 +255,8 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
             trOpts = tr[1];
             tr = tr[0];
         }
-        trOpts.packageDir = pkg.__dirname;
+        if (!trOpts.packageDir)
+            trOpts.packageDir = pkg.__dirname;
         if (typeof tr === 'function') {
             var t = tr(file, trOpts);
             self.emit('transform', t, file);