mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: installing local dep from directory that starts with @ (#6350)
close #6332
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
---
|
||||
"@pnpm/dependency-path": patch
|
||||
"@pnpm/lockfile-file": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
5
.changeset/short-mirrors-exercise.md
Normal file
5
.changeset/short-mirrors-exercise.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/dependency-path": minor
|
||||
---
|
||||
|
||||
Export `indexOfPeersSuffix`.
|
||||
6
.changeset/wise-actors-fix.md
Normal file
6
.changeset/wise-actors-fix.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Installation should not fail when there is a local dependency that starts in a directory that starts with the `@` char [#6332](https://github.com/pnpm/pnpm/issues/6332).
|
||||
@@ -159,12 +159,10 @@ export function revertFromInlineSpecifiersFormat (lockfile: InlineSpecifiersLock
|
||||
return newLockfile
|
||||
}
|
||||
|
||||
const PEERS_SUFFIX_REGEX = /(\([^)]+\))+$/
|
||||
|
||||
export function convertLockfileV6DepPathToV5DepPath (newDepPath: string) {
|
||||
if (!newDepPath.includes('@', 2)) return newDepPath
|
||||
if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:')) return newDepPath
|
||||
const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2)
|
||||
if (newDepPath.includes('(') && index > newDepPath.search(PEERS_SUFFIX_REGEX)) return newDepPath
|
||||
if (newDepPath.includes('(') && index > dp.indexOfPeersSuffix(newDepPath)) return newDepPath
|
||||
return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,29 @@ export function resolve (
|
||||
return resolutionLocation
|
||||
}
|
||||
|
||||
export function indexOfPeersSuffix (depPath: string) {
|
||||
if (!depPath.endsWith(')')) return -1
|
||||
let open = true
|
||||
for (let i = depPath.length - 2; i >= 0; i--) {
|
||||
if (depPath[i] === '(') {
|
||||
open = false
|
||||
} else if (depPath[i] === ')') {
|
||||
if (open) return -1
|
||||
open = true
|
||||
} else if (!open) {
|
||||
return i + 1
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
export function tryGetPackageId (registries: Registries, relDepPath: string) {
|
||||
if (relDepPath[0] !== '/') {
|
||||
return null
|
||||
}
|
||||
const sepIndex = relDepPath.indexOf('(')
|
||||
const sepIndex = indexOfPeersSuffix(relDepPath)
|
||||
if (sepIndex !== -1) {
|
||||
return resolve(registries, relDepPath.slice(0, sepIndex))
|
||||
return resolve(registries, relDepPath.substring(0, sepIndex))
|
||||
}
|
||||
const underscoreIndex = relDepPath.indexOf('_', relDepPath.lastIndexOf('/'))
|
||||
if (underscoreIndex !== -1) {
|
||||
|
||||
@@ -180,4 +180,5 @@ test('depPathToFilename()', () => {
|
||||
test('tryGetPackageId', () => {
|
||||
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0_@types+babel__core@7.1.14')).toEqual('registry.npmjs.org/foo/1.0.0')
|
||||
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/foo/1.0.0')
|
||||
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/@(-.-)/foo/1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/@(-.-)/foo/1.0.0')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user