Skip to content

Adds support for workspace:^ in peerDependencies#3386

Merged
arcanis merged 5 commits intomasterfrom
mael/workspace-peer-dependencies
Sep 4, 2021
Merged

Adds support for workspace:^ in peerDependencies#3386
arcanis merged 5 commits intomasterfrom
mael/workspace-peer-dependencies

Conversation

@arcanis
Copy link
Copy Markdown
Member

@arcanis arcanis commented Sep 3, 2021

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 peerDependencies field now accepts the workspace: 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:~, and workspace:* specifiers are now supported as well and will be replaced at publish time by respectively ^1.0.0, ~1.0.0, and 1.0.0 (assuming the target workspace is version 1.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 a file: dependency). Workspaces are quite special to many aspects, and this is one of them - it doesn't change the general rule.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@merceyz
Copy link
Copy Markdown
Member

merceyz commented Sep 3, 2021

cc @gaetanmaisse since you wanted this in storybookjs/storybook#15413 (comment)

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).
Copy link
Copy Markdown
Member

@merceyz merceyz Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I didn't want to make the diff too large, but I'll do it as soon as it gets merged.

Co-authored-by: Kristoffer K. <merceyz@users.noreply.github.com>
@arcanis arcanis merged commit 440dd61 into master Sep 4, 2021
@arcanis arcanis deleted the mael/workspace-peer-dependencies branch September 4, 2021 10:18
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