From cb50d8161fa372bcfa8c55130b3c212a86f7b209 Mon Sep 17 00:00:00 2001 From: Reimer Date: Thu, 15 Sep 2016 14:55:52 -0600 Subject: [PATCH 1/2] add test to ensure passed 'paths' option is respected --- test/files/findme/findme-transform.js | 8 ++++++++ test/files/findme/main.js | 2 ++ test/tr_paths.js | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/files/findme/findme-transform.js create mode 100644 test/files/findme/main.js create mode 100644 test/tr_paths.js diff --git a/test/files/findme/findme-transform.js b/test/files/findme/findme-transform.js new file mode 100644 index 0000000..2a58962 --- /dev/null +++ b/test/files/findme/findme-transform.js @@ -0,0 +1,8 @@ +var through = require('through2'); + +module.exports = function (file) { + return through(function (buf, enc, next) { + this.push(String(buf).replace(/abcdef/g, '123456')); + next(); + }); +}; diff --git a/test/files/findme/main.js b/test/files/findme/main.js new file mode 100644 index 0000000..595daa8 --- /dev/null +++ b/test/files/findme/main.js @@ -0,0 +1,2 @@ +module.exports = {}; +// abcdef diff --git a/test/tr_paths.js b/test/tr_paths.js new file mode 100644 index 0000000..f1b3ed1 --- /dev/null +++ b/test/tr_paths.js @@ -0,0 +1,24 @@ +var mdeps = require('../'); +var test = require('tap').test; +var JSONStream = require('JSONStream'); +var packer = require('browser-pack'); +var path = require('path'); + +test('transform', function (t) { + t.plan(2); + var p = mdeps({ + transform: [ 'findme-transform' ], + paths: [ path.join(__dirname, '/files/findme') ] + }); + p.end(path.join(__dirname, '/files/findme/main.js')); + var pack = packer(); + + p.pipe(JSONStream.stringify()).pipe(pack); + + var src = ''; + pack.on('data', function (buf) { src += buf }); + pack.on('end', function () { + t.ok(src.indexOf('abcdef') === -1, 'contains un-transformed output'); + t.ok(src.indexOf('123456') > -1, 'missing transformed output'); + }); +}); From 7c76b434d144679b0be7da57851657dea6d765cf Mon Sep 17 00:00:00 2001 From: Reimer Date: Thu, 15 Sep 2016 14:59:20 -0600 Subject: [PATCH 2/2] respect passed 'paths' option. also allows NODE_PATH to work --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4047e4e..3df7320 100644 --- a/index.js +++ b/index.js @@ -270,7 +270,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) { } function loadTransform (id, trOpts, cb) { - var params = { basedir: path.dirname(file) }; + var params = { basedir: path.dirname(file), paths: self.paths }; nodeResolve(id, params, function nr (err, res, again) { if (err && again) return cb && cb(err);