fix: only show save catalog skip warning when using pnpm add (#10041)

close #9662
This commit is contained in:
Brandon Cheng
2025-10-06 06:03:11 -06:00
committed by GitHub
parent 8fcdda9e2c
commit a004e37db7
2 changed files with 12 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
pnpm: patch
---
When using pnpm catalogs and running a normal `pnpm install`, pnpm produced false positive warnings for "_skip adding to the default catalog because it already exists_". This warning now only prints when using `pnpm add --save-catalog` as originally intended.

View File

@@ -245,6 +245,11 @@ export async function resolveDependencyTree<T> (
for (const directDependencies of pkgAddressesByImporters) {
for (const directDep of directDependencies as PkgAddress[]) {
const { alias, normalizedBareSpecifier, version, saveCatalogName } = directDep
if (saveCatalogName == null) {
continue
}
const existingCatalog = opts.catalogs?.default?.[alias]
if (existingCatalog != null) {
if (existingCatalog !== normalizedBareSpecifier) {
@@ -252,7 +257,7 @@ export async function resolveDependencyTree<T> (
`Skip adding ${alias} to the default catalog because it already exists as ${existingCatalog}. Please use \`pnpm update\` to update the catalogs.`
)
}
} else if (saveCatalogName != null && normalizedBareSpecifier != null && version != null) {
} else if (normalizedBareSpecifier != null && version != null) {
const userSpecifiedBareSpecifier = `catalog:${saveCatalogName === 'default' ? '' : saveCatalogName}`
// Attach metadata about how this new catalog dependency should be