-
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
Add "latest" flag to "yarn upgrade" #3510
Add "latest" flag to "yarn upgrade" #3510
Conversation
This is the documentation change that corresponds to yarnpkg/yarn#3510 They should be merged at the same time.
Shouldn't this flag be called |
I've always found this to be the most confusing part of Yarn; I always expect
I think
In other words, ... hope that makes sense. It's early and I'm on my 1st cup ☕️ |
I like |
src/cli/commands/upgrade.js
Outdated
addArgs = Object.keys(allDependencies) | ||
.map(dependency => { | ||
return getDependency(allDependencies, dependency); | ||
}); |
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.
nit: you don't need the curly braces and the return here.
src/cli/commands/upgrade.js
Outdated
@@ -11,6 +11,7 @@ export function setFlags(commander: Object) { | |||
// TODO: support some flags that install command has | |||
commander.usage('upgrade [flags]'); | |||
commander.option('-S, --scope <scope>', 'upgrade packages under the specified scope'); | |||
commander.option('-L, --latest', 'upgrade packages to the latest version, ignoring version ranges in package.json'); |
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.
do we really need the -L
shorthand? Let's just go with --latest
.
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.
OK, was just following the convention of the other flags. I'll remove that -L
.
Would you mind rebasing this diff and making it pass on CI? :) |
oops, I made the classic mistake of |
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile.indexOf('left-pad@<=1.1.1:')).toEqual(-1); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.3'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '^1.1.3'}); |
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.
You shouldn't use left-pad
for this test, otherwise it will break if they release a new version. I think you can use yarn-test
(cc @kittens ?)
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.
Hmm, I actually thought the packages used during tests were all loaded from the 'offline mirror' directory of __tests__/fixtures/request-cache/...
but it does like like just the left-pad tgz files are in there, not the metadata. So all these tests are actually resolving real metadata? that seems fragile...
I needed a package that had enough diverse version numbers to cover all these upgrade cases, and left-pad was the first one I found that worked.
Is there someplace I can see what version of yarn-test
exist?
(side-note, it might be useful to document how these tests actually work and should be constructed, for new developers who want to contribute. It took me a while the first time I needed to add one.)
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.
So all these tests are actually resolving real metadata? that seems fragile...
Think so. That's why our tests practically never completely pass: we always end up timeouting at least one of them 😞 Probably should fix this at some point! I thought maybe we could set up some sort of fake registry with only the few endpoints required, that would extract its data from a repository local folder.
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.
We can discuss this in #3455
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.
The metadata for left-pad
is taken from the __tests__/fixtures/request-cache/
directory, so a new version pushed to the live registry would not break the test. These tests actually pass with no internet connection.
|
||
expect(lockEntryIndex).toEqual(0); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.3'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '~1.1.2'}); |
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.
You can use left-pad
here, but then use ~1.0.1
(should resolve to 1.0.2
) instead of ~1.1.2
, since we know there won't be any more release to this branch, which is not the case for 1.1.x
.
expect(lockfile.indexOf('left-pad@<=1.1.1:')).toEqual(-1); | ||
expect(lockfile[lockEntryIndex + 1]).toContain('1.1.3'); | ||
expect(pkg.dependencies).toEqual({'left-pad': '^1.1.3'}); | ||
}); |
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.
This doesn't feel right ... shouldn't we have to pass the --latest
flag to have this behavior? It contradicts the "no argument means all packages" behavior ("upgrades to latest matching package.json semver when no package name passed").
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.
This test actually passes in current Yarn without my modifications (in other words, this is how Yarn has worked for a while). This is testing the command yarn upgrade left-pad
, which is roughly equivalent to yarn add left-pad
. The add
command resolves to the passed in version range for left-pad
which is unspecified, so it resolves to latest.
There is some discussion around that confusing behavior in 3384 3266 3204
I've always sort of wondered if it's an unintentional behavior.
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 just re-read my comment and decided it's confusing... In clearer terms, the way Yarn 0.24 - 0.26 all work currently is that if your package.json is:
"dependencies": {
"left-pad": "^1.0.0"
Then yarn upgrade
will upgrade left-pad to the greatest match for ^1.0.0
.
However yarn upgrade left-pad
will upgrade to latest
.
I didn't change that behavior.
This PR just adds the option to:
yarn upgrade --latest
which will upgrade left-pad to latest
(ignoring what was in package.json)
There is currently, and with this PR, still no way to yarn upgrade <package_name>
and have it use the range specified in package.json, unless you manually copy-paste the range yourself and do yarn upgrade left-pad@^1.0.0
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.
Yep, you're right. I feel like this should be considered as a bug ... otherwise there's no way to upgrade a specific package inside its allowed boundaries :/ can you open a separate PR where we could discuss this?
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 spawned #3603 as a discussion issue and added you as an assignee.
Oops, that was within the same 15 seconds! @rally25rs would you mind sending a follow-up PR to fix the issues that @arcanis pointed out? |
One problem with this flag — range specifier is not preserved:
changed after
i.e. package not upgraded, but range specifier changed. Range specifier must be preserved. |
@develar good remark, can you open an issue? |
Filed #3609 . |
This is the documentation change that corresponds to yarnpkg/yarn#3510 They should be merged at the same time.
This is the documentation change that corresponds to yarnpkg/yarn#3510 They should be merged at the same time.
This is the documentation change that corresponds to yarnpkg/yarn#3510 They should be merged at the same time.
Implements requested feature in #3384
Adds a
yarn upgrade [--latest/-L]
flag.This flag instructs Yarn to upgrade all dependencies to the latest version specified by it's registry, ignoring the versions specified in
package.json
.This is functionally equivalent to running
yarn upgrade <package>
and passing all dependency names (yarn upgrade foo bar baz ...etc
).Test plan
In test file
__tests__/commands/upgrade.js
:yarn upgrade
behaviors.latest
flag.Documentation
PR for the website documentation repo should be merged at the same time:
yarnpkg/website#513