Skip to content

Commit 7d7fe1d

Browse files
Transforms should be applied if row.file and row.expose are equal
The provided test case "row_expose_name_is_file_transform" fails without this fix. Also see #105
1 parent 2faff74 commit 7d7fe1d

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ Deps.prototype.walk = function (id, parent, cb) {
311311
}
312312

313313
self.resolve(id, parent, function (err, file, pkg, fakePath) {
314+
// this is checked early because parent.modules is also modified
315+
// by this function.
316+
var builtin = has(parent.modules, id);
317+
314318
if (rec.expose) {
315319
// Set options.expose to make the resolved pathname available to the
316320
// caller. They may or may not have requested it, but it's harmless
@@ -366,7 +370,7 @@ Deps.prototype.walk = function (id, parent, cb) {
366370

367371
self.readFile(file, id, pkg)
368372
.pipe(self.getTransforms(fakePath || file, pkg, {
369-
builtin: has(parent.modules, id)
373+
builtin: builtin
370374
}))
371375
.pipe(concat(function (body) {
372376
fromSource(file, body.toString('utf8'), pkg);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var parser = require('../');
2+
var test = require('tap').test;
3+
var through = require('through2');
4+
var path = require('path');
5+
6+
// test that (non global) transforms are applied to an exposed module, where in the
7+
// exposed name is identical to the file path.
8+
test('row is exposed with a name equal to the path, and transformed', function (t) {
9+
t.plan(2);
10+
var exposed_path = path.join(__dirname, '/files/main.js');
11+
var found_exposed_path = false;
12+
var opts = {
13+
expose: {},
14+
transform: function(file) {
15+
if (file === exposed_path) {
16+
found_exposed_path = true;
17+
}
18+
return through();
19+
}
20+
};
21+
22+
var p = parser(opts);
23+
p.end({ file: exposed_path, expose: exposed_path });
24+
p.on('error', t.fail.bind(t));
25+
26+
p.pipe(through.obj());
27+
28+
p.on('end', function () {
29+
t.equal(opts.expose[exposed_path], exposed_path);
30+
t.ok(found_exposed_path);
31+
});
32+
});

test/row_expose_transform.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var parser = require('../');
2+
var test = require('tap').test;
3+
var through = require('through2');
4+
var path = require('path');
5+
6+
// test that (non global) transforms are applied to an exposed module
7+
test('row is exposed and transformed', function (t) {
8+
t.plan(2);
9+
var exposed_path = path.join(__dirname, '/files/main.js');
10+
var found_exposed_path = false;
11+
var opts = {
12+
expose: {},
13+
transform: function(file) {
14+
if (file === exposed_path) {
15+
found_exposed_path = true;
16+
}
17+
return through();
18+
}
19+
};
20+
21+
var p = parser(opts);
22+
p.end({ file: exposed_path, expose: "whatever" });
23+
p.on('error', t.fail.bind(t));
24+
25+
p.pipe(through.obj());
26+
27+
p.on('end', function () {
28+
t.equal(opts.expose.whatever, exposed_path);
29+
t.ok(found_exposed_path);
30+
});
31+
});

0 commit comments

Comments
 (0)