mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: handle undefined version spec (#4487)
This commit is contained in:
5
.changeset/wet-rabbits-talk.md
Normal file
5
.changeset/wet-rabbits-talk.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/manifest-utils": patch
|
||||
---
|
||||
|
||||
Handle undefined version spec.
|
||||
@@ -7,7 +7,7 @@ export const getPrefix = (alias: string, name: string) => alias !== name ? `npm:
|
||||
export function getPref (
|
||||
alias: string,
|
||||
name: string,
|
||||
version: string,
|
||||
version: string | undefined,
|
||||
opts: {
|
||||
pinnedVersion?: PinnedVersion
|
||||
}
|
||||
@@ -16,7 +16,8 @@ export function getPref (
|
||||
return `${prefix}${createVersionSpec(version, opts.pinnedVersion)}`
|
||||
}
|
||||
|
||||
export function createVersionSpec (version: string, pinnedVersion?: PinnedVersion) {
|
||||
export function createVersionSpec (version: string | undefined, pinnedVersion?: PinnedVersion) {
|
||||
if (!version) return '*'
|
||||
switch (pinnedVersion ?? 'major') {
|
||||
case 'none':
|
||||
return '*'
|
||||
|
||||
35
packages/manifest-utils/test/getPref.test.ts
Normal file
35
packages/manifest-utils/test/getPref.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { getPref } from '@pnpm/manifest-utils'
|
||||
|
||||
test('getPref()', () => {
|
||||
expect(getPref('foo', 'foo', '1.0.0', {})).toEqual('^1.0.0')
|
||||
|
||||
expect(
|
||||
getPref('foo', 'foo', '1.0.0', {
|
||||
pinnedVersion: 'major',
|
||||
})
|
||||
).toEqual('^1.0.0')
|
||||
|
||||
expect(
|
||||
getPref('foo', 'foo', '2.0.0', {
|
||||
pinnedVersion: 'minor',
|
||||
})
|
||||
).toEqual('~2.0.0')
|
||||
|
||||
expect(
|
||||
getPref('foo', 'foo', '3.0.0', {
|
||||
pinnedVersion: 'patch',
|
||||
})
|
||||
).toEqual('3.0.0')
|
||||
|
||||
expect(
|
||||
getPref('foo', 'foo', '4.0.0', {
|
||||
pinnedVersion: 'none',
|
||||
})
|
||||
).toEqual('*')
|
||||
|
||||
expect(
|
||||
getPref('foo', 'foo', undefined, {
|
||||
pinnedVersion: 'major',
|
||||
})
|
||||
).toEqual('*')
|
||||
})
|
||||
Reference in New Issue
Block a user