Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit 6c248ff

Browse files
committed
install: Report normalization errors of the top level package
PR-URL: #8779
1 parent 391e29d commit 6c248ff

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/install/validate-tree.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var checkPlatform = npmInstallChecks.checkPlatform
77
var checkGit = npmInstallChecks.checkGit
88
var asyncMap = require('slide').asyncMap
99
var chain = require('slide').chain
10+
var clone = require('lodash.clonedeep')
11+
var normalizePackageData = require('normalize-package-data')
1012
var npm = require('../npm.js')
1113
var andFinishTracker = require('./and-finish-tracker.js')
1214
var flattenTree = require('./flatten-tree.js')
@@ -28,7 +30,7 @@ module.exports = function (idealTree, log, next) {
2830
mod.parent && !isInLink(mod) && [checkGit, mod.realpath],
2931
[checkErrors, mod, idealTree]
3032
], done)
31-
}, andValidateAllPeerDeps(idealTree, andFinishTracker(log, next)))
33+
}, andValidateAllPeerDeps(idealTree, andCheckTop(idealTree, andFinishTracker(log, next))))
3234
}
3335

3436
function isInLink (mod) {
@@ -54,3 +56,24 @@ function andValidateAllPeerDeps (idealTree, next) {
5456
next(er)
5557
}
5658
}
59+
60+
function andCheckTop (idealTree, next) {
61+
validate('OF', arguments)
62+
if (idealTree.package.error) {
63+
return next
64+
} else {
65+
return function (er) {
66+
// FIXME: when we replace read-package-json with something less magic,
67+
// this should done elsewhere.
68+
// As it is, the package has already been normalized and thus some
69+
// errors are suppressed.
70+
var pkg = clone(idealTree.package)
71+
normalizePackageData(pkg, function (warn) {
72+
var warnObj = new Error(pkg._id + ' ' + warn)
73+
warnObj.code = 'EPACKAGEJSON'
74+
idealTree.warnings.push(warnObj)
75+
}, false)
76+
next(er)
77+
}
78+
}
79+
}

test/tap/peer-deps-invalid.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ test('installing dependencies that have conflicting peerDependencies', function
7979
function () {
8080
npm.commands.install([], function (err, additions, tree) {
8181
t.error(err)
82-
t.is(tree.warnings.length, 2)
83-
t.is(tree.warnings[0].code, 'EPEERINVALID')
84-
t.is(tree.warnings[1].code, 'EPEERINVALID')
82+
var invalid = tree.warnings.filter(function (warning) { return warning.code === 'EPEERINVALID' })
83+
t.is(invalid.length, 2)
8584
s.close()
8685
t.end()
8786
})

0 commit comments

Comments
 (0)