-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
gyp: send spawned output to logger #1984
base: main
Are you sure you want to change the base?
Conversation
can we see a screenshot of what this looks line in action? |
if (!opts.silent && !opts.stdio) { | ||
opts.stdio = [0, 1, 2] | ||
cp.stdout.pipe(split()).on('data', function (line) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably OK but it's nice to make a habit of avoiding using 'data'
events so you can set up proper backpressure (not really a requirement here because npmlog doesn't give us a mechanism for it), usually done by implementing a custom stream.
maybe something like this
const { Transform } = require('stream')
...
function outLogger (prefix, log) {
return new Transform({
transform: (chunk, enc, callback) {
log(prefix, chunk.toString())
callback()
}
})
}
cp.stdout.pipe(split()).pipe(outLogger('spawn stdout', log.notice)) // does it need to be `log.notice.bind(log)`?
cp.stderr.pipe(split()).pipe(outLogger('spawn stderr', log.error))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I was wondering why you were suggesting this route in the original issue. I hadn't heard of a reason to not just use the data
event. I didn't see an advantage to using a Transform stream but makes sense.
To be clear, this is the data
event from split()
and not from stdout
/stderr
.
I wonder if there are any possible improvements from using a Writable
stream instead of a Transform
since there is no data coming out of the logger (as far as the stream api is concerned).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem that I see with this is that the subprocess loses the "TTY-ness" which many programs use to determine whether or not to out put output colors to the terminal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TooTallNate This seems like a reason to add an "opt-in" option.
Labeleling this semver-major for now, we can discuss if anyone disagrees or if this evolves in a different direction. For now I'm leaning on the assumption that there are use-cases in existence that parse output to look for certain things and that by changing the loglevel at which they show up might break that. |
If I understand the code correctly the current code doesn't log the output from spawned processes at any loglevel (which is probably why errors from |
@rvagg Has Alternatively, instead of prefixing spawned outputs with An extra option could be added to opt into this capturing of spawned output making it completely non-api changing. @richardlau The current code just passes the spawned IO to This just made me think of one other breaking change in what I'm currently proposing: |
@cinderblock there are not written guarantees but output tends to be treated as an API and with the massive deployment base of node-gyp we need to be a bit sensitive to such things because they break in surprising ways. We've learnt this the hard way with Node.js itself. Maybe the best way to deal with this, and the comment about stdout losing its TTY status is to add this as an opt-in and then we could consider making it opt-out in the future, more gentle and a good way to experiment. Opt-in via environment variable might be a good start, and that can be inherited from npm too so an |
I understand the implications of many people using such a big package. That's why it needs to be opt-in. I'll take a stab at improving the PR to make it opt in. The opt-in option name should probably include verbiage to indicate the stricter operating environment (no |
|
Checklist
npm install && npm test
passesDescription of change
As discussed in #532, might be nice to allow capturing of spawned output. This is my first stab at an implementation. Seems to work so far as I've tested.