sindresorhus / hook-std

Hook and modify stdout and stderr
MIT License
54 stars 12 forks source link

Does not write modified values to stdout/stderr in 1.0.0 #16

Closed pvdlg closed 6 years ago

pvdlg commented 6 years ago

In version 0.4.0:

const hookStd = require('hook-std');

const unhook = hookStd({silent: false}, () => {
  return 'modified value';
});
console.log('Test');
unhook();
console.log('Done');

writes modified value then Done to the console.

However in version 1.0.0:

const hookStd = require('hook-std');

const promise = hookStd({silent: false}, () => {
  return 'modified value';
});
console.log('Test');
promise.unhook();
promise.then(() => {
  console.log('Done');
});

writes only Done to the console.

It seems the silent option is ignored.

sindresorhus commented 6 years ago

// @acostalima

acostalima commented 6 years ago

Thanks for submitting the bug report.

After some testing, I found out the issued lied in the underlying call to process.stdout.write made by console.log, which, apparently, is made by supplying a function to the encoding argument instead of a string. I'll open a PR to fix the problem shortly.