[Pkg-javascript-commits] [node-module-deps] 321/444: accept transforms in the input stream

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:48:09 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 c4a3cebfe9ebf28b97ac2d5431a5e38a52c91fff
Author: James Halliday <mail at substack.net>
Date:   Wed Dec 3 00:26:46 2014 -0800

    accept transforms in the input stream
---
 index.js | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/index.js b/index.js
index 9dbc7dd..68fd74e 100644
--- a/index.js
+++ b/index.js
@@ -33,6 +33,7 @@ function Deps (opts) {
     this.visited = {};
     this.walking = {};
     this.entries = [];
+    this._input = [];
     
     this.paths = opts.paths || process.env.NODE_PATH;
     if (typeof this.paths === 'string') {
@@ -53,10 +54,19 @@ function Deps (opts) {
 
 Deps.prototype._transform = function (row, enc, next) {
     var self = this;
-    self.pending ++;
     if (typeof row === 'string') {
         row = { file: row };
     }
+    if (row.transform && row.global) {
+        this.globalTransforms.push([ row.transform, row.options ]);
+        return next();
+    }
+    else if (row.transform) {
+        this.transforms.push([ row.transform, row.options ]);
+        return next();
+    }
+    
+    self.pending ++;
     if (row.entry !== false) self.entries.push(row.file);
     
     self.lookupPackage(row.file, function (err, pkg) {
@@ -67,18 +77,18 @@ Deps.prototype._transform = function (row, enc, next) {
         }
         if (err) return self.emit('error', err)
         self.pending --;
-        start(pkg)
+        self._input.push({ row: row, pkg: pkg });
+        next();
     });
-    next();
-    
-    function start (pkg) {
-        if (!pkg) pkg = {};
-        if (!pkg.__dirname) pkg.__dirname = path.dirname(row.file);
-        self.walk(row, self.top);
-    }
 };
 
 Deps.prototype._flush = function () {
+    var self = this;
+    self._input.forEach(function (r) {
+        var pkg = r.pkg || {};
+        if (!pkg.__dirname) pkg.__dirname = path.dirname(r.row.file);
+        self.walk(r.row, self.top);
+    });
     if (this.pending === 0) this.push(null);
     this._ended = true;
 };
@@ -346,7 +356,7 @@ Deps.prototype.walk = function (id, parent, cb) {
             self.push(rec);
             
             if (cb) cb(null, file);
-            if (-- self.pending === 0 && self._ended) self.push(null);
+            if (-- self.pending === 0) self.push(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