mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: installing a new dependency with a trailing @
`pnpm add foo@` should install the latest `foo` PR #2742 close #2737
This commit is contained in:
5
.changeset/witty-chicken-eat.md
Normal file
5
.changeset/witty-chicken-eat.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"supi": patch
|
||||
---
|
||||
|
||||
Don't fail when installing a dependency with a trailing @.
|
||||
@@ -129,9 +129,12 @@ function getPrefPreferSpecifiedSpec (
|
||||
) {
|
||||
const prefix = getPrefix(opts.alias, opts.name)
|
||||
if (opts.specRaw?.startsWith(`${opts.alias}@${prefix}`)) {
|
||||
const selector = versionSelectorType(opts.specRaw.substr(`${opts.alias}@${prefix}`.length))
|
||||
if (selector && (selector.type === 'version' || selector.type === 'range')) {
|
||||
return opts.specRaw.substr(opts.alias.length + 1)
|
||||
const range = opts.specRaw.substr(`${opts.alias}@${prefix}`.length)
|
||||
if (range) {
|
||||
const selector = versionSelectorType(range)
|
||||
if (selector && (selector.type === 'version' || selector.type === 'range')) {
|
||||
return opts.specRaw.substr(opts.alias.length + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
return `${prefix}${createVersionSpec(opts.version, opts.pinnedVersion)}`
|
||||
|
||||
@@ -188,6 +188,22 @@ test('modules without version spec, with custom tag config', async (t) => {
|
||||
await project.storeHas('dep-of-pkg-with-1-dep', '100.0.0')
|
||||
})
|
||||
|
||||
test('modules without version spec but with a trailing @', async (t) => {
|
||||
const project = prepareEmpty(t)
|
||||
|
||||
await addDependenciesToPackage({}, ['dep-of-pkg-with-1-dep@'], await testDefaults())
|
||||
|
||||
await project.has('dep-of-pkg-with-1-dep')
|
||||
})
|
||||
|
||||
test('aliased modules without version spec but with a trailing @', async (t) => {
|
||||
const project = prepareEmpty(t)
|
||||
|
||||
await addDependenciesToPackage({}, ['foo@npm:dep-of-pkg-with-1-dep@'], await testDefaults())
|
||||
|
||||
await project.has('foo')
|
||||
})
|
||||
|
||||
test('installing a package by specifying a specific dist-tag', async (t) => {
|
||||
const project = prepareEmpty(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user