Skip to content

Commit

Permalink
Reimplemented using idealTree param
Browse files Browse the repository at this point in the history
PR-URL: #257
Credit: @ruyadorno
Close: #257
Reviewed-by: @isaacs
  • Loading branch information
ruyadorno authored and isaacs committed Oct 7, 2019
1 parent 3547d99 commit f3299ac
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 67 deletions.
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
21 changes: 14 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,17 +31,24 @@ function hasMinimumFields (pkg, cb) {
}
}

function setWarnings (pkg, warn) {
if (!pkg.warnings) pkg.warnings = []
if (pkg.warnings.every(i => (
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))) {
pkg.warnings.push(warn)
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 @@ -52,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) setWarnings(pkg, warn)
if (idealTree && warn) setWarnings(idealTree, warn)
checkPlatform(pkg, force, next)
}
}
Expand Down
12 changes: 1 addition & 11 deletions lib/install/validate-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ module.exports = function (idealTree, log, next) {
[asyncMap, modules, function (mod, done) {
chain([
mod.parent && !mod.isLink && [checkGit, mod.realpath],
[checkErrors, mod, idealTree],
[checkWarnings, mod, idealTree]
[checkErrors, mod, idealTree]
], done)
}],
[thenValidateAllPeerDeps, idealTree],
Expand All @@ -37,15 +36,6 @@ function checkErrors (mod, idealTree, next) {
next()
}

function checkWarnings (mod, idealTree, next) {
const warnings = mod.package.warnings
if (warnings && (mod.parent || path.resolve(npm.globalDir, '..') !== mod.path)) {
warnings.forEach(warn => idealTree.warnings.push(warn))
delete mod.package.warnings
}
next()
}

function thenValidateAllPeerDeps (idealTree, next) {
validate('OF', arguments)
validateAllPeerDeps(idealTree, function (tree, pkgname, version) {
Expand Down
6 changes: 3 additions & 3 deletions test/tap/check-engine-reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ test('warns on bad engine not strict', function (t) {
t.ifError(err, 'npm ran without issue')
t.is(code, 0, 'result code')
var result = JSON.parse(stdout)
t.match(result.warnings[1], /Unsupported engine/, 'reason for optional failure in JSON')
t.match(result.warnings[1], /1.0.0-not-a-real-version/, 'should print mismatch version info')
t.match(result.warnings[1], /Not compatible with your version of node/, 'incompatibility message')
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()
})
})
Expand Down
44 changes: 0 additions & 44 deletions test/tap/validate-tree-check-warnings.js

This file was deleted.

0 comments on commit f3299ac

Please sign in to comment.