Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipeline.get('deps') emits invalid data #837

Closed
jescalan opened this issue Jul 25, 2014 · 5 comments
Closed

pipeline.get('deps') emits invalid data #837

jescalan opened this issue Jul 25, 2014 · 5 comments

Comments

@jescalan
Copy link

Reproduce:

var b = browserify(args);
b.pipeline.get('deps').pipe(process.stdout);

Truncated error message:

Uncaught TypeError: invalid data
    at WriteStream.Socket.write (net.js:614:11)
    at Labeled.ondata (/Users/jeff/Sites/roots-browserify/node_modules/browserify/node_modules/labeled-stream-splicer/node_modules/stream-splicer/node_modules/readable-stream/lib/_stream_readable.js:565:20)

Sorry if I'm screwing up the usage here, and would appreciate any corrections. I'm not a streams expert by any means, just used the docs as best I was able to. As a side note, when I listen for the data event on this stream it does emit the correct data, but the stream never emits an end event. I assume these two issues are related somehow.

@ghost
Copy link

ghost commented Jul 25, 2014

'deps' is an object stream so you will need to either consume the 'data' events or pipe into another stream like:

b.pipeline.get('deps').pipe(through.obj(function (row, enc, next) {
   console.log(row);
   this.push(row);
   next();
}));

You won't get an 'end' event if the stream isn't being consumed, which is how streams2 work.

@ghost ghost closed this as completed Jul 25, 2014
@jescalan
Copy link
Author

Ok, so there's no way for me to use this stream normally as an event emitter, I need to use through in order to consume it? For example, this doesn't work:

b.pipeline.get('deps')
  .on('data', console.log)
  .on('end', function(){ console.log('done!'); })

Is there a way to get functionality like this without installing additional external dependencies?

@ghost
Copy link

ghost commented Jul 25, 2014

You need to also consume the bundle by calling b.bundle() and piping it somewhere or calling .resume() on the bundle stream.

@jescalan
Copy link
Author

I'm sorry if I'm being thick here, but I don't entirely understand. Do you mean "no" is the answer to my last question, and in addition I need to call b.bundle().resume() in order for this to work? Is it "yes" but only if I make the bundle call?

Is there any chance if you have a moment that you could give a quick example? All I'm really after is a way to grab the dependencies of a project with the least amount of overhead possible. I know you are a busy man, and I really appreciate both your great work on browserify and any time you can spare to help out here 😀

@ghost
Copy link

ghost commented Jul 25, 2014

Like --list?

$ browserify --list main.js
/tmp/node_modules/gamma/index.js
/tmp/main.js

or the same thing in code:

var through = require('through2');
var b = require('browserify')(__dirname + '/main.js');
b.pipeline.get('deps').push(through.obj(function (row, enc, next) {
    console.log(row.file);
    this.push(row);
    next();
}));
b.bundle();

or you could listen on 'dep' events:

var through = require('through2');
var b = require('browserify')(__dirname + '/main.js');
b.on('dep', function (row) {
    console.log(row.file);
});
b.bundle();

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant