-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support --peer
for install to install peer deps as well
#4689
Conversation
This fixes yarnpkg#1503 This also drops some legacy options for help output (which were moved to `add`) This refactors `run` a little because the code was a bit spaghetti pasta Added a test
Wasn't sure how to add a test for mock packages. Would like some input on that. I'd prefer not to use actual packages as I only want to see that the peer packages were or weren't included. |
I think I like it, but what do you think about making this a default behavior rather than something hidden behind a flag? Since it only affects the top-level package (which shouldn't have peer dependencies anyway, unless it's a plugin of something in which case it would make sense to install the peer dependencies), that shouldn't change a lot of things. The only things I can see being affected would be people using Would probably require a major bump, but I think it's worth being considered. |
As for the tests, you can setup a fixture that contains sub-packages and reference them through the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about this causing a breaking change.
Also, we need to separate the actual fix with code cleanups and improvements in other places, especially ones removing existing functionality 😉
commander.option('-g, --global', 'DEPRECATED'); | ||
commander.option('-S, --save', 'DEPRECATED - save package to your `dependencies`'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these? They are deprecated but removing them is a breaking change and we don't want to release a major version just yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They aren't deprecated so much as simply invalid. They won't do anything anymore so why report them as deprecated?
The --peer
option was going to be re-used in light of this and the other options are only valid in add
, unless I'm mistaken?
I left -g
because I think that still makes sense with install
. Although I think that one is also moot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing deprecated features doesn't require a major per semver. I don't have a problem removing them, since it's been pretty clear for quite a long time now that yarn install
isn't meant to add dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I thought these options did not work at all with install
. That's why I removed their listing. If they still function then I stand corrected and they should remain until the feature itself is removed.
(Note that this only removes the --help
output, not the actual features they once represented...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing deprecated features doesn't require a major per semver. I don't have a problem removing them, since it's been pretty clear for quite a long time now that yarn install isn't meant to add dependencies.
I think this is still a hard-breaking change. I'll ask React guys to see what they do. I think they start deprecating in feature updates and only remove them in major releases which makes sense.
Wait, I thought these options did not work at all with install. That's why I removed their listing. If they still function then I stand corrected and they should remain until the feature itself is removed.
The feature is always there. These are just legacy flags from NPM but AFAIK they do work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't work per-se, but generate a 'suggested command line'.
https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L951-L975
@qfox Can you remove their removal from this PR? I think we should focus on the peer dependency itself, removing the deprecated commands will be a separate PR :)
src/cli/commands/install.js
Outdated
if (args.length) { | ||
const exampleArgs = args.slice(); | ||
let command = 'add'; | ||
let error = 'installCommandRenamed'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change relevant to the new feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Guess I'll remove the refactor.
@@ -344,6 +351,9 @@ export class Install { | |||
pushDeps('dependencies', workspaceManifest, {hint: null, optional: false}, true); | |||
pushDeps('devDependencies', workspaceManifest, {hint: 'dev', optional: false}, !this.config.production); | |||
pushDeps('optionalDependencies', workspaceManifest, {hint: 'optional', optional: true}, true); | |||
if (this.flags.includePeerDeps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arcanis I feel like this would change the lockfile resolution based on the flag which is not something we want.
I feel like we should drop the if block and use the following line:
pushDeps('peerDependencies', workspaceManifest, {hint: 'peer', optional: false}, this.flags.includePeerDeps);
Even then, I feel like this will be a big change in the final resolution. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Whether it's a valid point is probably going to be a plain decision by the product owner.
Either we support this and running the command will invalidate the cache if used inconsistently (with and without the flag). The user may complain about the cache being broken, or it may not notice it at all. We could print a warning for this if that's desirable.
Or we don't support this feature. In that case we should mention a wontfix in the ticket, perhaps state the reason why, and close it.
I don't think it's worth a major version bump for making this a default behavior (see #4689 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BYK I think there is a precedent for this (namely, the --flat
option). But that's something that would be solved if peer dependencies were installed by default rather than via a flag (which I still think would make sense).
As you say yourself, the whole thing doesn't happen too often. The flag pleases a small subset of people who explicitly want to install the peer deps as well. As I understand it, this is normally not the case for most people. Making it a default behavior could actually be detrimental since you may be installing something local which is already available globally, and now you have two versions to keep to update. If making this a default behavior may also affect other cases like Additionally, if the use case is so minor then a major version bump seems definitely unwarranted. I think the flag is fine. I'll have another look at the test. |
Updated with proper tests and sans the refactoring. Still dropping the flags since I think they can't be used without add. So it's not a breaking change to remove the help messages, merely cleanup. |
@@ -344,6 +351,9 @@ export class Install { | |||
pushDeps('dependencies', workspaceManifest, {hint: null, optional: false}, true); | |||
pushDeps('devDependencies', workspaceManifest, {hint: 'dev', optional: false}, !this.config.production); | |||
pushDeps('optionalDependencies', workspaceManifest, {hint: 'optional', optional: true}, true); | |||
if (this.flags.includePeerDeps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BYK I think there is a precedent for this (namely, the --flat
option). But that's something that would be solved if peer dependencies were installed by default rather than via a flag (which I still think would make sense).
commander.option('-g, --global', 'DEPRECATED'); | ||
commander.option('-S, --save', 'DEPRECATED - save package to your `dependencies`'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't work per-se, but generate a 'suggested command line'.
https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L951-L975
@qfox Can you remove their removal from this PR? I think we should focus on the peer dependency itself, removing the deprecated commands will be a separate PR :)
cc @qfox ? do you think you'll have the bandwidth to rebase this PR and make the few changes requested ? |
@arcanis I don't think I have the necessary bw to push this further. I remember from discussions in our team that this is a more complex and contentious feature to work on than I have time to flesh out. If somebody else feels this is important and wants to finish where I left of then please feel free to do so. You can use my code, I'll keep the branch up. I am closing this PR since I won't see myself working on it any further any time soon. If this feature is important to you please take my code, rebase it, apply the changes as suggested above, and polish it. Thanks :) |
Summary
This fixes #1503
This also drops some legacy options for help output (which were moved to
add
and don't work at all underinstall
)Test plan
Have a package with
peerDepdendencies
, install withyarn install --peer
and confirm that the packages listed underpeerDepdendencies
are also installed.Test cases added.