Skip to content

feat: add cleanupUnusedCatalogs config #9793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

btea
Copy link
Member

@btea btea commented Jul 24, 2025

When cleanupUnusedCatalogs is set to true, unused catalog dependencies in pnpm-workspace.yaml are automatically cleared when installing or removing dependencies.

@btea btea requested a review from zkochan as a code owner July 24, 2025 07:18
@btea
Copy link
Member Author

btea commented Jul 26, 2025

The test failure should have nothing to do with this modification.

@gluxon
Copy link
Member

gluxon commented Jul 27, 2025

I could see some users wanting to leave around a catalog entry in case it'll be used in the future. Should we use a new config for this instead of going off of the existing catalogMode setting name?

I've found reusing configs for new behavior can cause coupling of behaviors that aren't desirable for all users. People setting catalogMode=strict may not realize they're opting into this unrelated check.

@btea
Copy link
Member Author

btea commented Jul 27, 2025

IMO, setting catalogMode=strict means that all dependencies are managed in the catalog, so when removing related dependencies, the corresponding dependency information should be removed like pnpm-lock.yaml.

To avoid confusion, we can update the description of catalogMode=strict to clarify this situation.

If we add new configurations, will that be too much?

@gluxon
Copy link
Member

gluxon commented Jul 28, 2025

IMO, setting catalogMode=strict means that all dependencies are managed in the catalog, so when removing related dependencies, the corresponding dependency information should be removed like pnpm-lock.yaml.

While I personally agree, I don't know if this is the case for all users.

There's a new case we should consider: What if users add catalog entries through pnpm config dependencies? We would probably want to omit catalog entries added in this way. Config dependencies are used to share configuration across multiple repos. A given repo may not use every catalog entry in the shared config dependency.

@btea
Copy link
Member Author

btea commented Jul 28, 2025

Indeed, there is such a scenario. 🤔

@zkochan
Copy link
Member

zkochan commented Jul 30, 2025

Well, this is the description of catalogMode=strict in our docs:

strict - only allows dependency versions from the catalog. Adding a dependency outside the catalog's version range will cause an error.

It doesn't mention that unused catalog entries are prohibited.

Also, I don't think it should necessarily be limited to catalogMode strict. Why can't we remove unused entries when catalogMode is prefer or manual. I think these are different and new setting would be better.

@btea
Copy link
Member Author

btea commented Jul 30, 2025

What's the best approach for handling new configurations? Should I add a configuration that takes effect when removing a catalog dependency, or create a new command to clear unused catalog dependencies?

@zkochan
Copy link
Member

zkochan commented Jul 30, 2025

I think it can work on any install command, not just on remove.

@btea btea marked this pull request as draft July 31, 2025 01:10
@btea btea changed the title feat: remove the corresponding catalog configuration when catalogMode is strict feat: add dedupeCatalog config Aug 3, 2025
@btea btea marked this pull request as ready for review August 4, 2025 13:27
@zkochan
Copy link
Member

zkochan commented Aug 5, 2025

dedupeCatalog doesn't sound right. It isn't deduping anything. Maybe cleanupUnusedCatalogs.

@btea
Copy link
Member Author

btea commented Aug 5, 2025

Looks great.

@btea btea changed the title feat: add dedupeCatalog config feat: add cleanupUnusedCatalogs config Aug 6, 2025
@zkochan
Copy link
Member

zkochan commented Aug 8, 2025

I don't think it is a good idea to do the update of the workspace manifest inside @pnpm/core. Right now as you can see updatedCatalogs is returned from mutateModules and then the update of the workspace manifest happens elsewhere.

Also, I think it is bad already that we currently have 2 functions that write the workspace manifest and you add a third one. Potentially we will be writing this file multiple times. I think we should have only one function with options. So even the addCatalogs function should be removed.

@btea
Copy link
Member Author

btea commented Aug 10, 2025

I've made the changes, but I'm not sure I understood you correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants