Adds support for workspace:^ in peerDependencies#3386
Merged
Conversation
Member
|
cc @gaetanmaisse since you wanted this in storybookjs/storybook#15413 (comment) |
merceyz
reviewed
Sep 3, 2021
Comment on lines
+53
to
+57
| % This rule enforces that all workspaces must depend on other workspaces using `workspace:^` in peerDependencies | ||
| gen_enforced_dependency(WorkspaceCwd, DependencyIdent, 'workspace:^', 'peerDependencies') :- | ||
| workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'peerDependencies'), | ||
| % Only consider those that target something that could be a workspace | ||
| workspace_ident(DependencyCwd, DependencyIdent). |
Member
There was a problem hiding this comment.
It's not strictly required to fulfil the goal of this PR but we should be able to remove the two constraints above this and make this one target all dependency types.
Member
Author
There was a problem hiding this comment.
Yep I didn't want to make the diff too large, but I'll do it as soon as it gets merged.
merceyz
reviewed
Sep 3, 2021
Co-authored-by: Kristoffer K. <merceyz@users.noreply.github.com>
merceyz
approved these changes
Sep 3, 2021
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the problem this PR addresses?
It's currently impossible to use the pack-time workspace version management to let Yarn inject the right version number for inter-workspaces peer dependencies when publishing a package. As a result, merging release branches lead to painful merge conflicts.
How did you fix it?
The
peerDependenciesfield now accepts theworkspace:specifier (only with a semver range; relative workspace paths aren't supported unlike other dependency types). When found, Yarn will check that the inherited peer dependency is a workspace, and that it matches the specified range.Additionally, the
workspace:^,workspace:~, andworkspace:*specifiers are now supported as well and will be replaced at publish time by respectively^1.0.0,~1.0.0, and1.0.0(assuming the target workspace is version1.0.0).One option I initially considered was to just accept
^and~as aliases for*. However I eventually decided against it since it would depart from the syntax used in dependencies/peer dependencies. Still, to be completely clear, this improvement doesn't change that peer dependencies don't/cannot enforce the source of a peer dependency in any general term (for example, you can't enforce that the peer dependency must be filled via afile:dependency). Workspaces are quite special to many aspects, and this is one of them - it doesn't change the general rule.Checklist