Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
ensure optional dependencies parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Feb 3, 2016
1 parent 1d9e6ce commit 49a1516
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down

0 comments on commit 49a1516

Please sign in to comment.