fix: installing local dep from directory that starts with @ (#6350)

close #6332
This commit is contained in:
Zoltan Kochan
2023-04-04 02:36:30 +03:00
committed by GitHub
parent 5087636b66
commit 94f94eed63
6 changed files with 33 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
---
"@pnpm/dependency-path": patch
"@pnpm/lockfile-file": patch
"pnpm": patch
---

View File

@@ -0,0 +1,5 @@
---
"@pnpm/dependency-path": minor
---
Export `indexOfPeersSuffix`.

View 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).

View File

@@ -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)}`
}

View File

@@ -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) {

View File

@@ -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')
})