silently

tcmts.cli.merge.silently · #gn2j4ltq · term · runs on the server

uses process

Run fn with nothing it prints shown (a type error's report is written straight to stdout): what a merge tries on the side, a text merge that may not typecheck, it reports itself.

export function silently<T>(fn: () => T): T {
  const [log, error, warn] = [console.log, console.error, console.warn];
  const [out, err] = [process.stdout.write, process.stderr.write];
  console.log = console.error = console.warn = () => {};
  process.stdout.write = process.stderr.write = (() => true) as typeof process.stdout.write;
  try {
    return fn();
  } finally {
    [console.log, console.error, console.warn] = [log, error, warn];
    [process.stdout.write, process.stderr.write] = [out, err];
  }
}

used by