fix: update should not add peer deps to deps

This commit is contained in:
Zoltan Kochan
2023-05-26 19:17:36 +03:00
parent 4fc497882c
commit a9e0b7cbfd
5 changed files with 37 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/types": minor
---
Add new types.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/manifest-utils": patch
---
Don't update peer dependencies.

View File

@@ -9,6 +9,11 @@ export const DEPENDENCIES_FIELDS: DependenciesField[] = [
'devDependencies',
]
export const DEPENDENCIES_OR_PEER_FIELDS: DependenciesOrPeersField[] = [
...DEPENDENCIES_FIELDS,
'peerDependencies',
]
export interface Registries {
default: string
[scope: string]: string

View File

@@ -210,3 +210,17 @@ test('update only the specified package', async () => {
'is-positive': '3.1.0',
})
})
test('peer dependency is not added to prod deps on update', async () => {
prepareEmpty()
const manifest = await install({
peerDependencies: {
'is-positive': '^3.0.0',
},
}, await testDefaults({ autoInstallPeers: true, update: true, depth: 0 }))
expect(manifest).toStrictEqual({
peerDependencies: {
'is-positive': '^3.0.0',
},
})
})

View File

@@ -1,7 +1,9 @@
import { packageManifestLogger } from '@pnpm/core-loggers'
import {
type DependenciesOrPeersField,
type DependenciesField,
DEPENDENCIES_FIELDS,
DEPENDENCIES_OR_PEER_FIELDS,
type ProjectManifest,
} from '@pnpm/types'
@@ -36,8 +38,10 @@ export async function updateProjectManifestObject (
}
} else if (packageSpec.pref) {
const usedDepType = guessDependencyType(packageSpec.alias, packageManifest) ?? 'dependencies'
packageManifest[usedDepType] = packageManifest[usedDepType] ?? {}
packageManifest[usedDepType]![packageSpec.alias] = packageSpec.pref
if (usedDepType !== 'peerDependencies') {
packageManifest[usedDepType] = packageManifest[usedDepType] ?? {}
packageManifest[usedDepType]![packageSpec.alias] = packageSpec.pref
}
}
if (packageSpec.nodeExecPath) {
if (packageManifest.dependenciesMeta == null) {
@@ -59,7 +63,7 @@ function findSpec (alias: string, manifest: ProjectManifest): string | undefined
return foundDepType && manifest[foundDepType]![alias]
}
export function guessDependencyType (alias: string, manifest: ProjectManifest): DependenciesField | undefined {
return DEPENDENCIES_FIELDS
export function guessDependencyType (alias: string, manifest: ProjectManifest): DependenciesOrPeersField | undefined {
return DEPENDENCIES_OR_PEER_FIELDS
.find((depField) => manifest[depField]?.[alias] === '' || Boolean(manifest[depField]?.[alias]))
}