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

Upgrade version rework 3603 #3847

Merged
merged 13 commits into from
Jul 20, 2017

Conversation

rally25rs
Copy link
Contributor

@rally25rs rally25rs commented Jul 7, 2017

** Related PR **

Documentation changes: yarnpkg/website#578

Summary

This is a PR for work done so far for RFC: https://github.com/yarnpkg/rfcs/blob/master/accepted/0000-upgrade-command-consistency.md

upgrade command now works more like upgrade-interactive.

upgrade-interactive is now actually an interactive version of upgrade.

See RFC for details.

@rally25rs rally25rs requested a review from arcanis July 7, 2017 02:15
@arcanis arcanis self-assigned this Jul 7, 2017
Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

Great work! Left some preliminary notes here and there

commander.usage('upgrade-interactive');
commander.option('-E, --exact', 'upgrade to most recent release with exact version');
commander.option('-T, --tilde', 'upgrade to most recent release with patch version');
setUpgradeFlags(commander);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not fond - I see why you're doing this, but it makes it harder to know what are the command options when reading the source code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was just trying to avoid the duplication. I can put the flags in both commands though.

const deps = await getOutdated(config, reporter, flags, lockfile, args);

// if specific versions were requested for packages, override what getOutdated reported as the latest to install
args.forEach(requestedPattern => {
Copy link
Member

Choose a reason for hiding this comment

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

We should try to use for (let ... of ...) instead of forEach when possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a reason, or just personal preference? I always visually mistake for ... of ... as the old for ... in ... which you seldom actually want. The subtle difference always messes me up.

current: '',
latestPattern: newPattern,
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to do this? I'd expect yarn upgrade foo@1.0.0 to throw if foo doesn't exists

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 was the case where a user specifies an exact version for something that isn't outdated. For example if you have foo@2.0.0 and that happens to be the latest, it won't be returned by getOutdatedPackages, but the user can still do yarn upgrade foo@1.2.4 and we would change to that requested version.
This is preserving functionality that the previous upgrade had (because it would just forward the package with version through to add)

// instead of the latest for the range.
deps.forEach(dep => lockfile.removePattern(dep.latestPattern));

const addFlags = Object.assign({}, flags, {force: true});
Copy link
Member

Choose a reason for hiding this comment

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

Can harmful flags be passed to upgrade by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. Probably. This is what the old/existing code did so I preserved it without much thought. Does the commander library that handles the command line options have anything to enforce only the allowed flags?


const addFlags = Object.assign({}, flags, {force: true});
const addArgs = deps.map(dep => dep.latestPattern);
delete addFlags.latest;
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 just use Object.assign({}, flags, {force: true, latest: false}) above to avoid using delete

src/types.js Outdated
@@ -153,6 +153,8 @@ export type Dependency = {
latest: string,
url: string,
hint: ?string,
range: string,
latestPattern: string,
Copy link
Member

Choose a reason for hiding this comment

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

(+ in the rest of the code)

I feel like the name isn't very clear - the difference between latest and latestPattern should be explained somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I agree... I had a hard time coming up with a meaningful name. Any suggestions? It's basically the name@version that we will upgrade to, which gets passed as input to the add command. Maybe something like upgradeToPattern or just upgradeTo?

@arcanis
Copy link
Member

arcanis commented Jul 7, 2017

Don't forget that automated tests (at least on upgrade) will be required to merge it, tho :)

@arcanis
Copy link
Member

arcanis commented Jul 17, 2017

@rally25rs Let me know when you want another review! Would love to see this merged 👍

@rally25rs
Copy link
Contributor Author

@arcanis I did some refactoring and linked a PR for the docs.
I also merged master as of a couple days ago and resolved some conflicts.
Hopefully this is good to go now...

const deps = (await PackageRequest.getOutdatedPackages(lockfile, install, config, reporter, patterns))
.filter(versionFilter)
.filter(scopeFilter);
deps.forEach(dep => (dep.upgradeTo = buildPatternToUpgradeTo(dep, flags)));
Copy link
Member

Choose a reason for hiding this comment

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

It won't block the merge but I think we should try using for ... of when possible, instead of forEach

@arcanis arcanis merged commit 1d06624 into yarnpkg:master Jul 20, 2017
@arcanis
Copy link
Member

arcanis commented Jul 20, 2017

Thanks a lot, @rally25rs ! I'm really happy to see this merged !

@cpojer
Copy link
Contributor

cpojer commented Jul 21, 2017

Great work @rally25rs, thank you so much for your contributions to Yarn :)

@danez
Copy link
Contributor

danez commented Sep 22, 2017

This has changed what yarn upgrade is doing. Before this change it was updating all dependencies in the tree, by respecting package.json ranges (by simply ignoring the lockfile and creating a new one) now it only updates dependencies I have in my package.json.

The only way to achieve the old behaviour is to remove yarn.lock and then do yarn install. Is this expected? It was really one of the nice features in comparison to npm to upgrade everything without having to manually touch the filesystem.

@bdwain
Copy link
Contributor

bdwain commented Oct 4, 2017

@danez we're discussing that in #4476

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.

5 participants