feat: implement catalog protocol for install#8221
Conversation
I am not sure about this approach. That code is executed for every single resolved package, while catalogs are only applied to the projects themselves (not to the dependencies). So, maybe it should happen somewhere here pnpm/pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts Lines 166 to 203 in 347c79a Or in the |
8fc37e4 to
4bf157f
Compare
I was also leaning towards Here's the call stack for reference. I generated this a few weeks ago when trying to think through where it made sense. One other reason that I settled on I can try that on I do think we should throw a clear error when the |
|
I'm recalling a big reason I put the replacement in pnpm/pkg-manager/resolve-dependencies/src/resolveDependencies.ts Lines 1158 to 1163 in 4bf157f |
That's a different thing though. That one is applied on all levels, while catalogs are only applied on importers.
That function sounds good as well. |
|
Thanks @zkochan. I have to head out for a few hours, but will update this PR with that improvement when I get back tonight. 👍 |
4bf157f to
8db6388
Compare
|
Looks like compilation fails. |
|
Sorry about that — fixing now. |
32c090d to
80a9036
Compare
| }) | ||
|
|
||
| if (catalogLookup != null) { | ||
| extendedWantedDep.wantedDependency.pref = catalogLookup.specifier |
There was a problem hiding this comment.
I don't love the mutation happening here, but following a similar pattern in resolveDependencies, which we were discussing a few days ago.
Let me know if we should recreate the extendedWantedDep object instead.
| // If the catalog protocol was used, store metadata about the catalog | ||
| // lookup to use in the lockfile. | ||
| if (result.resolveDependencyResult != null && catalogLookup != null) { | ||
| result.resolveDependencyResult.catalogLookup = catalogLookup |
There was a problem hiding this comment.
I similarly don't love the mutation here. Open to ideas on alternatives.
93143aa to
80a9036
Compare
80a9036 to
e6a09b8
Compare
|
Latest push removes the redundant newline and nested function. Let me get back to you about simplifying |
e6a09b8 to
d348749
Compare
3141668 to
05993a8
Compare
05993a8 to
0a65b30
Compare
|
Latest push should address all feedback so far except:
|
|
ok, I'll probably check tomorrow. |
| const { allProjects } = await filterPackagesFromDir( | ||
| this.workspaceDir, | ||
| opts?.filter?.map(parentDir => ({ parentDir })) ?? []) |
There was a problem hiding this comment.
why do you need the filterPackagesFromDir function? All the data is already available. The tests in core are low level. You already passed all the required objects to preparePackages.
You can see in multipleImporters.ts tests how it is done. I think duplicating code in tests is fine. It is easier to understand. While helpers force to additionally learn how the helpers work.
There was a problem hiding this comment.
merged accidentally. Still, filterPackagesFromDir is not needed as a new dev dep in core
There was a problem hiding this comment.
Got it. I'll remove this from core in a PR now.
why do you need the filterPackagesFromDir function? All the data is already available. The tests in core are low level. You already passed all the required objects to preparePackages.
I wanted something that re-read the manifests off of disk after the calling the updateProjectManifest method. I also wanted to avoid other people having to edit this test if something about the Project interface changes.
You can see in multipleImporters.ts tests how it is done. I think duplicating code in tests is fine. It is easier to understand. While helpers force to additionally learn how the helpers work.
I agree with this principle. Sometimes helpers do make code harder to understand.
There was a problem hiding this comment.
* feat: add catalogs to @pnpm/config * refactor: factor out resolveDependenciesOfImporterDependency function * feat: implement catalog resolver and replace prefs * revert: work around CI setup not compiling orphan packages before testing * feat: record catalog lookup snapshots through propagated metadata * feat: update projects when catalogs config changes * test: add catalog protocol install tests
* feat: create new @pnpm/catalogs.types package (#8026) * feat: read catalog configs from workspace manifest (#8123) * refactor: move InvalidWorkspaceManifestError to its own file * feat: read catalogs config from workspace manifest * chore: add changeset for new catalog config parsing * feat: create new `@pnpm/catalogs.protocol-parser` package (#8124) This works around a problem with pnpm's CI setup not compiling packages that are not dependencies of the main pnpm package before running these tests. #8027 (comment) * refactor: factor out isWantedDepPrefSame to extend in a future commit (#8125) * feat: create new `@pnpm/catalogs.config` package (#8220) * refactor: remove single default catalog check This check will happen in `@pnpm/catalogs.config` instead. * feat: create new @pnpm/catalogs.config package * fix: work around CI setup not compiling orphan packages before testing This works around a problem with pnpm's CI setup not compiling packages that are not dependencies of the main pnpm package before running these tests. #8027 (comment) * feat: create new `@pnpm/catalogs.resolver` package (#8219) * feat: create new @pnpm/catalogs.resolver package * fix: work around CI setup not compiling orphan packages before testing This works around a problem with pnpm's CI setup not compiling packages that are not dependencies of the main pnpm package before running these tests. #8027 (comment) * feat: implement catalog protocol for publish (#8225) * feat: implement catalog protocol for install (#8221) * feat: add catalogs to @pnpm/config * refactor: factor out resolveDependenciesOfImporterDependency function * feat: implement catalog resolver and replace prefs * revert: work around CI setup not compiling orphan packages before testing * feat: record catalog lookup snapshots through propagated metadata * feat: update projects when catalogs config changes * test: add catalog protocol install tests * refactor: remove filter-packages-from-dir dependency from core tests (#8244) * refactor: remove filter-packages-from-dir dependency from core tests * test: refactor * test: refactor --------- Co-authored-by: Zoltan Kochan <z@kochan.io> --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
Changes
This implements the following items from the tracking issue #7072.
catalog:andcatalog:defaultspecifiers.catalog:<name>specifiers.I've organized this PR into different commits that make sense by themselves. This PR should be easier to review commit by commit rather than all files changed at once.
When should we transform the catalog protocol?
The hardest part of this PR was determining the right place for the
catalog:→^1.2.3translation internally.pnpm.overridesandpackageExtensionswork. I think this is too early of a place for the protocol to be resolved since it means thepnpm-lock.yamlfile won't have the originalcatalog:specifier that was declared inpackage.json.@pnpm/default-resolverlevel, but I think that's too deep. It means the default resolver would need to understand catalogs, which leaks the catalogs abstraction and makes the resolvers more complicated.I settled on performing the
catalog:protocol replacement right before we request dependencies from the store. I think that strikes the right balance.pnpm/pkg-manager/resolve-dependencies/src/resolveDependencies.ts
Lines 1135 to 1141 in ade62a9
Edit: We pivoted to
resolveDependenciesOfImporters(which is still somewhere in the middle) after the discussion below. #8221 (comment)Changes from Previous PR
This PR was previously open at #8020. A few things have changed since the last PR.
--filterto update thepnpm-lock.yamlfile first, which eliminates potential problems with thecatalog:protocol resolving to stale values inpnpm-lock.yaml.pnpm-workspace.yamlfor catalogs is now done in@pnpm/configinstead of@pnpm/context. feat: implement catalog protocol reads (feature flagged) #8020 (comment)