Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/healthy-goats-tell.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
"@pnpm/dependency-path": patch
"@pnpm/lockfile-file": patch
"pnpm": patch
---
Expand Down
5 changes: 5 additions & 0 deletions .changeset/short-mirrors-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/dependency-path": minor
---

Export `indexOfPeersSuffix`.
6 changes: 6 additions & 0 deletions .changeset/wise-actors-fix.md
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`
}

Expand Down
20 changes: 18 additions & 2 deletions packages/dependency-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/dependency-path/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})