fix: specless global installation should always install latest
This commit is contained in:
3 files changed
+17
-2
No files matched your search
+1
-1
@@ -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,
|
||||
|
||||
+15
-1
@@ -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')
|
||||
})
|
||||
@@ -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: {
|
||||
|
||||
Reference in new issue
Block a user