mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: installation of packages with () in scope name (#6349)
close #6348
This commit is contained in:
6
.changeset/healthy-goats-tell.md
Normal file
6
.changeset/healthy-goats-tell.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Repeat installation should work on a project that has a dependency with () chars in the scope name [#6348](https://github.com/pnpm/pnpm/issues/6348).
|
||||
@@ -140,7 +140,7 @@ export function revertFromInlineSpecifiersFormat (lockfile: InlineSpecifiersLock
|
||||
if (newSnapshot.optionalDependencies != null) {
|
||||
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertNewRefToOldRef)
|
||||
}
|
||||
return [convertNewDepPathToOldDepPath(depPath), newSnapshot]
|
||||
return [convertLockfileV6DepPathToV5DepPath(depPath), newSnapshot]
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -153,17 +153,19 @@ export function revertFromInlineSpecifiersFormat (lockfile: InlineSpecifiersLock
|
||||
if (originalVersion === 6 && newLockfile.time) {
|
||||
newLockfile.time = Object.fromEntries(
|
||||
Object.entries(newLockfile.time)
|
||||
.map(([depPath, time]) => [convertNewDepPathToOldDepPath(depPath), time])
|
||||
.map(([depPath, time]) => [convertLockfileV6DepPathToV5DepPath(depPath), time])
|
||||
)
|
||||
}
|
||||
return newLockfile
|
||||
}
|
||||
|
||||
export function convertNewDepPathToOldDepPath (oldDepPath: string) {
|
||||
if (!oldDepPath.includes('@', 2)) return oldDepPath
|
||||
const index = oldDepPath.indexOf('@', oldDepPath.indexOf('/@') + 2)
|
||||
if (oldDepPath.includes('(') && index > oldDepPath.indexOf('(')) return oldDepPath
|
||||
return `${oldDepPath.substring(0, index)}/${oldDepPath.substring(index + 1)}`
|
||||
const PEERS_SUFFIX_REGEX = /(\([^)]+\))+$/
|
||||
|
||||
export function convertLockfileV6DepPathToV5DepPath (newDepPath: string) {
|
||||
if (!newDepPath.includes('@', 2)) return newDepPath
|
||||
const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2)
|
||||
if (newDepPath.includes('(') && index > newDepPath.search(PEERS_SUFFIX_REGEX)) return newDepPath
|
||||
return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`
|
||||
}
|
||||
|
||||
function convertNewRefToOldRef (oldRef: string) {
|
||||
@@ -171,7 +173,7 @@ function convertNewRefToOldRef (oldRef: string) {
|
||||
return oldRef
|
||||
}
|
||||
if (oldRef.includes('@')) {
|
||||
return convertNewDepPathToOldDepPath(oldRef)
|
||||
return convertLockfileV6DepPathToV5DepPath(oldRef)
|
||||
}
|
||||
return oldRef
|
||||
}
|
||||
|
||||
@@ -98,6 +98,14 @@ test('parse()', () => {
|
||||
version: '1.0.0',
|
||||
})
|
||||
|
||||
expect(parse('/@(-.-)/foo/1.0.0(@types/babel__core@7.1.14)(foo@1.0.0)')).toStrictEqual({
|
||||
host: undefined,
|
||||
isAbsolute: false,
|
||||
name: '@(-.-)/foo',
|
||||
peersSuffix: '(@types/babel__core@7.1.14)(foo@1.0.0)',
|
||||
version: '1.0.0',
|
||||
})
|
||||
|
||||
expect(() => parse('/foo/bar')).toThrow(/\/foo\/bar is an invalid relative dependency path/)
|
||||
|
||||
expect(parse('file:project(foo@1.0.0)')).toStrictEqual({
|
||||
|
||||
@@ -1596,3 +1596,10 @@ test('lockfile is not written when it has no changes', async () => {
|
||||
await install(manifest, await testDefaults())
|
||||
expect(await fs.stat(WANTED_LOCKFILE)).toHaveProperty('mtimeMs', initialMtime)
|
||||
})
|
||||
|
||||
test('installation should work with packages that have () in the scope name', async () => {
|
||||
prepareEmpty()
|
||||
const opts = await testDefaults()
|
||||
const manifest = await addDependenciesToPackage({}, ['@(-.-)/env@0.3.1'], opts)
|
||||
await install(manifest, opts)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user