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