[Pkg-javascript-commits] [node-module-deps] 156/444: fix a bug in the transform key walker to not be completely broken

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:47:51 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 97639cebdedcfe019ccbda1485ee675a32e4efa4
Author: James Halliday <mail at substack.net>
Date:   Fri Jan 3 21:59:30 2014 -0800

    fix a bug in the transform key walker to not be completely broken
---
 index.js     | 32 +++++++++++++++++++++-----------
 package.json |  2 +-
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/index.js b/index.js
index f1d90e9..4f6b3cb 100644
--- a/index.js
+++ b/index.js
@@ -167,15 +167,14 @@ module.exports = function (mains, opts) {
         var trx = [];
         if (opts.transformKey) {
             var n = pkg;
-            opts.transformKey.forEach(function (key) {
-                if (n && typeof n === 'object') n = n[key];
-            });
-            trx = [].concat(n).filter(Boolean).map(function (x) {
-                if (pkg && pkg.__dirname && /^\./.test(x)) {
-                    return path.resolve(pkg.__dirname, x);
-                }
-                return x;
-            });
+            var keys = opts.transformKey;
+            for (var i = 0; i < keys.length; i++) {
+                if (n && typeof n === 'object') n = n[keys[i]];
+                else break;
+            }
+            if (i === keys.length) {
+                trx = [].concat(n).filter(Boolean);
+            }
         }
         return trx.concat(opts.globalTransform || []);
     }
@@ -190,7 +189,14 @@ module.exports = function (mains, opts) {
         
         (function ap (trs) {
             if (trs.length === 0) return done();
-            makeTransform(file, trs[0], function (err, s) {
+            makeTransform(file, trs[0], function f (err, s) {
+                if (err && pkg && pkg.__dirname) {
+                    var t = path.resolve(pkg.__dirname, trs[0]);
+                    return makeTransform(file, t, function (e, s_) {
+                        if (e) output.emit('error', e);
+                        else f(null, s_);
+                    });
+                }
                 if (err) return output.emit('error', err);
                 
                 s.on('error', output.emit.bind(output, 'error'));
@@ -279,7 +285,11 @@ module.exports = function (mains, opts) {
                 ' while transforming ', file
             ].join('')));
             
-            cb(null, require(res)(file));
+            var r = require(res);
+            if (typeof r !== 'function') {
+                cb(new Error('transform not a function'));
+            }
+            else cb(null, r(file));
         });
     }
 };
diff --git a/package.json b/package.json
index 050ede5..60674e6 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
   "dependencies": {
     "through": "~2.3.4",
     "JSONStream": "~0.7.1",
-    "browser-resolve": "~1.2.1",
+    "browser-resolve": "~1.2.2",
     "resolve": "~0.6.0",
     "detective": "~2.1.2",
     "concat-stream": "~1.3.1",

-- 
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