[Pkg-javascript-commits] [node-module-deps] 52/444: use a callback to avoid stream buffering

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:47:42 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 a22fca6ebc75685ac63a2f4cc3159c537e40a6e0
Author: James Halliday <mail at substack.net>
Date:   Wed Feb 27 17:34:35 2013 -0800

    use a callback to avoid stream buffering
---
 index.js     | 31 ++++++++++++-------------------
 package.json |  3 +--
 2 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/index.js b/index.js
index 3b08e00..0de12c2 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,6 @@ var fs = require('fs');
 var path = require('path');
 var spawn = require('child_process').spawn;
 var parseShell = require('shell-quote').parse;
-var duplexer = require('duplexer');
 
 var browserResolve = require('browser-resolve');
 var nodeResolve = require('resolve');
@@ -79,16 +78,16 @@ module.exports = function (mains, opts) {
         
         (function ap (trs) {
             if (trs.length === 0) return done();
-            var s = makeTransform(file, trs[0]);
-            s.on('error', output.emit.bind(output, 'error'));
-            
-            var data = '';
-            s.on('data', function (buf) { data += buf });
-            s.on('end', function () {
-                src = data;
-                ap(trs.slice(1));
+            makeTransform(file, trs[0], function (s) {
+                s.on('error', output.emit.bind(output, 'error'));
+                var data = '';
+                s.on('data', function (buf) { data += buf });
+                s.on('end', function () {
+                    src = data;
+                    ap(trs.slice(1));
+                });
+                s.end(src);
             });
-            s.end(src);
         })(transf);
         
         function done () {
@@ -124,10 +123,8 @@ module.exports = function (mains, opts) {
         }
     }
     
-    function makeTransform (file, tr) {
-        if (typeof tr === 'function') return tr(file);
-        var tout = through(), tin = through();
-        tin.pause();
+    function makeTransform (file, tr, cb) {
+        if (typeof tr === 'function') return cb(tr(file));
         
         var params = { basedir: path.dirname(file) };
         nodeResolve(tr, params, function (err, res) {
@@ -136,11 +133,7 @@ module.exports = function (mains, opts) {
                 'cannot find transform module ', tr,
                 ' while transforming ', file
             ].join(''));
-            var t = require(res)(file);
-            t.pipe(tout);
-            tin.pipe(t);
-            tin.resume();
+            cb(require(res)(file));
         });
-        return duplexer(tin, tout);
     }
 };
diff --git a/package.json b/package.json
index 16bf802..9b7c192 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "module-deps",
-    "version": "0.4.1",
+    "version": "0.4.2",
     "description": "walk the dependency graph to generate json output that can be fed into browser-pack",
     "main": "index.js",
     "bin": {
@@ -8,7 +8,6 @@
     },
     "dependencies": {
         "through": "~2.2.0",
-        "duplexer": "~0.0.3",
         "JSONStream": "~0.4.3",
         "browser-resolve": "~0.0.3",
         "resolve": "~0.3.0",

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