mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 04:21:39 -04:00
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user