diff --git a/src/api/install.ts b/src/api/install.ts index ba6477f96b..50357e6abf 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -172,7 +172,7 @@ export async function installPkgs (fuzzyDeps: string[] | Dependencies, maybeOpts return lock(opts.prefix, async () => { const installType = 'named' const ctx = await getContext(opts, installType) - const existingSpecs = depsFromPackage(ctx.pkg) + const existingSpecs = opts.global ? {} : depsFromPackage(ctx.pkg) let packagesToInstall = Array.isArray(fuzzyDeps) ? argsToSpecs(fuzzyDeps, { defaultTag: opts.tag, diff --git a/test/install/global.ts b/test/install/global.ts index 40f9df762d..ec8c1f9f7c 100644 --- a/test/install/global.ts +++ b/test/install/global.ts @@ -1,7 +1,8 @@ import tape = require('tape') import promisifyTape from 'tape-promise' import path = require('path') -import {prepare, testDefaults} from '../utils' +import readPkg = require('read-pkg') +import {prepare, testDefaults, addDistTag} from '../utils' import {installPkgs} from '../../src' const test = promisifyTape(tape) @@ -22,3 +23,16 @@ test('global installation', async function (t) { const isNegative = require(path.join(globalPrefix, 'node_modules', 'is-negative')) t.ok(typeof isNegative === 'function', 'isNegative() is available') }) + +test('always install latest when doing global installation without spec', async function (t: tape.Test) { + await addDistTag('peer-c', '2.0.0', 'latest') + + const project = prepare(t) + const globalPrefix = process.cwd() + const opts = testDefaults({global: true, prefix: globalPrefix}) + + await installPkgs(['peer-c@1'], opts) + await installPkgs(['peer-c'], opts) + + t.equal(project.requireModule('peer-c/package.json').version, '2.0.0') +}) diff --git a/test/install/updatingPkgJson.ts b/test/install/updatingPkgJson.ts index dbd68de24b..6288af9ae9 100644 --- a/test/install/updatingPkgJson.ts +++ b/test/install/updatingPkgJson.ts @@ -21,6 +21,7 @@ test('save to package.json (rimraf@2.5.1)', async function (t) { t.deepEqual(pkgJson.dependencies, {rimraf: '^2.5.1'}, 'rimraf has been added to dependencies') }) +// NOTE: this works differently for global installations. See similar tests in global.ts test("don't override existing spec in package.json on named installation", async function (t: tape.Test) { const project = prepare(t, { dependencies: {