Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warn message on engine mismatch #257

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/install/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Object.keys(actions).forEach(function (actionName) {
if (pkg.knownInstallable) {
actionP = runAction(action, staging, pkg, log)
} else {
actionP = isInstallable(pkg.package).then(() => {
actionP = isInstallable(null, pkg.package).then(() => {
pkg.knownInstallable = true
return runAction(action, staging, pkg, log)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ function resolveWithNewModule (pkg, tree, log, next) {
validate('OOOF', arguments)

log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
return isInstallable(pkg, (err) => {
return isInstallable(tree, pkg, (err) => {
let installable = !err
addBundled(pkg, (bundleErr) => {
var parent = earliestInstallable(tree, tree, pkg, log) || tree
Expand Down
25 changes: 18 additions & 7 deletions lib/install/validate-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (idealTree, args, next) {
chain([
[hasMinimumFields, pkg],
[checkSelf, idealTree, pkg, force],
[isInstallable, pkg]
[isInstallable, idealTree, pkg]
], done)
}, next)
}
Expand All @@ -31,13 +31,24 @@ function hasMinimumFields (pkg, cb) {
}
}

function getWarnings (pkg) {
while (pkg.parent) pkg = pkg.parent
if (!pkg.warnings) pkg.warnings = []
return pkg.warnings
function setWarnings (idealTree, warn) {
function top (tree) {
if (tree.parent) return top(tree.parent)
return tree
}

var topTree = top(idealTree)
if (!topTree.warnings) topTree.warnings = []

if (topTree.warnings.every(i => (
i.code !== warn.code ||
i.required !== warn.required ||
i.pkgid !== warn.pkgid))) {
topTree.warnings.push(warn)
}
}

var isInstallable = module.exports.isInstallable = function (pkg, next) {
var isInstallable = module.exports.isInstallable = function (idealTree, pkg, next) {
var force = npm.config.get('force')
var nodeVersion = npm.config.get('node-version')
if (/-/.test(nodeVersion)) {
Expand All @@ -48,7 +59,7 @@ var isInstallable = module.exports.isInstallable = function (pkg, next) {
var strict = npm.config.get('engine-strict')
checkEngine(pkg, npm.version, nodeVersion, force, strict, iferr(next, thenWarnEngineIssues))
function thenWarnEngineIssues (warn) {
if (warn) getWarnings(pkg).push(warn)
if (idealTree && warn) setWarnings(idealTree, warn)
checkPlatform(pkg, force, next)
}
}
Expand Down
13 changes: 12 additions & 1 deletion test/tap/check-engine-reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ test('setup', function (t) {

var INSTALL_OPTS = ['--loglevel', 'silly']
var EXEC_OPTS = {cwd: installIn}

test('install bad engine', function (t) {
common.npm(['install', '--engine-strict', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
t.ifError(err, 'npm ran without issue')
Expand All @@ -43,6 +42,18 @@ test('force install bad engine', function (t) {
})
})

test('warns on bad engine not strict', function (t) {
common.npm(['install', '--json', installFrom], EXEC_OPTS, function (err, code, stdout, stderr) {
t.ifError(err, 'npm ran without issue')
t.is(code, 0, 'result code')
var result = JSON.parse(stdout)
t.match(result.warnings[0], /Unsupported engine/, 'reason for optional failure in JSON')
t.match(result.warnings[0], /1.0.0-not-a-real-version/, 'should print mismatch version info')
t.match(result.warnings[0], /Not compatible with your version of node/, 'incompatibility message')
t.done()
})
})

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