fix(dependency-path): parsing a local dep

This commit is contained in:
Zoltan Kochan
2023-02-05 12:35:05 +02:00
parent 65563ae098
commit d89d7a0786
3 changed files with 14 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/dependency-path": patch
---
`parse()` should not fail on dependency path pointing to a local dependency.

View File

@@ -105,6 +105,10 @@ export function parse (dependencyPath: string) {
const parts = dependencyPath.split('/')
if (!_isAbsolute) parts.shift()
const host = _isAbsolute ? parts.shift() : undefined
if (parts.length === 0) return {
host,
isAbsolute: _isAbsolute,
}
const name = parts[0].startsWith('@')
? `${parts.shift()}/${parts.shift()}` // eslint-disable-line @typescript-eslint/restrict-template-expressions
: parts.shift()

View File

@@ -99,6 +99,11 @@ test('parse()', () => {
})
expect(() => parse('/foo/bar')).toThrow(/\/foo\/bar is an invalid relative dependency path/)
expect(parse('file:project(foo@1.0.0)')).toStrictEqual({
host: 'file:project(foo@1.0.0)',
isAbsolute: true,
})
})
test('refToAbsolute()', () => {