[Pkg-javascript-commits] [node-module-deps] 179/444: Support fs-like stream paths as id Streams returned by the fs core package, as well as vinyl-fs streams used by GulpJS, carry a 'path' property representing the path of the file behind the stream. When this exists, it should be used as an id instead of generating a fake id.

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:47:53 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 9f91270d1d9ea9215d29c03ca7c0fb861b03d57d
Author: ximus <maximeliron at gmail.com>
Date:   Mon Feb 10 12:09:19 2014 +0100

    Support fs-like stream paths as id Streams returned by the fs core package, as well as vinyl-fs streams used by GulpJS, carry a 'path' property representing the path of the file behind the stream. When this exists, it should be used as an id instead of generating a fake id.
---
 index.js       |  3 ++-
 test/stream.js | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index ee724a1..5aad7f5 100644
--- a/index.js
+++ b/index.js
@@ -18,7 +18,8 @@ module.exports = function (mains, opts) {
     var basedir = opts.basedir || process.cwd();
     
     var entries = mains.map(function (file) {
-        if (file && typeof file.pipe === 'function') {
+        if (file.path) return file.path;
+        if (typeof file.pipe === 'function') {
             var n = Math.floor(Math.pow(16,8) * Math.random()).toString(16);
             return path.join(basedir, 'fake_' + n + '.js');
         }
diff --git a/test/stream.js b/test/stream.js
index 81878c1..1cc6de1 100644
--- a/test/stream.js
+++ b/test/stream.js
@@ -22,3 +22,21 @@ test('read from a stream', function (t) {
     tr.queue('t.ok(true)');
     tr.queue(null);
 });
+
+test('infer path from fs-like streams', function (t) {
+    t.plan(2);
+    var path = 'foo-path'
+    var stream = through();
+
+    stream.path = path
+
+    var p = parser(stream);
+    p.on('error', t.fail.bind(t));
+    p.on('data', function(result) {
+        t.ok(!result.id.match(/fake/), "id should not be autogenerated")
+        t.equal(result.id, path, "id should be stream path property")
+    });
+
+    stream.queue('');
+    stream.queue(null);
+});
\ No newline at end of file

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