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.
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.
See here:
#28579 (review)
When @yannbf was testing the behavior on his machine we observed
yarn
behave very differently from when we tested a similar command on your machine withnpm
.The problem is that package managers do different things.
npm
will install the exact version, in the lockfile, but add a caret in thepackage.json
fileyarn however, will add the exact version to the
package.json`.The industry standard is to have
^
ranges inpackage.json
and ensure versions do not drift unexpectedly using lockfiles.We want to ensure this behavior is held true, for all package managers.
Here's why me and @JReinhold ended up with the code above:
@latest
isCLIOutdated
will befalse
, andisCanary
will befalse
too.Meaning we add the
^
and manually write that to thepackage.json
We can safely do this, because
latest
islatest
, the subsequent install command will install the same version, because nothing higher can exist.@next
, both will befalse
again. Actually that behavior might be wrong. The caret will be added, meaning you might get a lateralpha
then you asked for.isCanary
will be true, and no caret will be added.Due to this being manually written to
package.json
, the behavior from all the package manager will be consistent.isCLIOutdated
will betrue
, and cause the^
not to be printed.I hope this explains a bit why it was chosen to manually write to
package.json
, instead of letting them do as they do... their behavior is inconsistent, and the upgrade experience would be different between usingnpm
andyarn
.If we're going to fix the bug here: #28569
..then we need to make absolutely sure, that the upgrade behavior is as is expected in every package manager we support.
The code below will not do that.