Skip to content

fix: preserve catalog protocol when updating project manifest#8285

Merged
zkochan merged 3 commits intomainfrom
gluxon/catalog-update-ignore
Jul 7, 2024
Merged

fix: preserve catalog protocol when updating project manifest#8285
zkochan merged 3 commits intomainfrom
gluxon/catalog-update-ignore

Conversation

@gluxon
Copy link
Member

@gluxon gluxon commented Jul 7, 2024

Problem

Running pnpm update reverts dependencies using the catalog: protocol back to their original version ranges. Credit to @KSXGitHub for finding this bug.

Note how @pnpm/registry-mock changes from catalog: to ^3.34.0 in the video below. (The path-exists dependency is actually untouched because it's configured in pnpm.updateConfig.ignoreDependencies.)

update.mov

Changes

The updateProjectManifest function is generates a specsToUpsert array that determines the values in package.json after a pnpm update.

Updating this function to understand catalog: protocol dependencies.

Now that updateProjectManifest understands how to write catalog: protocol dependencies, this has the side effect of making pnpm add foo@catalog: work correctly. 🎉

@gluxon
Copy link
Member Author

gluxon commented Jul 7, 2024

Considerations

One problem I was worried about was pnpm update silently requesting newer versions of the cataloged dependency in the background. This would be inefficient (and possibly a bug) since we wouldn't record the resulting new version to pnpm-workspace.yaml or pnpm-lock.yaml.

After a lot of digging to understand the pnpm update code path more, I convinced myself this can't happen since we don't create new preferredSpecifiers for non-semver versions here in getVersionSpecsByRealNames.

} else if (!currentPref.includes(':')) { // we really care only about semver specs

gluxon added 3 commits July 7, 2024 00:38
This makes `pnpm add foo@catalog:` preserve the catalog protocol when
updating `package.json`.

This also fixes a quirk with `pnpm update --latest <name>` when <name>
is a catalog'ed dep. The `updateSpec` field is set on all deps if
`wantedDependencies` filters to 0.

https://github.com/pnpm/pnpm/blob/341656f9b36fd08a138fe31969f21f6a9409b0ea/pkg-manager/resolve-dependencies/src/toResolveImporter.ts#L44-L48
@gluxon gluxon force-pushed the gluxon/catalog-update-ignore branch from 5e1e4b7 to d33cc86 Compare July 7, 2024 04:42
@gluxon gluxon changed the title fix: skip cataloged dependencies when running pnpm update fix: preserve catalog protocol when updating project manifest Jul 7, 2024
@gluxon gluxon changed the title fix: preserve catalog protocol when updating project manifest fix: preserve catalog protocol when updating project manifest Jul 7, 2024
@gluxon gluxon marked this pull request as ready for review July 7, 2024 11:29
@gluxon gluxon requested a review from zkochan as a code owner July 7, 2024 11:29
@zkochan zkochan merged commit 824363b into main Jul 7, 2024
@zkochan zkochan deleted the gluxon/catalog-update-ignore branch July 7, 2024 12:27
@gluxon gluxon mentioned this pull request Jul 7, 2024
18 tasks
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.

2 participants