From 63005f4a98d55786fda46f3bbb3feab044d078df Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 10 Sep 2020 14:40:24 -0400 Subject: [PATCH] fix: npm view should not output extra newline Currently in npm 7 output of npm view is being printed by a call to console.log which is causing an extra newline on output compared to npm 6. Replace the call to console.log with process.stdout.write to avoid this. Fixes: https://github.com/npm/cli/issues/1639 PR-URL: https://github.com/npm/cli/pull/1791 Credit: @MylesBorins Close: #1791 Reviewed-by: @ruyadorno --- lib/view.js | 4 ++-- test/lib/view.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/view.js b/lib/view.js index 0e93fe81ae808..b8c22cd6a1274 100644 --- a/lib/view.js +++ b/lib/view.js @@ -407,8 +407,8 @@ async function printData (data, name, opts) { // we may have partial lines printed. log.disableProgress() - // print directly to stdout to not unnecessarily add blank lines - console.log(msg.trim()) + // only log if there is something to log + if (msg !== '') console.log(msg.trim()) } function cleanup (data) { diff --git a/test/lib/view.js b/test/lib/view.js index bd4876e14c417..9053d1a6473c2 100644 --- a/test/lib/view.js +++ b/test/lib/view.js @@ -332,7 +332,7 @@ t.test('should log package info', t => { t.test('package with --json and no versions', t => { viewJson(['brown'], () => { - t.equals(logs, '\n', 'no info to display') + t.equals(logs, '', 'no info to display') t.end() }) }) @@ -446,7 +446,7 @@ t.test('should log info by field name', t => { t.test('unknown nested field ', t => { view(['yellow@1.0.0', 'dist.foobar'], () => { - t.equals(logs, '\n', 'no info to display') + t.equals(logs, '', 'no info to display') t.end() }) })