[Pkg-javascript-commits] [node-module-deps] 409/444: Transforms should be applied if row.file and row.expose are equal
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:48:18 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-module-deps.
commit 7d7fe1dbfbf7f56c6c03bf05aab27f50364284ef
Author: Joris van der Wel <joris at jorisvanderwel.com>
Date: Sun Nov 29 13:24:26 2015 +0100
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
---
index.js | 6 +++++-
test/row_expose_name_is_file_transform.js | 32 +++++++++++++++++++++++++++++++
test/row_expose_transform.js | 31 ++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index 0f2f55a..e3baa80 100644
--- a/index.js
+++ b/index.js
@@ -311,6 +311,10 @@ Deps.prototype.walk = function (id, parent, cb) {
}
self.resolve(id, parent, function (err, file, pkg, fakePath) {
+ // this is checked early because parent.modules is also modified
+ // by this function.
+ var builtin = has(parent.modules, id);
+
if (rec.expose) {
// Set options.expose to make the resolved pathname available to the
// caller. They may or may not have requested it, but it's harmless
@@ -366,7 +370,7 @@ Deps.prototype.walk = function (id, parent, cb) {
self.readFile(file, id, pkg)
.pipe(self.getTransforms(fakePath || file, pkg, {
- builtin: has(parent.modules, id)
+ builtin: builtin
}))
.pipe(concat(function (body) {
fromSource(file, body.toString('utf8'), pkg);
diff --git a/test/row_expose_name_is_file_transform.js b/test/row_expose_name_is_file_transform.js
new file mode 100644
index 0000000..d93ec1f
--- /dev/null
+++ b/test/row_expose_name_is_file_transform.js
@@ -0,0 +1,32 @@
+var parser = require('../');
+var test = require('tap').test;
+var through = require('through2');
+var path = require('path');
+
+// test that (non global) transforms are applied to an exposed module, where in the
+// exposed name is identical to the file path.
+test('row is exposed with a name equal to the path, and transformed', function (t) {
+ t.plan(2);
+ var exposed_path = path.join(__dirname, '/files/main.js');
+ var found_exposed_path = false;
+ var opts = {
+ expose: {},
+ transform: function(file) {
+ if (file === exposed_path) {
+ found_exposed_path = true;
+ }
+ return through();
+ }
+ };
+
+ var p = parser(opts);
+ p.end({ file: exposed_path, expose: exposed_path });
+ p.on('error', t.fail.bind(t));
+
+ p.pipe(through.obj());
+
+ p.on('end', function () {
+ t.equal(opts.expose[exposed_path], exposed_path);
+ t.ok(found_exposed_path);
+ });
+});
diff --git a/test/row_expose_transform.js b/test/row_expose_transform.js
new file mode 100644
index 0000000..1b2d9ee
--- /dev/null
+++ b/test/row_expose_transform.js
@@ -0,0 +1,31 @@
+var parser = require('../');
+var test = require('tap').test;
+var through = require('through2');
+var path = require('path');
+
+// test that (non global) transforms are applied to an exposed module
+test('row is exposed and transformed', function (t) {
+ t.plan(2);
+ var exposed_path = path.join(__dirname, '/files/main.js');
+ var found_exposed_path = false;
+ var opts = {
+ expose: {},
+ transform: function(file) {
+ if (file === exposed_path) {
+ found_exposed_path = true;
+ }
+ return through();
+ }
+ };
+
+ var p = parser(opts);
+ p.end({ file: exposed_path, expose: "whatever" });
+ p.on('error', t.fail.bind(t));
+
+ p.pipe(through.obj());
+
+ p.on('end', function () {
+ t.equal(opts.expose.whatever, exposed_path);
+ t.ok(found_exposed_path);
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-module-deps.git
More information about the Pkg-javascript-commits
mailing list