feat(workspaces): Add --ignore-workspace-root-check flag and improve usage#4630
Conversation
7647e38 to
8ba4966
Compare
|
This change will decrease the build size from 9.91 MB to 9.9 MB, a decrease of 2.96 KB (0%)
|
1 similar comment
|
This change will decrease the build size from 9.91 MB to 9.9 MB, a decrease of 2.96 KB (0%)
|
BYK
left a comment
There was a problem hiding this comment.
LGTM. Great job with the PR explanation.
|
|
||
| export function setFlags(commander: Object) { | ||
| commander.usage('add [packages ...] [flags]'); | ||
| commander.option('-W, --ignore-workspace-root-check', 'required to run yarn add inside a workspace root'); |
There was a problem hiding this comment.
Didn't think long about this one, but you make me remember it conflicts with -W(arning) of compilers 😞 oh well, should be fine for this iteration.
| if (file[0] === '@') { | ||
| const scopedPaths: Set<string> = new Set(); | ||
|
|
||
| const findExtraneousFiles = async basePath => { |
There was a problem hiding this comment.
It may be better in the future to extract this method outside of the closure.
There was a problem hiding this comment.
Since it needs to changes scopedPaths and extraneousFiles and isn't meant to be reused anywhere else in the code I thought it was cleaner to keep it together with the code segment that uses it.
--ignore-workspace-root-check flag and improve the DX
--ignore-workspace-root-check flag and improve the DX--ignore-workspace-root-check flag and improve usage
There was a problem hiding this comment.
@arcanis Your explanation makes sense and I agree that outdated and upgrade should operate across all workspaces, including the root.
However, I just tested your branch and ran outdated and upgrade-interactive at the workspace root for my test repository, and both commands only showed outdated root packages only, even though there are outdated packages in the workspaces. Did you intend to change that behaviour in this PR too?
jgoz
left a comment
There was a problem hiding this comment.
Also, this doesn't fix the "No lockfile in this directory..." issue when running remove inside of a workspace package (which is a legitimate case for running an individual command in a workspace).
I think you need to include the changes I made in cli.js too.
|
@jgoz Yep I missed those fixes :/ Right now I'll have to merge this PR as is (the new |
|
Thank you both for all your work on this - I can't wait to start using yarn workspaces once the remaining papercuts are fixed 😃 Looking at #4583 which this superseded, I see a few test-cases that weren't migrated to this PR - was this intentional? eg: |
Summary
Supercedes #4583 - cc @kaylieEB and @jgoz
Implements a
--ignore-workspace-root-checkoption that replaces the--devrequirement when adding a dependency at the root. We received a lot of feedback about this warning, which prompted this change. You can now add both production and development dependencies to your packages, as long as you also use the new flag. Hopefully it will make things easier to understand!Fixes the bug of Fix commands when used in a workspace #4583 where the extraneous files were not removed from the workspaces.
Partially fixes
outdated, which will now print the whole tree (including the workspace root).Running
yarn addin the root won't remove workspaces dependencies from the lockfile anymore.Details
At first this PR was only about adding the
--ignore-workspace-root-checkflag, but then I needed to change some parts of the code that #4583 was already altering, so I had to spend some time thinking about it as well, and eventually integrated the relevant changes here.First, a distinction has to be made:
package.jsonfile format. We have apackage.jsonfor each workspace.yarn.lockfile format. There's only a single lockfile that aggregate all workspaces.Which now brings me to my point: the following bugs, fixed in #4278 and #4583:
They are not bugs.
Now that might sounds weird, but it all makes sense if you think about how we store the resolved dependencies! Our lockfile format looks like this:
Think about a workspace root containing two workspaces, A and B. Both depends on
foo@~1.0.0. Now what will happen when we runyarn upgrade fooin A? Should we only update A? But then, what will our lockfile look like? We can't have two entries with the same key, like this:And here lies the problem: the lockfile format doesn't (yet) allow us to operate on part of the workspace tree. We always must deal with the whole workspace tree, because if we don't we'll end up corrupting the lockfile by "forgetting" entries (like what happened when we were just not reading the workspaces package.json files), or overriding them accidentally (like what would happen if we were to just override
foo@~1.0.0: B would be surprisingly affected as well by this change because it happens to share the same pattern range).Test plan
Added some tests from #4583, fixed a few others, everything should be green.