Skip to content

Commit

Permalink
install: log failed optional platform dependencies as info
Browse files Browse the repository at this point in the history
  • Loading branch information
cmedinasoriano committed Feb 24, 2019
1 parent 1e5fb28 commit c48fc7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 8 additions & 1 deletion lib/install/report-optional-failure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
var path = require('path')
var moduleName = require('../utils/module-name.js')
var logErrorMessage = require('../utils/log-error-message.js')

module.exports = reportOptionalFailure

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

error.optional = id
error.location = location
topTree.warnings.push(error)
if (error.code === 'EBADPLATFORM') {
// Optional dependencies irrelevant to the current OS probably aren't worth
// always warning users about, so indicate this issue at a lower log level.
logErrorMessage(error, 'info', 'verbose')
} else {
topTree.warnings.push(error)
}
}
22 changes: 13 additions & 9 deletions test/tap/full-warning-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ function exists (t, filepath, msg) {
t.pass(msg)
return true
} catch (ex) {
t.fail(msg, {found: null, wanted: 'exists', compare: 'fs.stat(' + filepath + ')'})
t.fail(msg, { found: null, wanted: 'exists', compare: 'fs.stat(' + filepath + ')' })
return false
}
}

function notExists (t, filepath, msg) {
try {
fs.statSync(filepath)
t.fail(msg, {found: 'exists', wanted: null, compare: 'fs.stat(' + filepath + ')'})
t.fail(msg, { found: 'exists', wanted: null, compare: 'fs.stat(' + filepath + ')' })
return true
} catch (ex) {
t.pass(msg)
Expand All @@ -87,25 +87,29 @@ function notExists (t, filepath, msg) {
}

test('tree-style', function (t) {
common.npm(['install', '--json', '--loglevel=warn'], {cwd: base}, function (err, code, stdout, stderr) {
common.npm(['install', '--json', '--loglevel=info'], { cwd: base }, function (err, code, stdout, stderr) {
if (err) throw err
t.is(code, 0, 'result code')
var result = JSON.parse(stdout)
t.is(result.added.length, 1, 'only added one module')
t.is(result.added[0].name, 'modA', 'modA got installed')
t.is(result.warnings.length, 1, 'one warning')
var stderrlines = stderr.trim().split(/\n/)
t.is(stderrlines.length, 2, 'two lines of warnings')
t.match(stderr, /SKIPPING OPTIONAL DEPENDENCY/, 'expected optional failure warning in stderr')
t.is(result.warnings.length, 0, 'no warnings')
t.match(stderr, /SKIPPING OPTIONAL DEPENDENCY/, 'expected optional failure info in stderr')
t.match(stderr, /Unsupported platform/, 'reason for optional failure in stderr')
t.match(result.warnings[0], /SKIPPING OPTIONAL DEPENDENCY/, 'expected optional failure warning in JSON')
t.match(result.warnings[0], /Unsupported platform/, 'reason for optional failure in JSON')
exists(t, modJoin(base, 'modA'), 'module A')
notExists(t, modJoin(base, 'modB'), 'module B')
t.done()
})
})

test('tree-style', function (t) {
common.npm(['install', '--loglevel=warn'], { cwd: base }, function (err, code, stdout, stderr) {
if (err) throw err
t.is(stderr.length, 0, 'EBADPLATFORM errors for optional deps are excluded from warnings')
t.done()
})
})

test('cleanup', function (t) {
cleanup()
t.end()
Expand Down

0 comments on commit c48fc7c

Please sign in to comment.