diff options
author | Rebecca Turner <me@re-becca.org> | 2017-12-19 12:31:40 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2018-02-02 02:42:56 +0300 |
commit | 3b305ee71e2bf852ff3037366a1774b8c5fcc0a5 (patch) | |
tree | d6a8f80750b6f038952e2847974de10d3be2551e /lib | |
parent | 8c73405c5b7ca69f4025861a968e75e4078115c4 (diff) |
install: Only autoprune on install with lock file
Diffstat (limited to 'lib')
-rw-r--r-- | lib/install.js | 6 | ||||
-rw-r--r-- | lib/install/deps.js | 12 | ||||
-rw-r--r-- | lib/prune.js | 1 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/install.js b/lib/install.js index 42906f239..0cf2facea 100644 --- a/lib/install.js +++ b/lib/install.js @@ -220,6 +220,8 @@ function Installer (where, dryrun, args, opts) { this.noPackageJsonOk = !!args.length this.topLevelLifecycles = !args.length + this.autoPrune = npm.config.get('package-lock') + const dev = npm.config.get('dev') const only = npm.config.get('only') const onlyProd = /^prod(uction)?$/.test(only) @@ -436,8 +438,8 @@ Installer.prototype.pruneIdealTree = function (cb) { // if our lock file didn't have the requires field and there // are any fake children then forgo pruning until we have more info. if (!this.idealTree.hasRequiresFromLock && this.idealTree.children.some((n) => n.fakeChild)) return cb() - var toPrune = this.idealTree.children - .filter(isExtraneous) + const toPrune = this.idealTree.children + .filter((child) => isExtraneous(child) && (this.autoPrune || child.removing)) .map((n) => ({name: moduleName(n)})) return removeExtraneous(toPrune, this.idealTree, cb) } diff --git a/lib/install/deps.js b/lib/install/deps.js index 93c4adffd..113f0b92f 100644 --- a/lib/install/deps.js +++ b/lib/install/deps.js @@ -332,9 +332,21 @@ exports.removeDeps = function (args, tree, saveToDependencies, next) { parent.requires = parent.requires.filter((child) => child !== pkgToRemove) } pkgToRemove.requiredBy = pkgToRemove.requiredBy.filter((parent) => parent !== tree) + flagAsRemoving(pkgToRemove) } next() } + +function flagAsRemoving (toRemove, seen) { + if (!seen) seen = new Set() + if (seen.has(toRemove)) return + seen.add(toRemove) + toRemove.removing = true + toRemove.requires.forEach((required) => { + flagAsRemoving(required, seen) + }) +} + exports.removeExtraneous = function (args, tree, next) { for (let pkg of args) { var pkgName = moduleName(pkg) diff --git a/lib/prune.js b/lib/prune.js index 4ac813957..8d642e5b2 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -26,6 +26,7 @@ function prune (args, cb) { function Pruner (where, dryrun, args) { Installer.call(this, where, dryrun, args) + this.autoPrune = true } util.inherits(Pruner, Installer) |