mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: pnpm doesn't respect save-prefix (#3420)
When save-prefix in .npmrc is set to an empty string, pnpm does not honor it and sets the package version with the default ^ as a prefix. Close #3414 Co-authored-by: amit <amit@enso.security>
This commit is contained in:
5
.changeset/spicy-eggs-collect.md
Normal file
5
.changeset/spicy-eggs-collect.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
---
|
||||
|
||||
Fix: align pnpm save-prefix behavior when a range is not specified explicitly.
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function getPinnedVersion (opts: { saveExact?: boolean, savePrefix?: string }) {
|
||||
if (opts.saveExact === true) return 'patch'
|
||||
if (opts.saveExact === true || opts.savePrefix === '') return 'patch'
|
||||
return opts.savePrefix === '~' ? 'minor' : 'major'
|
||||
}
|
||||
|
||||
@@ -243,3 +243,45 @@ test('pnpm add --save-peer', async () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test('pnpm add - with save-prefix set to empty string should save package version without prefix', async () => {
|
||||
prepare()
|
||||
await add.handler({
|
||||
...DEFAULT_OPTIONS,
|
||||
dir: process.cwd(),
|
||||
linkWorkspacePackages: false,
|
||||
savePrefix: '',
|
||||
}, ['is-positive@1.0.0'])
|
||||
|
||||
{
|
||||
const manifest = await loadJsonFile(path.resolve('package.json'))
|
||||
|
||||
expect(
|
||||
manifest
|
||||
).toStrictEqual(
|
||||
{
|
||||
name: 'project',
|
||||
version: '0.0.0',
|
||||
dependencies: { 'is-positive': '1.0.0' },
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test('pnpm add - should add prefix when set in .npmrc when a range is not specified explicitly', async () => {
|
||||
prepare()
|
||||
await add.handler({
|
||||
...DEFAULT_OPTIONS,
|
||||
dir: process.cwd(),
|
||||
linkWorkspacePackages: false,
|
||||
savePrefix: '~',
|
||||
}, ['is-positive'])
|
||||
|
||||
{
|
||||
const manifest = (await import(path.resolve('package.json')))
|
||||
|
||||
expect(
|
||||
manifest.dependencies['is-positive']
|
||||
).toMatch(/~([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user