diff options
author | Rebecca Turner <me@re-becca.org> | 2017-05-25 14:00:43 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-05-26 04:55:31 +0300 |
commit | 5599538eff233f7cbf128d70bbe34997bf7e7dd3 (patch) | |
tree | f80d51c70ab1de492ad6e5d92c518f19a8374110 /lib | |
parent | 3116cfecdaaf3b76abe44ae1e3e08cce8bf8cfe1 (diff) |
install,uninstall: Disable fake children when installing one mod or uninstalling
Diffstat (limited to 'lib')
-rw-r--r-- | lib/install.js | 13 | ||||
-rw-r--r-- | lib/install/inflate-shrinkwrap.js | 21 | ||||
-rw-r--r-- | lib/install/read-shrinkwrap.js | 8 | ||||
-rw-r--r-- | lib/prune.js | 1 | ||||
-rw-r--r-- | lib/uninstall.js | 2 |
5 files changed, 31 insertions, 14 deletions
diff --git a/lib/install.js b/lib/install.js index 3a1dc5b98..d3a913245 100644 --- a/lib/install.js +++ b/lib/install.js @@ -204,6 +204,11 @@ function Installer (where, dryrun, args) { this.where = where this.dryrun = dryrun this.args = args + // fakechildren are children created from the lockfile and lack relationship data + // the only exist when the tree does not match the lockfile + // this is fine when doing full tree installs/updates but not ok when modifying only + // a few deps via `npm install` or `npm uninstall`. + this.fakeChildren = true this.currentTree = null this.idealTree = null this.differences = [] @@ -317,9 +322,9 @@ Installer.prototype.run = function (_cb) { } Installer.prototype.loadArgMetadata = function (next) { - var self = this - getAllMetadata(this.args, this.currentTree, process.cwd(), iferr(next, function (args) { - self.args = args + getAllMetadata(this.args, this.currentTree, process.cwd(), iferr(next, (args) => { + this.args = args + if (args.length) this.fakeChildren = false next() })) } @@ -669,7 +674,7 @@ function isLink (child) { Installer.prototype.loadShrinkwrap = function (cb) { validate('F', arguments) log.silly('install', 'loadShrinkwrap') - readShrinkwrap.andInflate(this.idealTree, cb) + readShrinkwrap.andInflate(this.idealTree, {fakeChildren: this.fakeChildren}, cb) } Installer.prototype.getInstalledModules = function () { diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js index 8514f00dd..596885613 100644 --- a/lib/install/inflate-shrinkwrap.js +++ b/lib/install/inflate-shrinkwrap.js @@ -14,17 +14,22 @@ const realizeShrinkwrapSpecifier = require('./realize-shrinkwrap-specifier.js') const validate = require('aproba') const path = require('path') -module.exports = function (tree, swdeps, finishInflating) { +module.exports = function (tree, swdeps, opts, finishInflating) { if (!npm.config.get('shrinkwrap')) return finishInflating() + if (arguments.length === 3) { + finishInflating = opts + opts = {} + } tree.loaded = true - return inflateShrinkwrap(tree.path, tree, swdeps).then( + return inflateShrinkwrap(tree.path, tree, swdeps, opts).then( () => finishInflating(), finishInflating ) } -function inflateShrinkwrap (topPath, tree, swdeps) { - validate('SOO', arguments) +function inflateShrinkwrap (topPath, tree, swdeps, opts) { + validate('SOO|SOOO', arguments) + if (!opts) opts = {} const onDisk = {} tree.children.forEach((child) => { onDisk[moduleName(child)] = child @@ -43,7 +48,7 @@ function inflateShrinkwrap (topPath, tree, swdeps) { const dependencies = sw.dependencies || {} const requested = realizeShrinkwrapSpecifier(name, sw, topPath) return inflatableChild( - onDisk[name], name, topPath, tree, sw, requested + onDisk[name], name, topPath, tree, sw, requested, opts ).then((child) => { return inflateShrinkwrap(topPath, child, dependencies) }) @@ -58,8 +63,8 @@ function normalizePackageDataNoErrors (pkg) { } } -function inflatableChild (onDiskChild, name, topPath, tree, sw, requested) { - validate('OSSOOO|ZSSOOO', arguments) +function inflatableChild (onDiskChild, name, topPath, tree, sw, requested, opts) { + validate('OSSOOOO|ZSSOOOO', arguments) if (onDiskChild && childIsEquivalent(sw, requested, onDiskChild)) { // The version on disk matches the shrinkwrap entry. if (!onDiskChild.fromShrinkwrap) onDiskChild.fromShrinkwrap = true @@ -77,7 +82,7 @@ function inflatableChild (onDiskChild, name, topPath, tree, sw, requested) { normalizePackageDataNoErrors(onDiskChild.package) tree.children.push(onDiskChild) return BB.resolve(onDiskChild) - } else if (sw.version && sw.integrity) { + } else if (opts.fakeChildren !== false && sw.version && sw.integrity) { // The shrinkwrap entry has an integrity field. We can fake a pkg to get // the installer to do a content-address fetch from the cache, if possible. return BB.resolve(makeFakeChild(name, topPath, tree, sw, requested)) diff --git a/lib/install/read-shrinkwrap.js b/lib/install/read-shrinkwrap.js index 913c30348..56d8ce11e 100644 --- a/lib/install/read-shrinkwrap.js +++ b/lib/install/read-shrinkwrap.js @@ -56,10 +56,14 @@ function maybeReadFile (name, child) { ).catch({code: 'ENOENT'}, () => null) } -module.exports.andInflate = function (child, next) { +module.exports.andInflate = function (child, opts, next) { + if (arguments.length === 2) { + next = opts + opts = {} + } readShrinkwrap(child, iferr(next, function () { if (child.package._shrinkwrap) { - return inflateShrinkwrap(child, child.package._shrinkwrap.dependencies || {}, next) + return inflateShrinkwrap(child, child.package._shrinkwrap.dependencies || {}, opts, next) } else { return next() } diff --git a/lib/prune.js b/lib/prune.js index 9ca17ae29..602774538 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.fakeChildren = false } util.inherits(Pruner, Installer) diff --git a/lib/uninstall.js b/lib/uninstall.js index 473b47acc..1aca04aa0 100644 --- a/lib/uninstall.js +++ b/lib/uninstall.js @@ -11,6 +11,7 @@ const npm = require('./npm.js') const Installer = require('./install.js').Installer const getSaveType = require('./install/save.js').getSaveType const removeDeps = require('./install/deps.js').removeDeps +var readShrinkwrap = require('./install/read-shrinkwrap.js') const log = require('npmlog') const usage = require('./utils/usage') @@ -52,6 +53,7 @@ class Uninstaller extends Installer { constructor (where, dryrun, args) { super(where, dryrun, args) this.remove = [] + this.fakeChildren = false } loadArgMetadata (next) { |