Skip to content

Commit

Permalink
Implements peerDependenciesMeta
Browse files Browse the repository at this point in the history
PR-URL: #224
Credit: @arcanis
Close: #224
Reviewed-by: @isaacs
  • Loading branch information
arcanis authored and isaacs committed Aug 12, 2019
1 parent e8fb2a1 commit a123410
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,12 @@ function resolveWithNewModule (pkg, tree, log, next) {
})
}

var isOptionalPeerDep = exports.isOptionalPeerDep = function (tree, pkgname) {
if (!tree.package.peerDependenciesMeta) return
if (!tree.package.peerDependenciesMeta[pkgname]) return
return !!tree.package.peerDependenciesMeta[pkgname].optional
}

var validatePeerDeps = exports.validatePeerDeps = function (tree, onInvalid) {
if (!tree.package.peerDependencies) return
Object.keys(tree.package.peerDependencies).forEach(function (pkgname) {
Expand All @@ -719,7 +725,7 @@ var validatePeerDeps = exports.validatePeerDeps = function (tree, onInvalid) {
var spec = npa.resolve(pkgname, version)
} catch (e) {}
var match = spec && findRequirement(tree.parent || tree, pkgname, spec)
if (!match) onInvalid(tree, pkgname, version)
if (!match && !isOptionalPeerDep(tree, pkgname)) onInvalid(tree, pkgname, version)
})
}

Expand Down

0 comments on commit a123410

Please sign in to comment.