Skip to content

Conversation

Piterden
Copy link

No description provided.

}

BrowserStdout.prototype._write = function(chunks, encoding, cb) {
var output = chunks.toString ? chunks.toString() : chunks
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this check?

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont remember why its there, though its certainly possible to pass in a value that does not have a toString method. Fallback should likely be String(chunks)

@jimmywarting
Copy link

suggested change:

import { Writable } from 'node:stream'

export class BrowserStdout extends Writable {
  constructor (opts) {
    super(opts)
    const label = opts.label ?? 'stdout'
    this.log = label === false 
      ? console.log
      : console.log.bind(null, label + ':')
  }

  _write (chunks, encoding, cb) {
    this.log(chunks.toString ? chunks.toString() : chunks)
    cb()
  }
}

@johnsnelson
Copy link

suggested change to @jimmywarting's suggested change:

import { Writable } from 'node:stream'

export class BrowserStdout extends Writable {
  constructor (opts) {
    super(opts)
    const label = opts.label ?? 'stdout'
    this.log = label === false 
      ? console.log
     : console.log.bind(null, label + ': ') //added space after colon.

}

_write (chunks, encoding, cb) {
this.log(chunks.toString ? chunks.toString() : chunks)
cb()
}
}

Not having that space there would drive me crazy.

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

Successfully merging this pull request may close these issues.

4 participants