Skip to content
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

Merged
merged 4 commits into from
Jun 7, 2017

Conversation

rally25rs
Copy link
Contributor

@rally25rs rally25rs commented May 26, 2017

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 :

  • Added additional tests for the existing yarn upgrade behaviors.
  • Added tests for behavior specific to latest flag.

Documentation

PR for the website documentation repo should be merged at the same time:
yarnpkg/website#513

rally25rs added a commit to rally25rs/website that referenced this pull request May 26, 2017
This is the documentation change that corresponds to yarnpkg/yarn#3510
They should be merged at the same time.
@arcanis
Copy link
Member

arcanis commented Jun 2, 2017

This is functionally equivalent to running yarn upgrade and passing all dependency names (yarn upgrade foo bar baz ...etc).

Shouldn't this flag be called --all, then?

@rally25rs
Copy link
Contributor Author

rally25rs commented Jun 2, 2017

I've always found this to be the most confusing part of Yarn;

I always expect yarn upgrade to be the same as yarn upgrade <all packages> but it isn't.

  • If you specify a package name, it ignores the version range in package.json.
  • If you don't specify a package name, then it uses the version ranges in package.json.

I think --latest is more indicative of what it's doing:

yarn upgrade - upgrades all respecting version range in package.json
yarn upgrade --latest - upgrades all to latest, ignoring package.json

In other words, yarn upgrade itself is already a "--all" in that it upgrades all packages. This change is really about what version it upgrades all packages to.

... hope that makes sense. It's early and I'm on my 1st cup ☕️
There is additional discussion in issue 3384 (linked in the original PR comment)

@cpojer
Copy link
Contributor

cpojer commented Jun 7, 2017

I like --latest, I think the explanation makes sense.

addArgs = Object.keys(allDependencies)
.map(dependency => {
return getDependency(allDependencies, dependency);
});
Copy link
Contributor

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.

@@ -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');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@cpojer
Copy link
Contributor

cpojer commented Jun 7, 2017

Would you mind rebasing this diff and making it pass on CI? :)

@rally25rs
Copy link
Contributor Author

oops, I made the classic mistake of git commit -a and forgetting to git add new files 😢
Merged latest master into the branch and fixed tests. Should be good to go now @cpojer

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'});
Copy link
Member

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 ?)

Copy link
Contributor Author

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.)

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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'});
Copy link
Member

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'});
});
Copy link
Member

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").

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Member

@arcanis arcanis Jun 7, 2017

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?

Copy link
Contributor Author

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.

@cpojer cpojer merged commit b9fe983 into yarnpkg:master Jun 7, 2017
@cpojer
Copy link
Contributor

cpojer commented Jun 7, 2017

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?

@develar
Copy link

develar commented Jun 8, 2017

One problem with this flag — range specifier is not preserved:

"electron-osx-sign": "0.4.6"

changed after yarn upgrade --latest to

"electron-osx-sign": "^0.4.6"

i.e. package not upgraded, but range specifier changed.

Range specifier must be preserved.

@arcanis
Copy link
Member

arcanis commented Jun 8, 2017

@develar good remark, can you open an issue?

@develar
Copy link

develar commented Jun 8, 2017

Filed #3609 .

@rally25rs
Copy link
Contributor Author

@develar @arcanis There is at least one issue already open for this same thing against upgrade-interactive #2367

Perhaps we can just combine them (I believe that from a code perspective, they are the same issue)

@rally25rs rally25rs deleted the upgrade-latest-parameter-3384 branch June 8, 2017 13:01
bestander pushed a commit to yarnpkg/website that referenced this pull request Jun 15, 2017
This is the documentation change that corresponds to yarnpkg/yarn#3510
They should be merged at the same time.
lovelypuppy0607 added a commit to lovelypuppy0607/website that referenced this pull request May 11, 2023
This is the documentation change that corresponds to yarnpkg/yarn#3510
They should be merged at the same time.
Kumljevx1 added a commit to Kumljevx1/yarn-website that referenced this pull request Aug 26, 2024
This is the documentation change that corresponds to yarnpkg/yarn#3510
They should be merged at the same time.
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.

4 participants