[Pkg-javascript-commits] [node-module-deps] 98/444: load an entry file from a stream, in-place

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:47:46 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 c249e48dd6579bafa6eb81f44f948df31a767d17
Author: James Halliday <mail at substack.net>
Date:   Sun Jun 9 11:22:35 2013 -0700

    load an entry file from a stream, in-place
---
 index.js       | 45 ++++++++++++++++++++++++++++++++++-----------
 test/stream.js |  1 +
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/index.js b/index.js
index bd31450..19b2b48 100644
--- a/index.js
+++ b/index.js
@@ -6,7 +6,7 @@ var browserResolve = require('browser-resolve');
 var nodeResolve = require('resolve');
 var detective = require('detective');
 var through = require('through');
-var concatStream = require('concat-stream');
+var concat = require('concat-stream');
 
 module.exports = function (mains, opts) {
     if (!opts) opts = {};
@@ -14,7 +14,7 @@ module.exports = function (mains, opts) {
     
     if (!Array.isArray(mains)) mains = [ mains ].filter(Boolean);
     mains = mains.map(function (file) {
-        return path.resolve(file);
+        return typeof file === 'object' ? file : path.resolve(file);
     });
     
     var visited = {};
@@ -39,6 +39,24 @@ module.exports = function (mains, opts) {
     function walk (id, parent, cb) {
         pending ++;
         
+        if (id && typeof id === 'object' && typeof id.pipe === 'function') {
+            return id.pipe(concat(function (src) {
+                var n = Math.floor(Math.pow(16,8) * Math.random()).toString(16);
+                var basedir = opts.basedir || process.cwd();
+                var file = path.join(basedir, 'fake_' + n + '.js');
+                var pkgfile = path.join(basedir, 'package.json');
+                fs.readFile(pkgfile, function (err, pkgsrc) {
+                    var pkg = {};
+                    if (!err) {
+                        try { pkg = JSON.parse(pkgsrc) }
+                        catch (e) {};
+                    }
+                    var trx = getTransform(pkg);
+                    applyTransforms(file, trx, src, pkg);
+                });
+            }));
+        }
+        
         var c = opts.cache && opts.cache[parent.id];
         var resolver = c && typeof c === 'object'
         && !Buffer.isBuffer(c) && c.deps[id]
@@ -63,14 +81,7 @@ module.exports = function (mains, opts) {
             }
             visited[file] = true;
             
-            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);
-            }
+            var trx = getTransform(pkg);
             
             if (cache && cache[file]) {
                 parseDeps(file, cache[file], pkg);
@@ -82,6 +93,18 @@ module.exports = function (mains, opts) {
         });
     }
     
+    function getTransform (pkg) {
+        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);
+        }
+        return trx;
+    }
+    
     function applyTransforms (file, trx, src, pkg) {
         var isTopLevel = mains.some(function (main) {
             var m = path.relative(path.dirname(main), file);
@@ -96,7 +119,7 @@ module.exports = function (mains, opts) {
                 if (err) return output.emit('error', err);
                 
                 s.on('error', output.emit.bind(output, 'error'));
-                s.pipe(concatStream(function (data) {
+                s.pipe(concat(function (data) {
                     src = data;
                     ap(trs.slice(1));
                 }));
diff --git a/test/stream.js b/test/stream.js
index 1ed377d..9fd9ffd 100644
--- a/test/stream.js
+++ b/test/stream.js
@@ -18,4 +18,5 @@ test('read from a stream', function (t) {
     }));
     
     tr.queue('t.ok(true)');
+    tr.queue(null);
 });

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