Skip to content

Fix 4263: Make upgrade and upgrade-interactive compatible with workspaces#4278

Merged
arcanis merged 6 commits intoyarnpkg:masterfrom
kaylie-alexa:fix-upgrade-for-workspaces
Sep 4, 2017
Merged

Fix 4263: Make upgrade and upgrade-interactive compatible with workspaces#4278
arcanis merged 6 commits intoyarnpkg:masterfrom
kaylie-alexa:fix-upgrade-for-workspaces

Conversation

@kaylie-alexa
Copy link
Copy Markdown
Member

Summary
Fix for #4263

When called at the project root level with workspaces, upgrade and upgrade-interactive should only change the root dev dependencies. Previously it was resolving / reinstalling workspace dependencies as well. Also it didn't allow for existing dev dependency to update (see screenshot)

Test plan

Added a test in upgrade with workspaces

BEFORE (only chalk should be updated)

screen shot 2017-08-27 at 12 28 08 pm

AFTER

screen shot 2017-08-27 at 12 25 45 pm

BEFORE (typescript is a dev dependency)

screen shot 2017-08-27 at 12 25 23 pm

AFTER

screen shot 2017-08-27 at 12 25 32 pm

pushDeps('optionalDependencies', projectManifestJson, {hint: 'optional', optional: true}, true);

if (this.config.workspaceRootFolder) {
if (this.config.workspaceRootFolder && !this.ignoreWorkspaces) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, doesn't this break running yarn install at the root of the workspace? It won't install the workspaces dependencies anymore, and its own dependencies won't have the same layout than what they would have been if the hoister had been aware of the workspaces.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this.ignoreWorkspaces is only set on add (defaults to false), so install should be ok. I'd also imagine this test (https://github.com/yarnpkg/yarn/blob/master/__tests__/commands/install/workspaces-install.js#L71) would catch it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I see! Ok, I missed that ignoreWorkspaces was undefined in Install. I think you should make it a flag defined in Install (rather than Add) and add a setter to toggle it (like the topLevelBinLinkFlag implemented here).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you got it!

@kaylie-alexa kaylie-alexa force-pushed the fix-upgrade-for-workspaces branch from 6448d3c to 3bd3602 Compare September 1, 2017 00:32
if (deps.length) {
for (const pattern of deps) {
lockfile.removePattern(pattern);
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

upgrade-interactive seemed to have been previously broken, regardless of workspaces or not. When --latest flag wasn't being passed, it needed https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/upgrade.js#L84-L86, like upgrade, otherwise nothing would get re-installed.


if (flags.existing) {
this.flagToOrigin = '';
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this required? Isn't it already handled by this line (according to the comment above, depType is the dependency source when upgrading a package)? I think it also might break the warning here, since the string will now always be empty

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So the issue I was running into was that when I ran yarn upgrade typescript (a dev dependency) in the workspace root directory, it would incorrectly warn me that workspaces prefer dev dependencies. This is because flagsToOrgin defaults to being a hard dependency when flags aren't passed. I don't think yarn should ever throw that warning if the command is an upgrade and save it for when it's a brand new add (hence the check for flags.existing passed in the upgrade file below).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An inline comment about this would have been great.


async init(): Promise<Array<string>> {
if (this.config.workspaceRootFolder && this.config.cwd === this.config.workspaceRootFolder) {
if (this.ignoreWorkspaces) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless I'm mistaken, this condition cannot be replaced this way; it is meant to ensure that running yarn add <something> inside the workspace root will warn the user that they probably don't want to do this. With this change, no warning will be emitted in such a case because ignoreWorkspaces will be false in traditional add settings. I think a better condition is:

this.config.workspaceRootFolder && this.config.cwd === this.config.workspaceRootFolder && !this.ignoreWorkspaces

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That conditional wouldn't ever be true though according to this logic right? https://github.com/kaylieEB/yarn/blob/93b2aaeb33aad23218177f3a1ed2bd9870e4d077/src/cli/commands/add.js#L27-L29. I've also tested that it still warns when I try to add a non-dev dependency.

Copy link
Copy Markdown
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.

I have some concerns on the readability, but let's merge it for now and we can iterate later :)

@arcanis arcanis merged commit da2b909 into yarnpkg:master Sep 4, 2017
arcanis pushed a commit that referenced this pull request Sep 6, 2017
@cpsubrian
Copy link
Copy Markdown

How would one run upgrade-interactive inside a particular workspace? The lack of lockfile prevents it.

joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
…aces (yarnpkg#4278)

* make upgrade and upgrade-interactive compatible with workspaces

* lint

* flow

* feedback from @arcanis

* fix flow

* remove lockfile pattern for normal upgrade interactive
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
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