Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it so that passed-in 'paths' are respected when loading transforms #120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions test/files/findme/findme-transform.js
Original file line number Diff line number Diff line change
@@ -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();
});
};
2 changes: 2 additions & 0 deletions test/files/findme/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = {};
// abcdef
24 changes: 24 additions & 0 deletions test/tr_paths.js
Original file line number Diff line number Diff line change
@@ -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');
});
});