From 49a151628caf335a9776c4579aac26c4042b2c5f Mon Sep 17 00:00:00 2001 From: guybedford Date: Wed, 3 Feb 2016 21:32:29 +0200 Subject: [PATCH] ensure optional dependencies parsing --- lib/npm.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/npm.js b/lib/npm.js index fa2f089..9a3a7fb 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -248,19 +248,23 @@ NPMLocation.prototype = { packageConfig.dependencies = parseDependencies(packageConfig.dependencies, this.ui); packageConfig.peerDependencies = parseDependencies(packageConfig.peerDependencies, this.ui); + packageConfig.optionalDependencies = parseDependencies(packageConfig.optionalDependencies, this.ui); - // by default we install optionalDependencies as peerDependencies - // when supported in jspm via https://github.com/jspm/jspm-cli/issues/1441, - // optionalDependencies will be optional peer dependencies - if (packageConfig.optionalDependencies) { + // ensure optionalDependencies take preference over peer and normal dependencies + if (packageConfig.optionalDependencies) Object.keys(packageConfig.optionalDependencies).forEach(function(dep) { - if (!packageConfig.peerDependencies[dep]) { + if (packageConfig.peerDependencies && packageConfig.peerDependencies[dep]) + delete packageConfig.peerDependencies[dep]; + if (packageConfig.dependencies && packageConfig.dependencies[dep]) + delete packageConfig.dependencies[dep]; + }); + + // ensure peerDependencies take preference over normal dependencies + if (packageConfig.peerDependencies) + Object.keys(packageConfig.peerDependencies).forEach(function(dep) { + if (packageConfig.dependencies[dep]) delete packageConfig.dependencies[dep]; - packageConfig.peerDependencies[dep] = packageConfig.optionalDependencies[dep]; - } }); - packageConfig.optionalDependencies = parseDependencies(packageConfig.optionalDependencies, this.ui); - } if (packageConfig.main instanceof Array) this.ui.log('warn', 'Package `' + packageName + '` has a main array, which is not supported.');