From d4400482deb02c0bcc4f133ea4fc654d675921ea Mon Sep 17 00:00:00 2001 From: zkochan Date: Mon, 3 Oct 2016 23:52:25 +0300 Subject: [PATCH] fix(install): always try to install a newer version Close #390 --- src/install/isAvailable.ts | 10 +++++++--- test/install.ts | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/install/isAvailable.ts b/src/install/isAvailable.ts index e9118740f2..bcc695c82a 100644 --- a/src/install/isAvailable.ts +++ b/src/install/isAvailable.ts @@ -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) } diff --git a/test/install.ts b/test/install.ts index 928ef7dcd5..b79f37930d 100644 --- a/test/install.ts +++ b/test/install.ts @@ -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'])