diff options
author | Rebecca Turner <me@re-becca.org> | 2017-06-29 10:12:06 +0300 |
---|---|---|
committer | Kat Marchán <kzm@sykosomatic.org> | 2017-07-06 00:58:48 +0300 |
commit | 33827c74767da256453ed8683ebfae580b737d88 (patch) | |
tree | dff8ce04b916900d9abd9f1f79ee63d4a5c27190 | |
parent | 8dd3337df6907a516bf3988642a0be32429a40a2 (diff) |
install: Insist on full tree when mutating with a package.lock
That is, if you have a package-lock but haven't installed anything yet then
we're going to insist that all of the bits be there. This is necessary in order
to be able to cleanly upgrade old package-lock files. This means if you type
`npm install foo` or `npm rm foo` and don't have a `node_modules` but do have
a `package-lock.json` it's gonna install everything from the
`package-lock.json` in addition to making your change.
The one thing we won't do is update your package-lock from your
package.json. We only do that when you request a full install.
This does not change the behavior if you don't have a lock file.
PR-URL: https://github.com/npm/npm/pull/17508
Credit: @iarna
Reviewed-By: @zkat
-rw-r--r-- | lib/install.js | 12 | ||||
-rw-r--r-- | lib/install/inflate-shrinkwrap.js | 2 | ||||
-rw-r--r-- | lib/install/read-shrinkwrap.js | 8 | ||||
-rw-r--r-- | lib/ls.js | 2 | ||||
-rw-r--r-- | lib/prune.js | 1 | ||||
-rw-r--r-- | lib/uninstall.js | 1 |
6 files changed, 9 insertions, 17 deletions
diff --git a/lib/install.js b/lib/install.js index c6e67e979..71ccde4ad 100644 --- a/lib/install.js +++ b/lib/install.js @@ -208,7 +208,6 @@ function Installer (where, dryrun, args) { // 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 = [] @@ -325,7 +324,6 @@ Installer.prototype.run = function (_cb) { Installer.prototype.loadArgMetadata = function (next) { getAllMetadata(this.args, this.currentTree, process.cwd(), iferr(next, (args) => { this.args = args - if (args.length) this.fakeChildren = false next() })) } @@ -422,14 +420,14 @@ Installer.prototype.loadAllDepsIntoIdealTree = function (cb) { var installNewModules = !!this.args.length var steps = [] - const depsToPreload = Object.assign({}, - this.dev ? this.idealTree.package.devDependencies : {}, - this.prod ? this.idealTree.package.dependencies : {} - ) if (installNewModules) { steps.push([validateArgs, this.idealTree, this.args]) steps.push([loadRequestedDeps, this.args, this.idealTree, saveDeps, cg.newGroup('loadRequestedDeps')]) } else { + const depsToPreload = Object.assign({}, + this.dev ? this.idealTree.package.devDependencies : {}, + this.prod ? this.idealTree.package.dependencies : {} + ) if (this.prod || this.dev) { steps.push( [prefetchDeps, this.idealTree, depsToPreload, cg.newGroup('prefetchDeps')]) @@ -680,7 +678,7 @@ function isLink (child) { Installer.prototype.loadShrinkwrap = function (cb) { validate('F', arguments) log.silly('install', 'loadShrinkwrap') - readShrinkwrap.andInflate(this.idealTree, {fakeChildren: this.fakeChildren}, cb) + readShrinkwrap.andInflate(this.idealTree, cb) } Installer.prototype.getInstalledModules = function () { diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js index fcd58d0fb..0f22d5223 100644 --- a/lib/install/inflate-shrinkwrap.js +++ b/lib/install/inflate-shrinkwrap.js @@ -88,7 +88,7 @@ function inflatableChild (onDiskChild, name, topPath, tree, sw, requested, opts) onDiskChild.swRequires = sw.requires tree.children.push(onDiskChild) return BB.resolve(onDiskChild) - } else if (opts.fakeChildren !== false && sw.version && sw.integrity) { + } else if (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 de398fb40..cb5a578a9 100644 --- a/lib/install/read-shrinkwrap.js +++ b/lib/install/read-shrinkwrap.js @@ -47,14 +47,10 @@ function maybeReadFile (name, child) { ).catch({code: 'ENOENT'}, () => null) } -module.exports.andInflate = function (child, opts, next) { - if (arguments.length === 2) { - next = opts - opts = {} - } +module.exports.andInflate = function (child, next) { readShrinkwrap(child, iferr(next, function () { if (child.package._shrinkwrap) { - return inflateShrinkwrap(child, child.package._shrinkwrap.dependencies || {}, opts, next) + return inflateShrinkwrap(child, child.package._shrinkwrap.dependencies || {}, next) } else { return next() } @@ -39,7 +39,7 @@ function ls (args, silent, cb) { readPackageTree(dir, function (_, physicalTree) { if (!physicalTree) physicalTree = {package: {}, path: dir} physicalTree.isTop = true - readShrinkwrap.andInflate(physicalTree, {fakeChildren: true}, function () { + readShrinkwrap.andInflate(physicalTree, function () { lsFromTree(dir, computeMetadata(physicalTree), args, silent, cb) }) }) diff --git a/lib/prune.js b/lib/prune.js index 602774538..9ca17ae29 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -26,7 +26,6 @@ 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 c181fdc4e..333d3e9d6 100644 --- a/lib/uninstall.js +++ b/lib/uninstall.js @@ -52,7 +52,6 @@ class Uninstaller extends Installer { constructor (where, dryrun, args) { super(where, dryrun, args) this.remove = [] - this.fakeChildren = false } loadArgMetadata (next) { |