mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
fix: don't break the lockfile if it has peer deps with underscores (#3546)
close #3542
This commit is contained in:
5
.changeset/breezy-waves-camp.md
Normal file
5
.changeset/breezy-waves-camp.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"dependency-path": patch
|
||||
---
|
||||
|
||||
Fix `tryGetPackageId()`, it should parse correctly a dependency path that has peer dependency names with underscores.
|
||||
@@ -31,9 +31,9 @@ export function tryGetPackageId (registries: Registries, relDepPath: string) {
|
||||
if (relDepPath[0] !== '/') {
|
||||
return null
|
||||
}
|
||||
const lastUnderscore = relDepPath.lastIndexOf('_')
|
||||
if (lastUnderscore > relDepPath.lastIndexOf('/')) {
|
||||
return resolve(registries, relDepPath.substr(0, lastUnderscore))
|
||||
const underscoreIndex = relDepPath.indexOf('_', relDepPath.lastIndexOf('/'))
|
||||
if (underscoreIndex !== -1) {
|
||||
return resolve(registries, relDepPath.substr(0, underscoreIndex))
|
||||
}
|
||||
return resolve(registries, relDepPath)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
refToRelative,
|
||||
relative,
|
||||
resolve,
|
||||
tryGetPackageId,
|
||||
} from 'dependency-path'
|
||||
|
||||
test('isAbsolute()', () => {
|
||||
@@ -73,6 +74,14 @@ test('parse()', () => {
|
||||
version: '1.0.0',
|
||||
})
|
||||
|
||||
expect(parse('/foo/1.0.0_@types+babel__core@7.1.14')).toStrictEqual({
|
||||
host: undefined,
|
||||
isAbsolute: false,
|
||||
name: 'foo',
|
||||
peersSuffix: '@types+babel__core@7.1.14',
|
||||
version: '1.0.0',
|
||||
})
|
||||
|
||||
expect(() => parse('/foo/bar')).toThrow(/\/foo\/bar is an invalid relative dependency path/)
|
||||
})
|
||||
|
||||
@@ -130,3 +139,7 @@ test('depPathToFilename()', () => {
|
||||
expect(depPathToFilename('abcd/'.repeat(200), process.cwd())).toBe('abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+_27524303f1ddd808db67f175ff83606e')
|
||||
expect(depPathToFilename('/JSONSteam/1.0.0', process.cwd())).toBe('JSONSteam@1.0.0_4b2567ab922fbdf01171f59fab8f6fef')
|
||||
})
|
||||
|
||||
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')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user