Skip to content

Commit a2a4017

Browse files
author
Christian Medina
committed
install: log failed optional platform dependencies as info
1 parent 1e5fb28 commit a2a4017

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/install/report-optional-failure.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22
var path = require('path')
33
var moduleName = require('../utils/module-name.js')
4+
var logErrorMessage = require('../utils/log-error-message.js')
45

56
module.exports = reportOptionalFailure
67

@@ -27,5 +28,11 @@ function reportOptionalFailure (tree, what, error) {
2728

2829
error.optional = id
2930
error.location = location
30-
topTree.warnings.push(error)
31+
if (error.code === 'EBADPLATFORM') {
32+
// Optional dependencies irrelevant to the current OS probably aren't worth
33+
// always warning users about, so indicate this issue at a lower log level.
34+
logErrorMessage(error, 'info', 'verbose')
35+
} else {
36+
topTree.warnings.push(error)
37+
}
3138
}

test/tap/full-warning-messages.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ function exists (t, filepath, msg) {
7070
t.pass(msg)
7171
return true
7272
} catch (ex) {
73-
t.fail(msg, {found: null, wanted: 'exists', compare: 'fs.stat(' + filepath + ')'})
73+
t.fail(msg, { found: null, wanted: 'exists', compare: 'fs.stat(' + filepath + ')' })
7474
return false
7575
}
7676
}
7777

7878
function notExists (t, filepath, msg) {
7979
try {
8080
fs.statSync(filepath)
81-
t.fail(msg, {found: 'exists', wanted: null, compare: 'fs.stat(' + filepath + ')'})
81+
t.fail(msg, { found: 'exists', wanted: null, compare: 'fs.stat(' + filepath + ')' })
8282
return true
8383
} catch (ex) {
8484
t.pass(msg)
@@ -87,16 +87,14 @@ function notExists (t, filepath, msg) {
8787
}
8888

8989
test('tree-style', function (t) {
90-
common.npm(['install', '--json', '--loglevel=warn'], {cwd: base}, function (err, code, stdout, stderr) {
90+
common.npm(['install', '--json', '--loglevel=info'], { cwd: base }, function (err, code, stdout, stderr) {
9191
if (err) throw err
9292
t.is(code, 0, 'result code')
9393
var result = JSON.parse(stdout)
9494
t.is(result.added.length, 1, 'only added one module')
9595
t.is(result.added[0].name, 'modA', 'modA got installed')
96-
t.is(result.warnings.length, 1, 'one warning')
97-
var stderrlines = stderr.trim().split(/\n/)
98-
t.is(stderrlines.length, 2, 'two lines of warnings')
99-
t.match(stderr, /SKIPPING OPTIONAL DEPENDENCY/, 'expected optional failure warning in stderr')
96+
t.is(result.warnings.length, 0, 'no warnings')
97+
t.match(stderr, /SKIPPING OPTIONAL DEPENDENCY/, 'expected optional failure info in stderr')
10098
t.match(stderr, /Unsupported platform/, 'reason for optional failure in stderr')
10199
t.match(result.warnings[0], /SKIPPING OPTIONAL DEPENDENCY/, 'expected optional failure warning in JSON')
102100
t.match(result.warnings[0], /Unsupported platform/, 'reason for optional failure in JSON')
@@ -106,6 +104,14 @@ test('tree-style', function (t) {
106104
})
107105
})
108106

107+
test('tree-style', function (t) {
108+
common.npm(['install', '--loglevel=warn'], { cwd: base }, function (err, code, stdout, stderr) {
109+
if (err) throw err
110+
t.is(stderr.length, 0, 'EBADPLATFORM errors for optional deps are excluded from warnings')
111+
t.done()
112+
})
113+
})
114+
109115
test('cleanup', function (t) {
110116
cleanup()
111117
t.end()

0 commit comments

Comments
 (0)