diff options
-rw-r--r-- | lib/install/deps.js | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/lib/install/deps.js b/lib/install/deps.js index cc6420ee0..c0fe905d4 100644 --- a/lib/install/deps.js +++ b/lib/install/deps.js @@ -301,23 +301,17 @@ exports.removeDeps = function (args, tree, saveToDependencies, next) { var pkgName = moduleName(pkg) var toRemove = tree.children.filter(moduleNameMatches(pkgName)) var pkgToRemove = toRemove[0] || createChild({package: {name: pkgName}}) + var saveType = getSaveType(tree, pkg) || 'dependencies' if (tree.isTop && saveToDependencies) { - pkgToRemove.save = getSaveType(tree, pkg) - let existing = false - if (tree.package[pkgToRemove.save][pkgName]) { - existing = true - delete tree.package[pkgToRemove.save][pkgName] - } - if (existing && pkgToRemove.save === 'optionalDependencies') { - if (tree.package.dependencies[pkgName]) { - existing = true - delete tree.package.dependencies[pkgName] - } - } - if (existing) { - replaceModuleByPath(tree, 'removedChildren', pkgToRemove) + pkgToRemove.save = saveType + } + if (tree.package[saveType][pkgName]) { + delete tree.package[saveType][pkgName] + if (saveType === 'optionalDependencies' && tree.package.dependencies[pkgName]) { + delete tree.package.dependencies[pkgName] } } + replaceModuleByPath(tree, 'removedChildren', pkgToRemove) for (let parent of pkgToRemove.requiredBy) { parent.requires = parent.requires.filter((child) => child !== pkgToRemove) } |