fix(update): preserve the range prefix in aliased deps

This commit is contained in:
Zoltan Kochan
2023-05-26 14:00:34 +03:00
parent 04a279881a
commit 4fc497882c
4 changed files with 17 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/which-version-is-pinned": patch
"pnpm": patch
---
When updating dependencies, preserve the range prefix in aliased dependencies. So `npm:foo@1.0.0` becomes `npm:foo@1.1.0`.

View File

@@ -4,6 +4,10 @@ export function whichVersionIsPinned (spec: string) {
const isWorkspaceProtocol = spec.startsWith('workspace:')
if (isWorkspaceProtocol) spec = spec.slice('workspace:'.length)
if (spec === '*') return isWorkspaceProtocol ? 'patch' : 'none'
if (spec.startsWith('npm:')) {
const index = spec.lastIndexOf('@')
spec = spec.slice(index + 1)
}
const parsedRange = parseRange(spec)
if (parsedRange.length !== 1) return undefined
const versionObject = parsedRange[0]

View File

@@ -6,6 +6,11 @@ test.each([
['1.0.0', 'patch'],
['*', 'none'],
['workspace:^1.0.0', 'major'],
['npm:foo@1.0.0', 'patch'],
['npm:@foo/foo@1.0.0', 'patch'],
['npm:foo@^1.0.0', 'major'],
['npm:@foo/foo@^1.0.0', 'major'],
['npm:@pnpm.e2e/qar@100.0.0', 'patch'],
])('whichVersionIsPinned()', (spec, expectedResult) => {
expect(whichVersionIsPinned(spec)).toEqual(expectedResult)
})

View File

@@ -399,7 +399,7 @@ test('recursive update --latest specific dependency on projects that do not shar
const manifest1 = await readPackageJsonFromDir(path.resolve('project-1'))
expect(manifest1.dependencies).toStrictEqual({
alias: 'npm:@pnpm.e2e/qar@^100.1.0', // this might be not correct
alias: 'npm:@pnpm.e2e/qar@100.1.0',
'@pnpm.e2e/dep-of-pkg-with-1-dep': '100.0.0',
'@pnpm.e2e/foo': '^100.1.0',
})
@@ -574,7 +574,7 @@ test('recursive update --latest specific dependency on projects with a shared a
const manifest1 = await readPackageJsonFromDir(path.resolve('project-1'))
expect(manifest1.dependencies).toStrictEqual({
alias: 'npm:@pnpm.e2e/qar@^100.1.0', // this might be incorrect
alias: 'npm:@pnpm.e2e/qar@100.1.0',
'@pnpm.e2e/dep-of-pkg-with-1-dep': '100.0.0',
'@pnpm.e2e/foo': '100.1.0',
})