Skip to content

Commit f3299ac

Browse files
ruyadornoisaacs
authored andcommitted
Reimplemented using idealTree param
PR-URL: #257 Credit: @ruyadorno Close: #257 Reviewed-by: @isaacs
1 parent 3547d99 commit f3299ac

File tree

6 files changed

+20
-67
lines changed

6 files changed

+20
-67
lines changed

lib/install/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Object.keys(actions).forEach(function (actionName) {
4949
if (pkg.knownInstallable) {
5050
actionP = runAction(action, staging, pkg, log)
5151
} else {
52-
actionP = isInstallable(pkg.package).then(() => {
52+
actionP = isInstallable(null, pkg.package).then(() => {
5353
pkg.knownInstallable = true
5454
return runAction(action, staging, pkg, log)
5555
})

lib/install/deps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ function resolveWithNewModule (pkg, tree, log, next) {
665665
validate('OOOF', arguments)
666666

667667
log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
668-
return isInstallable(pkg, (err) => {
668+
return isInstallable(tree, pkg, (err) => {
669669
let installable = !err
670670
addBundled(pkg, (bundleErr) => {
671671
var parent = earliestInstallable(tree, tree, pkg, log) || tree

lib/install/validate-args.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (idealTree, args, next) {
1616
chain([
1717
[hasMinimumFields, pkg],
1818
[checkSelf, idealTree, pkg, force],
19-
[isInstallable, pkg]
19+
[isInstallable, idealTree, pkg]
2020
], done)
2121
}, next)
2222
}
@@ -31,17 +31,24 @@ function hasMinimumFields (pkg, cb) {
3131
}
3232
}
3333

34-
function setWarnings (pkg, warn) {
35-
if (!pkg.warnings) pkg.warnings = []
36-
if (pkg.warnings.every(i => (
34+
function setWarnings (idealTree, warn) {
35+
function top (tree) {
36+
if (tree.parent) return top(tree.parent)
37+
return tree
38+
}
39+
40+
var topTree = top(idealTree)
41+
if (!topTree.warnings) topTree.warnings = []
42+
43+
if (topTree.warnings.every(i => (
3744
i.code !== warn.code ||
3845
i.required !== warn.required ||
3946
i.pkgid !== warn.pkgid))) {
40-
pkg.warnings.push(warn)
47+
topTree.warnings.push(warn)
4148
}
4249
}
4350

44-
var isInstallable = module.exports.isInstallable = function (pkg, next) {
51+
var isInstallable = module.exports.isInstallable = function (idealTree, pkg, next) {
4552
var force = npm.config.get('force')
4653
var nodeVersion = npm.config.get('node-version')
4754
if (/-/.test(nodeVersion)) {
@@ -52,7 +59,7 @@ var isInstallable = module.exports.isInstallable = function (pkg, next) {
5259
var strict = npm.config.get('engine-strict')
5360
checkEngine(pkg, npm.version, nodeVersion, force, strict, iferr(next, thenWarnEngineIssues))
5461
function thenWarnEngineIssues (warn) {
55-
if (warn) setWarnings(pkg, warn)
62+
if (idealTree && warn) setWarnings(idealTree, warn)
5663
checkPlatform(pkg, force, next)
5764
}
5865
}

lib/install/validate-tree.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ module.exports = function (idealTree, log, next) {
2222
[asyncMap, modules, function (mod, done) {
2323
chain([
2424
mod.parent && !mod.isLink && [checkGit, mod.realpath],
25-
[checkErrors, mod, idealTree],
26-
[checkWarnings, mod, idealTree]
25+
[checkErrors, mod, idealTree]
2726
], done)
2827
}],
2928
[thenValidateAllPeerDeps, idealTree],
@@ -37,15 +36,6 @@ function checkErrors (mod, idealTree, next) {
3736
next()
3837
}
3938

40-
function checkWarnings (mod, idealTree, next) {
41-
const warnings = mod.package.warnings
42-
if (warnings && (mod.parent || path.resolve(npm.globalDir, '..') !== mod.path)) {
43-
warnings.forEach(warn => idealTree.warnings.push(warn))
44-
delete mod.package.warnings
45-
}
46-
next()
47-
}
48-
4939
function thenValidateAllPeerDeps (idealTree, next) {
5040
validate('OF', arguments)
5141
validateAllPeerDeps(idealTree, function (tree, pkgname, version) {

test/tap/check-engine-reqs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ test('warns on bad engine not strict', function (t) {
4747
t.ifError(err, 'npm ran without issue')
4848
t.is(code, 0, 'result code')
4949
var result = JSON.parse(stdout)
50-
t.match(result.warnings[1], /Unsupported engine/, 'reason for optional failure in JSON')
51-
t.match(result.warnings[1], /1.0.0-not-a-real-version/, 'should print mismatch version info')
52-
t.match(result.warnings[1], /Not compatible with your version of node/, 'incompatibility message')
50+
t.match(result.warnings[0], /Unsupported engine/, 'reason for optional failure in JSON')
51+
t.match(result.warnings[0], /1.0.0-not-a-real-version/, 'should print mismatch version info')
52+
t.match(result.warnings[0], /Not compatible with your version of node/, 'incompatibility message')
5353
t.done()
5454
})
5555
})

test/tap/validate-tree-check-warnings.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)