Skip to content

fix: do not move packages that are not shared to catalog#6

Merged
zkochan merged 1 commit intopnpm:mainfrom
mcous:fix-non-shared
Dec 7, 2025
Merged

fix: do not move packages that are not shared to catalog#6
zkochan merged 1 commit intopnpm:mainfrom
mcous:fix-non-shared

Conversation

@mcous
Copy link
Contributor

@mcous mcous commented Nov 8, 2024

Hello, thanks for this codemod! I tried it out in a monorepo, and noticed this aspect of the docs was not true:

If there are more than 2 packages with same dependency - it will move dependency to catalog.

Instead, the codemod moved all dependencies to the catalog, which wasn't what I wanted. In case the difference was unintentional, this PR updates the codemod to behave according to the docs. In addition to tracking the version count, it also tracks the dependent count, so we only select dependencies that have a single version used across multiple dependencies

@deanc
Copy link

deanc commented Feb 4, 2025

Same observation here. This codemod did the exact opposite of what it said it would do. It "catalogged" all the packages that were used once, and none of those used 2+ times.

@zkochan
Copy link
Member

zkochan commented Feb 4, 2025

I think moving everything to catalogs is also a valuable feature. Do codemods support flags or options to support both?

@mcous
Copy link
Contributor Author

mcous commented Feb 5, 2025

I think moving everything to catalogs is also a valuable feature. Do codemods support flags or options to support both?

@zkochan I've not worked with codemods before this PR, but a quick glance at their docs seem to indicate that yes, arguments are supported. Would you like me to update this PR with argument(s) to support both the current behavior of moving all packages and the docs-stated behavior of moving duplicated packages? If so, do you have any preferences on the argument names and/or defaults?

Some sort of "threshold" argument would be easy to tack on to this PR without much fuss - i.e. "if [N] or more packages have this dependency, move it to the catalog"

@zkochan
Copy link
Member

zkochan commented Feb 5, 2025

I guess it depends on what will be the default. We could have something like --duplicates-only or --all-deps.

@mcous
Copy link
Contributor Author

mcous commented Feb 6, 2025

"Only duplicates" was the behavior I was seeking out as a user to try catalogs for the first time. I think it's a sensible default while the catalogs feature is still relatively new and isn't fully integrated into stuff like pnpm update.

That being said, as long as both are possible I don't much mind either way. I defer to your judgement if you feel "all dependencies" is a better default

@zkochan
Copy link
Member

zkochan commented Feb 6, 2025

I wasn't the one who created the codemod. If the README says that only duplicates are moved to catalogs, then I am OK with that being the default.

@mcous
Copy link
Contributor Author

mcous commented May 1, 2025

I investigated this last night, and I couldn't figure out how to get arguments working. I'm not familiar with codemods, and their docs are kind of non-existent (in favor of upsells and pushing to AI tooling)

Accordingly, I do not intend to make any more updates to this PR. If you'd like to merge it as is to make the behavior match the documentation, please do! Otherwise feel free to close it (and maybe update the docs)

@sebastienbarre
Copy link

sebastienbarre commented Oct 14, 2025

Thanks for the work.
Any update on this? I too noticed that all dependencies were moved to the catalog, instead of the shared ones.

UPDATE: meanwhile, here is what you can do

  • Clone mcous/codemod (or fork, then clone your own).
  • Checkout the fix-non-shared branch, where the fix is, or commit 5acf6b3 directly
  • Run pnpm install
  • From your repo, run pnpx codemod -s [path to the mcous/codemod repo]/catalog/

ialexryan added a commit to ialexryan/pnpm.io that referenced this pull request Dec 4, 2025
Until such time as pnpm/codemod#6 is merged, the pnpm/codemod has behavior that is not consistent with its own [README](https://github.com/pnpm/codemod/blob/main/catalog/README.md), nor reasonable/expected. Therefore it should not be recommended on the official docs page.
@ialexryan
Copy link

@zkochan are you able to merge this PR? 🙏🏻

@zkochan zkochan merged commit 32840a7 into pnpm:main Dec 7, 2025
@Julien-R44
Copy link

Hey I noticed that this PR was merged, but it doesnt seem to have been released on Codemod yet:
https://app.codemod.com/registry/pnpm/catalog

The latest version available is 1.0.7, which was published about a year ago

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants