Skip to content

Commit 63005f4

Browse files
MylesBorinsruyadorno
authored andcommitted
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: #1639 PR-URL: #1791 Credit: @MylesBorins Close: #1791 Reviewed-by: @ruyadorno
1 parent c13806b commit 63005f4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ async function printData (data, name, opts) {
407407
// we may have partial lines printed.
408408
log.disableProgress()
409409

410-
// print directly to stdout to not unnecessarily add blank lines
411-
console.log(msg.trim())
410+
// only log if there is something to log
411+
if (msg !== '') console.log(msg.trim())
412412
}
413413

414414
function cleanup (data) {

test/lib/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ t.test('should log package info', t => {
332332

333333
t.test('package with --json and no versions', t => {
334334
viewJson(['brown'], () => {
335-
t.equals(logs, '\n', 'no info to display')
335+
t.equals(logs, '', 'no info to display')
336336
t.end()
337337
})
338338
})
@@ -446,7 +446,7 @@ t.test('should log info by field name', t => {
446446

447447
t.test('unknown nested field ', t => {
448448
view(['[email protected]', 'dist.foobar'], () => {
449-
t.equals(logs, '\n', 'no info to display')
449+
t.equals(logs, '', 'no info to display')
450450
t.end()
451451
})
452452
})

0 commit comments

Comments
 (0)