Skip to content

Commit

Permalink
fix: npm view should not output extra newline
Browse files Browse the repository at this point in the history
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: #1639

PR-URL: #1791
Credit: @MylesBorins
Close: #1791
Reviewed-by: @ruyadorno
  • Loading branch information
MylesBorins authored and ruyadorno committed Sep 16, 2020
1 parent c13806b commit 63005f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down Expand Up @@ -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()
})
})
Expand Down

0 comments on commit 63005f4

Please sign in to comment.