fix(install): always try to install a newer version

Close #390
This commit is contained in:
zkochan
2016-10-03 23:52:25 +03:00
parent eedb0e212a
commit d4400482de
2 changed files with 20 additions and 3 deletions

View File

@@ -1,4 +1,3 @@
import semver = require('semver')
import path = require('path')
import fs = require('mz/fs')
import {PackageSpec} from '../install'
@@ -22,6 +21,11 @@ export default async function isAvailable (spec: PackageSpec, modules: string) {
const packageJsonPath = path.join(modules, name, 'package.json')
try {
const stat = await fs.lstat(path.join(modules, name))
if (stat.isDirectory()) {
return true
}
const content = await fs.readFile(packageJsonPath)
const pkgJson = JSON.parse(content)
return verify(spec, pkgJson)
@@ -33,6 +37,6 @@ export default async function isAvailable (spec: PackageSpec, modules: string) {
function verify (spec: PackageSpec, packageJson: Package) {
return packageJson.name === spec.name &&
((spec.type !== 'range' && spec.type !== 'version') ||
semver.satisfies(packageJson.version, spec.spec, true))
((spec.type !== 'range' && spec.type !== 'version' && spec.type !== 'tag') ||
packageJson.version === spec.spec)
}

View File

@@ -130,6 +130,19 @@ test('overwriting (magic-hook@2.0.0 and @0.1.0)', async function (t) {
t.ok(_.version === '0.1.0', 'magic-hook is 0.1.0')
})
test('overwriting (is-positive@3.0.0 with is-positive@latest)', async function (t) {
prepare()
await installPkgs(['is-positive@3.0.0'], {save: true})
let _ = await exists(path.join(process.cwd(), 'node_modules/.store/is-positive@3.0.0'))
t.ok(_, 'magic-hook@3.0.0 exists')
await installPkgs(['is-positive@latest'], {save: true})
_ = await exists(path.join(process.cwd(), 'node_modules/.store/is-positive@3.1.0'))
t.ok(_, 'magic-hook@3.1.0 exists after installing the latest')
})
test('forcing', async function (t) {
prepare()
await installPkgs(['magic-hook@2.0.0'])